You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1523 lines
70KB

  1. /*
  2. * utils for libavcodec
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file utils.c
  24. * utils.
  25. */
  26. #include "avcodec.h"
  27. #include "dsputil.h"
  28. #include "mpegvideo.h"
  29. #include "integer.h"
  30. #include "opt.h"
  31. #include "crc.h"
  32. #include <stdarg.h>
  33. #include <limits.h>
  34. #include <float.h>
  35. #if !defined(HAVE_MKSTEMP)
  36. #include <fcntl.h>
  37. #endif
  38. const uint8_t ff_reverse[256]={
  39. 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
  40. 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
  41. 0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
  42. 0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
  43. 0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
  44. 0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
  45. 0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
  46. 0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
  47. 0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
  48. 0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
  49. 0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
  50. 0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
  51. 0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
  52. 0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
  53. 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
  54. 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF,
  55. };
  56. static int volatile entangled_thread_counter=0;
  57. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
  58. {
  59. if(min_size < *size)
  60. return ptr;
  61. *size= FFMAX(17*min_size/16 + 32, min_size);
  62. return av_realloc(ptr, *size);
  63. }
  64. static unsigned int last_static = 0;
  65. static unsigned int allocated_static = 0;
  66. static void** array_static = NULL;
  67. void *av_mallocz_static(unsigned int size)
  68. {
  69. void *ptr = av_mallocz(size);
  70. if(ptr){
  71. array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1));
  72. if(!array_static)
  73. return NULL;
  74. array_static[last_static++] = ptr;
  75. }
  76. return ptr;
  77. }
  78. void *ff_realloc_static(void *ptr, unsigned int size)
  79. {
  80. int i;
  81. if(!ptr)
  82. return av_mallocz_static(size);
  83. /* Look for the old ptr */
  84. for(i = 0; i < last_static; i++) {
  85. if(array_static[i] == ptr) {
  86. array_static[i] = av_realloc(array_static[i], size);
  87. return array_static[i];
  88. }
  89. }
  90. return NULL;
  91. }
  92. void av_free_static(void)
  93. {
  94. while(last_static){
  95. av_freep(&array_static[--last_static]);
  96. }
  97. av_freep(&array_static);
  98. }
  99. /**
  100. * Call av_free_static automatically before it's too late
  101. */
  102. static void do_free(void) __attribute__ ((destructor));
  103. static void do_free(void)
  104. {
  105. av_free_static();
  106. }
  107. /* encoder management */
  108. AVCodec *first_avcodec = NULL;
  109. void register_avcodec(AVCodec *format)
  110. {
  111. AVCodec **p;
  112. p = &first_avcodec;
  113. while (*p != NULL) p = &(*p)->next;
  114. *p = format;
  115. format->next = NULL;
  116. }
  117. void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
  118. s->coded_width = width;
  119. s->coded_height= height;
  120. s->width = -((-width )>>s->lowres);
  121. s->height= -((-height)>>s->lowres);
  122. }
  123. typedef struct InternalBuffer{
  124. int last_pic_num;
  125. uint8_t *base[4];
  126. uint8_t *data[4];
  127. int linesize[4];
  128. int width, height;
  129. enum PixelFormat pix_fmt;
  130. }InternalBuffer;
  131. #define INTERNAL_BUFFER_SIZE 32
  132. #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
  133. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
  134. int w_align= 1;
  135. int h_align= 1;
  136. switch(s->pix_fmt){
  137. case PIX_FMT_YUV420P:
  138. case PIX_FMT_YUYV422:
  139. case PIX_FMT_UYVY422:
  140. case PIX_FMT_YUV422P:
  141. case PIX_FMT_YUV444P:
  142. case PIX_FMT_GRAY8:
  143. case PIX_FMT_GRAY16BE:
  144. case PIX_FMT_GRAY16LE:
  145. case PIX_FMT_YUVJ420P:
  146. case PIX_FMT_YUVJ422P:
  147. case PIX_FMT_YUVJ444P:
  148. w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
  149. h_align= 16;
  150. break;
  151. case PIX_FMT_YUV411P:
  152. case PIX_FMT_UYYVYY411:
  153. w_align=32;
  154. h_align=8;
  155. break;
  156. case PIX_FMT_YUV410P:
  157. if(s->codec_id == CODEC_ID_SVQ1){
  158. w_align=64;
  159. h_align=64;
  160. }
  161. case PIX_FMT_RGB555:
  162. if(s->codec_id == CODEC_ID_RPZA){
  163. w_align=4;
  164. h_align=4;
  165. }
  166. case PIX_FMT_PAL8:
  167. if(s->codec_id == CODEC_ID_SMC){
  168. w_align=4;
  169. h_align=4;
  170. }
  171. break;
  172. case PIX_FMT_BGR24:
  173. if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
  174. w_align=4;
  175. h_align=4;
  176. }
  177. break;
  178. default:
  179. w_align= 1;
  180. h_align= 1;
  181. break;
  182. }
  183. *width = ALIGN(*width , w_align);
  184. *height= ALIGN(*height, h_align);
  185. }
  186. int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
  187. if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/4)
  188. return 0;
  189. av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h);
  190. return -1;
  191. }
  192. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
  193. int i;
  194. int w= s->width;
  195. int h= s->height;
  196. InternalBuffer *buf;
  197. int *picture_number;
  198. if(pic->data[0]!=NULL) {
  199. av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
  200. return -1;
  201. }
  202. if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
  203. av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
  204. return -1;
  205. }
  206. if(avcodec_check_dimensions(s,w,h))
  207. return -1;
  208. if(s->internal_buffer==NULL){
  209. s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
  210. }
  211. #if 0
  212. s->internal_buffer= av_fast_realloc(
  213. s->internal_buffer,
  214. &s->internal_buffer_size,
  215. sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
  216. );
  217. #endif
  218. buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  219. picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack
  220. (*picture_number)++;
  221. if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
  222. for(i=0; i<4; i++){
  223. av_freep(&buf->base[i]);
  224. buf->data[i]= NULL;
  225. }
  226. }
  227. if(buf->base[0]){
  228. pic->age= *picture_number - buf->last_pic_num;
  229. buf->last_pic_num= *picture_number;
  230. }else{
  231. int h_chroma_shift, v_chroma_shift;
  232. int pixel_size, size[3];
  233. AVPicture picture;
  234. avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
  235. avcodec_align_dimensions(s, &w, &h);
  236. if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
  237. w+= EDGE_WIDTH*2;
  238. h+= EDGE_WIDTH*2;
  239. }
  240. avcodec_align_dimensions(s, &w, &h);
  241. avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
  242. pixel_size= picture.linesize[0]*8 / w;
  243. //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", (int)picture.data[1], w, h, s->pix_fmt);
  244. assert(pixel_size>=1);
  245. //FIXME next ensures that linesize= 2^x uvlinesize, that is needed because some MC code assumes it
  246. if(pixel_size == 3*8)
  247. w= ALIGN(w, STRIDE_ALIGN<<h_chroma_shift);
  248. else
  249. w= ALIGN(pixel_size*w, STRIDE_ALIGN<<(h_chroma_shift+3)) / pixel_size;
  250. size[1] = avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
  251. size[0] = picture.linesize[0] * h;
  252. size[1] -= size[0];
  253. if(picture.data[2])
  254. size[1]= size[2]= size[1]/2;
  255. else
  256. size[2]= 0;
  257. buf->last_pic_num= -256*256*256*64;
  258. memset(buf->base, 0, sizeof(buf->base));
  259. memset(buf->data, 0, sizeof(buf->data));
  260. for(i=0; i<3 && size[i]; i++){
  261. const int h_shift= i==0 ? 0 : h_chroma_shift;
  262. const int v_shift= i==0 ? 0 : v_chroma_shift;
  263. buf->linesize[i]= picture.linesize[i];
  264. buf->base[i]= av_malloc(size[i]+16); //FIXME 16
  265. if(buf->base[i]==NULL) return -1;
  266. memset(buf->base[i], 128, size[i]);
  267. // no edge if EDEG EMU or not planar YUV, we check for PAL8 redundantly to protect against a exploitable bug regression ...
  268. if((s->flags&CODEC_FLAG_EMU_EDGE) || (s->pix_fmt == PIX_FMT_PAL8) || !size[2])
  269. buf->data[i] = buf->base[i];
  270. else
  271. buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN);
  272. }
  273. buf->width = s->width;
  274. buf->height = s->height;
  275. buf->pix_fmt= s->pix_fmt;
  276. pic->age= 256*256*256*64;
  277. }
  278. pic->type= FF_BUFFER_TYPE_INTERNAL;
  279. for(i=0; i<4; i++){
  280. pic->base[i]= buf->base[i];
  281. pic->data[i]= buf->data[i];
  282. pic->linesize[i]= buf->linesize[i];
  283. }
  284. s->internal_buffer_count++;
  285. return 0;
  286. }
  287. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
  288. int i;
  289. InternalBuffer *buf, *last;
  290. assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
  291. assert(s->internal_buffer_count);
  292. buf = NULL; /* avoids warning */
  293. for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
  294. buf= &((InternalBuffer*)s->internal_buffer)[i];
  295. if(buf->data[0] == pic->data[0])
  296. break;
  297. }
  298. assert(i < s->internal_buffer_count);
  299. s->internal_buffer_count--;
  300. last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  301. FFSWAP(InternalBuffer, *buf, *last);
  302. for(i=0; i<3; i++){
  303. pic->data[i]=NULL;
  304. // pic->base[i]=NULL;
  305. }
  306. //printf("R%X\n", pic->opaque);
  307. }
  308. int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
  309. AVFrame temp_pic;
  310. int i;
  311. /* If no picture return a new buffer */
  312. if(pic->data[0] == NULL) {
  313. /* We will copy from buffer, so must be readable */
  314. pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
  315. return s->get_buffer(s, pic);
  316. }
  317. /* If internal buffer type return the same buffer */
  318. if(pic->type == FF_BUFFER_TYPE_INTERNAL)
  319. return 0;
  320. /*
  321. * Not internal type and reget_buffer not overridden, emulate cr buffer
  322. */
  323. temp_pic = *pic;
  324. for(i = 0; i < 4; i++)
  325. pic->data[i] = pic->base[i] = NULL;
  326. pic->opaque = NULL;
  327. /* Allocate new frame */
  328. if (s->get_buffer(s, pic))
  329. return -1;
  330. /* Copy image data from old buffer to new buffer */
  331. av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
  332. s->height);
  333. s->release_buffer(s, &temp_pic); // Release old frame
  334. return 0;
  335. }
  336. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
  337. int i;
  338. for(i=0; i<count; i++){
  339. int r= func(c, arg[i]);
  340. if(ret) ret[i]= r;
  341. }
  342. return 0;
  343. }
  344. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){
  345. return fmt[0];
  346. }
  347. static const char* context_to_name(void* ptr) {
  348. AVCodecContext *avc= ptr;
  349. if(avc && avc->codec && avc->codec->name)
  350. return avc->codec->name;
  351. else
  352. return "NULL";
  353. }
  354. #define OFFSET(x) offsetof(AVCodecContext,x)
  355. #define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
  356. //these names are too long to be readable
  357. #define V AV_OPT_FLAG_VIDEO_PARAM
  358. #define A AV_OPT_FLAG_AUDIO_PARAM
  359. #define S AV_OPT_FLAG_SUBTITLE_PARAM
  360. #define E AV_OPT_FLAG_ENCODING_PARAM
  361. #define D AV_OPT_FLAG_DECODING_PARAM
  362. #define AV_CODEC_DEFAULT_BITRATE 200*1000
  363. static const AVOption options[]={
  364. {"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|E},
  365. {"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, 64*1000, INT_MIN, INT_MAX, A|E},
  366. {"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE*20, 1, INT_MAX, V|E},
  367. {"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|E|D, "flags"},
  368. {"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
  369. {"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
  370. {"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
  371. {"loop", "use loop filter", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOOP_FILTER, INT_MIN, INT_MAX, V|E, "flags"},
  372. {"qscale", "use fixed qscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QSCALE, INT_MIN, INT_MAX, 0, "flags"},
  373. {"gmc", "use gmc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GMC, INT_MIN, INT_MAX, V|E, "flags"},
  374. {"mv0", "always try a mb with mv=<0,0>", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_MV0, INT_MIN, INT_MAX, V|E, "flags"},
  375. {"part", "use data partitioning", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PART, INT_MIN, INT_MAX, V|E, "flags"},
  376. {"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INPUT_PRESERVED, INT_MIN, INT_MAX, 0, "flags"},
  377. {"pass1", "use internal 2pass ratecontrol in first pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS1, INT_MIN, INT_MAX, 0, "flags"},
  378. {"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS2, INT_MIN, INT_MAX, 0, "flags"},
  379. {"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EXTERN_HUFF, INT_MIN, INT_MAX, 0, "flags"},
  380. {"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GRAY, INT_MIN, INT_MAX, V|E|D, "flags"},
  381. {"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EMU_EDGE, INT_MIN, INT_MAX, 0, "flags"},
  382. {"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PSNR, INT_MIN, INT_MAX, V|E, "flags"},
  383. {"truncated", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRUNCATED, INT_MIN, INT_MAX, 0, "flags"},
  384. {"naq", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_NORMALIZE_AQP, INT_MIN, INT_MAX, V|E, "flags"},
  385. {"ildct", "use interlaced dct", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_DCT, INT_MIN, INT_MAX, V|E, "flags"},
  386. {"low_delay", "force low delay", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOW_DELAY, INT_MIN, INT_MAX, V|D|E, "flags"},
  387. {"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_ALT_SCAN, INT_MIN, INT_MAX, V|E, "flags"},
  388. {"trell", "use trellis quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRELLIS_QUANT, INT_MIN, INT_MAX, V|E, "flags"},
  389. {"global_header", "place global headers in extradata instead of every keyframe", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GLOBAL_HEADER, INT_MIN, INT_MAX, 0, "flags"},
  390. {"bitexact", "use only bitexact stuff (except (i)dct)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_BITEXACT, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
  391. {"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_AC_PRED, INT_MIN, INT_MAX, V|E, "flags"},
  392. {"umv", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_UMV, INT_MIN, INT_MAX, V|E, "flags"},
  393. {"cbp", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CBP_RD, INT_MIN, INT_MAX, V|E, "flags"},
  394. {"qprd", "use rate distortion optimization for qp selection", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QP_RD, INT_MIN, INT_MAX, V|E, "flags"},
  395. {"aiv", "h263 alternative inter vlc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_AIV, INT_MIN, INT_MAX, V|E, "flags"},
  396. {"slice", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_SLICE_STRUCT, INT_MIN, INT_MAX, V|E, "flags"},
  397. {"ilme", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_ME, INT_MIN, INT_MAX, V|E, "flags"},
  398. {"scan_offset", "will reserve space for svcd scan offset user data", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_SVCD_SCAN_OFFSET, INT_MIN, INT_MAX, V|E, "flags"},
  399. {"cgop", "closed gop", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CLOSED_GOP, INT_MIN, INT_MAX, V|E, "flags"},
  400. {"fast", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FAST, INT_MIN, INT_MAX, V|E, "flags2"},
  401. {"sgop", "strictly enforce gop size", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_STRICT_GOP, INT_MIN, INT_MAX, V|E, "flags2"},
  402. {"noout", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NO_OUTPUT, INT_MIN, INT_MAX, V|E, "flags2"},
  403. {"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"},
  404. {"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  405. {"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"},
  406. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  407. {"me", "set motion estimation method (deprecated, use me_method instead)", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"},
  408. #endif
  409. {"zero", "zero motion estimation (fastest)", 0, FF_OPT_TYPE_CONST, ME_ZERO, INT_MIN, INT_MAX, V|E, "me_method" },
  410. {"full", "full motion estimation (slowest)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" },
  411. {"epzs", "EPZS motion estimation (default)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" },
  412. {"log", "log motion estimation", 0, FF_OPT_TYPE_CONST, ME_LOG, INT_MIN, INT_MAX, V|E, "me_method" },
  413. {"phods", "phods motion estimation", 0, FF_OPT_TYPE_CONST, ME_PHODS, INT_MIN, INT_MAX, V|E, "me_method" },
  414. {"x1", "X1 motion estimation", 0, FF_OPT_TYPE_CONST, ME_X1, INT_MIN, INT_MAX, V|E, "me_method" },
  415. {"hex", "hex motion estimation", 0, FF_OPT_TYPE_CONST, ME_HEX, INT_MIN, INT_MAX, V|E, "me_method" },
  416. {"umh", "umh motion estimation", 0, FF_OPT_TYPE_CONST, ME_UMH, INT_MIN, INT_MAX, V|E, "me_method" },
  417. {"iter", "iter motion estimation", 0, FF_OPT_TYPE_CONST, ME_ITER, INT_MIN, INT_MAX, V|E, "me_method" },
  418. {"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  419. {"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
  420. {"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E},
  421. {"rate_emu", "frame rate emulation", OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  422. {"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  423. {"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  424. {"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
  425. {"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E},
  426. {"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  427. {"real_pict_num", NULL, OFFSET(real_pict_num), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  428. {"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  429. {"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), FF_OPT_TYPE_FLOAT, 0.5, FLT_MIN, FLT_MAX, V|E},
  430. {"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), FF_OPT_TYPE_FLOAT, 0.5, FLT_MIN, FLT_MAX, V|E},
  431. {"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), FF_OPT_TYPE_INT, 2, 1, 51, V|E},
  432. {"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), FF_OPT_TYPE_INT, 31, 1, 51, V|E},
  433. {"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), FF_OPT_TYPE_INT, 3, INT_MIN, INT_MAX, V|E},
  434. {"bf", "use 'frames' B frames", OFFSET(max_b_frames), FF_OPT_TYPE_INT, DEFAULT, 0, FF_MAX_B_FRAMES, V|E},
  435. {"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, FLT_MAX, V|E},
  436. {"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  437. {"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
  438. {"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  439. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  440. {"rtp_mode", NULL, OFFSET(rtp_mode), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  441. #endif
  442. {"ps", "rtp payload size in bits", OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  443. {"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  444. {"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  445. {"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  446. {"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  447. {"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  448. {"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  449. {"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  450. {"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  451. {"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  452. {"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  453. {"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), FF_OPT_TYPE_FLAGS, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
  454. {"autodetect", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
  455. {"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, FF_OPT_TYPE_CONST, FF_BUG_OLD_MSMPEG4, INT_MIN, INT_MAX, V|D, "bug"},
  456. {"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, FF_OPT_TYPE_CONST, FF_BUG_XVID_ILACE, INT_MIN, INT_MAX, V|D, "bug"},
  457. {"ump4", "(autodetected if fourcc==UMP4)", 0, FF_OPT_TYPE_CONST, FF_BUG_UMP4, INT_MIN, INT_MAX, V|D, "bug"},
  458. {"no_padding", "padding bug (autodetected)", 0, FF_OPT_TYPE_CONST, FF_BUG_NO_PADDING, INT_MIN, INT_MAX, V|D, "bug"},
  459. {"amv", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AMV, INT_MIN, INT_MAX, V|D, "bug"},
  460. {"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, FF_OPT_TYPE_CONST, FF_BUG_AC_VLC, INT_MIN, INT_MAX, V|D, "bug"},
  461. {"qpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
  462. {"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_STD_QPEL, INT_MIN, INT_MAX, V|D, "bug"},
  463. {"qpel_chroma2", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA2, INT_MIN, INT_MAX, V|D, "bug"},
  464. {"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_DIRECT_BLOCKSIZE, INT_MIN, INT_MAX, V|D, "bug"},
  465. {"edge", "edge padding bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_EDGE, INT_MIN, INT_MAX, V|D, "bug"},
  466. {"hpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_HPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
  467. {"dc_clip", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DC_CLIP, INT_MIN, INT_MAX, V|D, "bug"},
  468. {"ms", "workaround various bugs in microsofts broken decoders", 0, FF_OPT_TYPE_CONST, FF_BUG_MS, INT_MIN, INT_MAX, V|D, "bug"},
  469. {"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  470. {"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  471. {"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|D, "strict"},
  472. {"very", "strictly conform to a older more strict version of the spec or reference software", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_VERY_STRICT, INT_MIN, INT_MAX, V|E, "strict"},
  473. {"strict", "strictly conform to all the things in the spec no matter what consequences", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|E, "strict"},
  474. {"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|E, "strict"},
  475. {"inofficial", "allow inofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|E, "strict"},
  476. {"experimental", "allow non standardized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"},
  477. {"b_qoffset", "qp offset between p and b frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, FLT_MAX, V|E},
  478. {"er", "set error resilience strategy", OFFSET(error_resilience), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"},
  479. {"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
  480. {"compliant", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"},
  481. {"aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
  482. {"very_aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_VERY_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
  483. {"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  484. {"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  485. {"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  486. {"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  487. {"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
  488. {"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
  489. {"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 99, V|E},
  490. {"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
  491. {"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  492. {"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  493. {"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
  494. {"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  495. {"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  496. {"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  497. {"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, 1.0, FLT_MIN, FLT_MAX, V|E},
  498. {"i_qfactor", "qp factor between p and i frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E},
  499. {"i_qoffset", "qp offset between p and i frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E},
  500. {"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
  501. {"dct", "DCT algorithm", OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"},
  502. {"auto", "autoselect a good one (default)", 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"},
  503. {"fastint", "fast integer", 0, FF_OPT_TYPE_CONST, FF_DCT_FASTINT, INT_MIN, INT_MAX, V|E, "dct"},
  504. {"int", "accurate integer", 0, FF_OPT_TYPE_CONST, FF_DCT_INT, INT_MIN, INT_MAX, V|E, "dct"},
  505. {"mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MMX, INT_MIN, INT_MAX, V|E, "dct"},
  506. {"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MLIB, INT_MIN, INT_MAX, V|E, "dct"},
  507. {"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_ALTIVEC, INT_MIN, INT_MAX, V|E, "dct"},
  508. {"faan", "floating point AAN DCT", 0, FF_OPT_TYPE_CONST, FF_DCT_FAAN, INT_MIN, INT_MAX, V|E, "dct"},
  509. {"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
  510. {"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
  511. {"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
  512. {"p_mask", "inter masking", OFFSET(p_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
  513. {"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E},
  514. {"unused", NULL, OFFSET(unused), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  515. {"idct", "select IDCT implementation", OFFSET(idct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E|D, "idct"},
  516. {"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_AUTO, INT_MIN, INT_MAX, V|E|D, "idct"},
  517. {"int", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_INT, INT_MIN, INT_MAX, V|E|D, "idct"},
  518. {"simple", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLE, INT_MIN, INT_MAX, V|E|D, "idct"},
  519. {"simplemmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  520. {"libmpeg2mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_LIBMPEG2MMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  521. {"ps2", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_PS2, INT_MIN, INT_MAX, V|E|D, "idct"},
  522. {"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_MLIB, INT_MIN, INT_MAX, V|E|D, "idct"},
  523. {"arm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ARM, INT_MIN, INT_MAX, V|E|D, "idct"},
  524. {"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ALTIVEC, INT_MIN, INT_MAX, V|E|D, "idct"},
  525. {"sh4", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SH4, INT_MIN, INT_MAX, V|E|D, "idct"},
  526. {"simplearm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARM, INT_MIN, INT_MAX, V|E|D, "idct"},
  527. {"simplearmv5te", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV5TE, INT_MIN, INT_MAX, V|E|D, "idct"},
  528. {"h264", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_H264, INT_MIN, INT_MAX, V|E|D, "idct"},
  529. {"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
  530. {"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
  531. {"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  532. {"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  533. {"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
  534. {"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
  535. {"deblock", "use strong deblock filter for damaged MBs", 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"},
  536. {"bits_per_sample", NULL, OFFSET(bits_per_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  537. {"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"},
  538. {"left", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"},
  539. {"plane", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"},
  540. {"median", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"},
  541. {"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E},
  542. {"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"},
  543. {"pict", "picture info", 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"},
  544. {"rc", "rate control", 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"},
  545. {"bitstream", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"},
  546. {"mb_type", "macroblock (MB) type", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
  547. {"qp", "per-block quantization parameter (QP)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"},
  548. {"mv", "motion vector", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"},
  549. {"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"},
  550. {"skip", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"},
  551. {"startcode", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"},
  552. {"pts", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"},
  553. {"er", "error resilience", 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"},
  554. {"mmco", "memory management control operations (H.264)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"},
  555. {"bugs", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"},
  556. {"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_QP, INT_MIN, INT_MAX, V|D, "debug"},
  557. {"vis_mb_type", "visualize block types", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
  558. {"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"},
  559. {"pf", "forward predicted MVs of P-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
  560. {"bf", "forward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
  561. {"bb", "backward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"},
  562. {"mb_qmin", "obsolete, use qmin", OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  563. {"mb_qmax", "obsolete, use qmax", OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  564. {"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  565. {"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  566. {"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  567. {"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  568. {"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  569. {"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  570. {"preme", "pre motion estimation", OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  571. {"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  572. {"sad", "sum of absolute differences, fast (default)", 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  573. {"sse", "sum of squared errors", 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  574. {"satd", "sum of absolute Hadamard transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  575. {"dct", "sum of absolute DCT transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  576. {"psnr", "sum of squared quantization errors (avoid, low quality)", 0, FF_OPT_TYPE_CONST, FF_CMP_PSNR, INT_MIN, INT_MAX, V|E, "cmp_func"},
  577. {"bit", "number of bits needed for the block", 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  578. {"rd", "rate distortion optimal, slow", 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  579. {"zero", "0", 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"},
  580. {"vsad", "sum of absolute vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  581. {"vsse","sum of squared vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  582. {"nsse", "noise preserving sum of squared differences", 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  583. #ifdef CONFIG_SNOW_ENCODER
  584. {"w53", "5/3 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"},
  585. {"w97", "9/7 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"},
  586. #endif
  587. {"dctmax", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
  588. {"chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"},
  589. {"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  590. {"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
  591. {"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  592. {"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  593. {"ibias", "intra quant bias", OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
  594. {"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
  595. {"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  596. {"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  597. {"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  598. {"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
  599. {"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
  600. {"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
  601. {"raw", "raw (no encoding)", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RAW, INT_MIN, INT_MAX, V|E, "coder"},
  602. {"rle", "run-length coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RLE, INT_MIN, INT_MAX, V|E, "coder"},
  603. {"deflate", "deflate-based coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_DEFLATE, INT_MIN, INT_MAX, V|E, "coder"},
  604. {"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  605. {"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  606. {"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  607. {"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"},
  608. {"simple", "use mbcmp (default)", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"},
  609. {"bits", "use fewest bits", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"},
  610. {"rd", "use best rate distortion", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"},
  611. {"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  612. {"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  613. {"lmin", "min lagrange factor (VBR)", OFFSET(lmin), FF_OPT_TYPE_INT, 2*FF_QP2LAMBDA, 0, INT_MAX, V|E},
  614. {"lmax", "max lagrange factor (VBR)", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E},
  615. {"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  616. {"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  617. {"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  618. {"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|A|E|D, "flags2"},
  619. {"error", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  620. {"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"},
  621. {"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"},
  622. {"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"},
  623. {"int", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"},
  624. {"float", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"},
  625. {"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  626. {"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E|D},
  627. {"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  628. {"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  629. {"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
  630. {"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
  631. {"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  632. {"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  633. {"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
  634. {"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
  635. {"aac_main", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_MAIN, INT_MIN, INT_MAX, A|E, "profile"},
  636. {"aac_low", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LOW, INT_MIN, INT_MAX, A|E, "profile"},
  637. {"aac_ssr", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_SSR, INT_MIN, INT_MAX, A|E, "profile"},
  638. {"aac_ltp", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LTP, INT_MIN, INT_MAX, A|E, "profile"},
  639. {"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
  640. {"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
  641. {"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D},
  642. {"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  643. {"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  644. {"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  645. {"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
  646. {"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
  647. {"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 2, 1, FF_LAMBDA_MAX, V|E},
  648. {"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 31, 1, FF_LAMBDA_MAX, V|E},
  649. {"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, 256, INT_MIN, INT_MAX, V|E},
  650. {"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 0, 4, V|E},
  651. {"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, DEFAULT, 0, 10, V|E},
  652. {"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E},
  653. {"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, V|E},
  654. {"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, 25, INT_MIN, INT_MAX, V|E},
  655. {"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E},
  656. {"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  657. {"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  658. {"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
  659. {"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal)", OFFSET(directpred), FF_OPT_TYPE_INT, 2, INT_MIN, INT_MAX, V|E},
  660. {"bpyramid", "allows B-frames to be used as references for predicting", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BPYRAMID, INT_MIN, INT_MAX, V|E, "flags2"},
  661. {"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"},
  662. {"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MIXED_REFS, INT_MIN, INT_MAX, V|E, "flags2"},
  663. {"dct8x8", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
  664. {"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"},
  665. {"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"},
  666. {"brdo", "b-frame rate-distortion optimization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BRDO, INT_MIN, INT_MAX, V|E, "flags2"},
  667. {"skiprd", "RD optimal MB level residual skipping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"},
  668. {"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E},
  669. {"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
  670. {"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
  671. {"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "partitions"},
  672. {"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I4X4, INT_MIN, INT_MAX, V|E, "partitions"},
  673. {"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I8X8, INT_MIN, INT_MAX, V|E, "partitions"},
  674. {"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"},
  675. {"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"},
  676. {"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
  677. {"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E},
  678. {"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E},
  679. {"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
  680. {"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
  681. {"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E},
  682. {"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  683. {"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
  684. {"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  685. {"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  686. {"prediction_order_method", "search method for selecting prediction order", OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  687. {"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  688. {"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  689. {"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E},
  690. {"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
  691. {"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"},
  692. {"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D},
  693. {NULL},
  694. };
  695. #undef A
  696. #undef V
  697. #undef S
  698. #undef E
  699. #undef D
  700. #undef DEFAULT
  701. static AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
  702. void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){
  703. int flags=0;
  704. memset(s, 0, sizeof(AVCodecContext));
  705. s->av_class= &av_codec_context_class;
  706. s->codec_type = codec_type;
  707. if(codec_type == CODEC_TYPE_AUDIO)
  708. flags= AV_OPT_FLAG_AUDIO_PARAM;
  709. else if(codec_type == CODEC_TYPE_VIDEO)
  710. flags= AV_OPT_FLAG_VIDEO_PARAM;
  711. else if(codec_type == CODEC_TYPE_SUBTITLE)
  712. flags= AV_OPT_FLAG_SUBTITLE_PARAM;
  713. av_opt_set_defaults2(s, flags, flags);
  714. s->rc_eq= "tex^qComp";
  715. s->time_base= (AVRational){0,1};
  716. s->get_buffer= avcodec_default_get_buffer;
  717. s->release_buffer= avcodec_default_release_buffer;
  718. s->get_format= avcodec_default_get_format;
  719. s->execute= avcodec_default_execute;
  720. s->sample_aspect_ratio= (AVRational){0,1};
  721. s->pix_fmt= PIX_FMT_NONE;
  722. s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE
  723. s->palctrl = NULL;
  724. s->reget_buffer= avcodec_default_reget_buffer;
  725. }
  726. AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
  727. AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
  728. if(avctx==NULL) return NULL;
  729. avcodec_get_context_defaults2(avctx, codec_type);
  730. return avctx;
  731. }
  732. void avcodec_get_context_defaults(AVCodecContext *s){
  733. avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);
  734. }
  735. AVCodecContext *avcodec_alloc_context(void){
  736. return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);
  737. }
  738. void avcodec_get_frame_defaults(AVFrame *pic){
  739. memset(pic, 0, sizeof(AVFrame));
  740. pic->pts= AV_NOPTS_VALUE;
  741. pic->key_frame= 1;
  742. }
  743. AVFrame *avcodec_alloc_frame(void){
  744. AVFrame *pic= av_malloc(sizeof(AVFrame));
  745. if(pic==NULL) return NULL;
  746. avcodec_get_frame_defaults(pic);
  747. return pic;
  748. }
  749. int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
  750. {
  751. int ret= -1;
  752. entangled_thread_counter++;
  753. if(entangled_thread_counter != 1){
  754. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  755. goto end;
  756. }
  757. if(avctx->codec)
  758. goto end;
  759. if (codec->priv_data_size > 0) {
  760. avctx->priv_data = av_mallocz(codec->priv_data_size);
  761. if (!avctx->priv_data) {
  762. ret = AVERROR(ENOMEM);
  763. goto end;
  764. }
  765. } else {
  766. avctx->priv_data = NULL;
  767. }
  768. if(avctx->coded_width && avctx->coded_height)
  769. avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
  770. else if(avctx->width && avctx->height)
  771. avcodec_set_dimensions(avctx, avctx->width, avctx->height);
  772. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){
  773. av_freep(&avctx->priv_data);
  774. ret = AVERROR(EINVAL);
  775. goto end;
  776. }
  777. avctx->codec = codec;
  778. avctx->codec_id = codec->id;
  779. avctx->frame_number = 0;
  780. if(avctx->codec->init){
  781. ret = avctx->codec->init(avctx);
  782. if (ret < 0) {
  783. av_freep(&avctx->priv_data);
  784. avctx->codec= NULL;
  785. goto end;
  786. }
  787. }
  788. ret=0;
  789. end:
  790. entangled_thread_counter--;
  791. return ret;
  792. }
  793. int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  794. const short *samples)
  795. {
  796. if(buf_size < FF_MIN_BUFFER_SIZE && 0){
  797. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  798. return -1;
  799. }
  800. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
  801. int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
  802. avctx->frame_number++;
  803. return ret;
  804. }else
  805. return 0;
  806. }
  807. int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  808. const AVFrame *pict)
  809. {
  810. if(buf_size < FF_MIN_BUFFER_SIZE){
  811. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  812. return -1;
  813. }
  814. if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))
  815. return -1;
  816. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
  817. int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
  818. avctx->frame_number++;
  819. emms_c(); //needed to avoid an emms_c() call before every return;
  820. return ret;
  821. }else
  822. return 0;
  823. }
  824. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  825. const AVSubtitle *sub)
  826. {
  827. int ret;
  828. ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub);
  829. avctx->frame_number++;
  830. return ret;
  831. }
  832. int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  833. int *got_picture_ptr,
  834. uint8_t *buf, int buf_size)
  835. {
  836. int ret;
  837. *got_picture_ptr= 0;
  838. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
  839. return -1;
  840. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
  841. ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
  842. buf, buf_size);
  843. emms_c(); //needed to avoid an emms_c() call before every return;
  844. if (*got_picture_ptr)
  845. avctx->frame_number++;
  846. }else
  847. ret= 0;
  848. return ret;
  849. }
  850. int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
  851. int *frame_size_ptr,
  852. uint8_t *buf, int buf_size)
  853. {
  854. int ret;
  855. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
  856. //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
  857. if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
  858. av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
  859. return -1;
  860. }
  861. if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
  862. *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t) ||
  863. *frame_size_ptr < buf_size){
  864. av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
  865. return -1;
  866. }
  867. ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
  868. buf, buf_size);
  869. avctx->frame_number++;
  870. }else{
  871. ret= 0;
  872. *frame_size_ptr=0;
  873. }
  874. return ret;
  875. }
  876. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  877. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  878. int *frame_size_ptr,
  879. uint8_t *buf, int buf_size){
  880. *frame_size_ptr= AVCODEC_MAX_AUDIO_FRAME_SIZE;
  881. return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, buf_size);
  882. }
  883. #endif
  884. int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
  885. int *got_sub_ptr,
  886. const uint8_t *buf, int buf_size)
  887. {
  888. int ret;
  889. *got_sub_ptr = 0;
  890. ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
  891. (uint8_t *)buf, buf_size);
  892. if (*got_sub_ptr)
  893. avctx->frame_number++;
  894. return ret;
  895. }
  896. int avcodec_close(AVCodecContext *avctx)
  897. {
  898. entangled_thread_counter++;
  899. if(entangled_thread_counter != 1){
  900. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  901. entangled_thread_counter--;
  902. return -1;
  903. }
  904. if (ENABLE_THREADS && avctx->thread_opaque)
  905. avcodec_thread_free(avctx);
  906. if (avctx->codec->close)
  907. avctx->codec->close(avctx);
  908. avcodec_default_free_buffers(avctx);
  909. av_freep(&avctx->priv_data);
  910. avctx->codec = NULL;
  911. entangled_thread_counter--;
  912. return 0;
  913. }
  914. AVCodec *avcodec_find_encoder(enum CodecID id)
  915. {
  916. AVCodec *p;
  917. p = first_avcodec;
  918. while (p) {
  919. if (p->encode != NULL && p->id == id)
  920. return p;
  921. p = p->next;
  922. }
  923. return NULL;
  924. }
  925. AVCodec *avcodec_find_encoder_by_name(const char *name)
  926. {
  927. AVCodec *p;
  928. p = first_avcodec;
  929. while (p) {
  930. if (p->encode != NULL && strcmp(name,p->name) == 0)
  931. return p;
  932. p = p->next;
  933. }
  934. return NULL;
  935. }
  936. AVCodec *avcodec_find_decoder(enum CodecID id)
  937. {
  938. AVCodec *p;
  939. p = first_avcodec;
  940. while (p) {
  941. if (p->decode != NULL && p->id == id)
  942. return p;
  943. p = p->next;
  944. }
  945. return NULL;
  946. }
  947. AVCodec *avcodec_find_decoder_by_name(const char *name)
  948. {
  949. AVCodec *p;
  950. p = first_avcodec;
  951. while (p) {
  952. if (p->decode != NULL && strcmp(name,p->name) == 0)
  953. return p;
  954. p = p->next;
  955. }
  956. return NULL;
  957. }
  958. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  959. {
  960. const char *codec_name;
  961. AVCodec *p;
  962. char buf1[32];
  963. char channels_str[100];
  964. int bitrate;
  965. if (encode)
  966. p = avcodec_find_encoder(enc->codec_id);
  967. else
  968. p = avcodec_find_decoder(enc->codec_id);
  969. if (p) {
  970. codec_name = p->name;
  971. if (!encode && enc->codec_id == CODEC_ID_MP3) {
  972. if (enc->sub_id == 2)
  973. codec_name = "mp2";
  974. else if (enc->sub_id == 1)
  975. codec_name = "mp1";
  976. }
  977. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  978. /* fake mpeg2 transport stream codec (currently not
  979. registered) */
  980. codec_name = "mpeg2ts";
  981. } else if (enc->codec_name[0] != '\0') {
  982. codec_name = enc->codec_name;
  983. } else {
  984. /* output avi tags */
  985. if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
  986. && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
  987. snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
  988. enc->codec_tag & 0xff,
  989. (enc->codec_tag >> 8) & 0xff,
  990. (enc->codec_tag >> 16) & 0xff,
  991. (enc->codec_tag >> 24) & 0xff,
  992. enc->codec_tag);
  993. } else {
  994. snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
  995. }
  996. codec_name = buf1;
  997. }
  998. switch(enc->codec_type) {
  999. case CODEC_TYPE_VIDEO:
  1000. snprintf(buf, buf_size,
  1001. "Video: %s%s",
  1002. codec_name, enc->mb_decision ? " (hq)" : "");
  1003. if (enc->pix_fmt != PIX_FMT_NONE) {
  1004. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1005. ", %s",
  1006. avcodec_get_pix_fmt_name(enc->pix_fmt));
  1007. }
  1008. if (enc->width) {
  1009. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1010. ", %dx%d",
  1011. enc->width, enc->height);
  1012. if(av_log_level >= AV_LOG_DEBUG){
  1013. int g= ff_gcd(enc->time_base.num, enc->time_base.den);
  1014. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1015. ", %d/%d",
  1016. enc->time_base.num/g, enc->time_base.den/g);
  1017. }
  1018. }
  1019. if (encode) {
  1020. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1021. ", q=%d-%d", enc->qmin, enc->qmax);
  1022. }
  1023. bitrate = enc->bit_rate;
  1024. break;
  1025. case CODEC_TYPE_AUDIO:
  1026. snprintf(buf, buf_size,
  1027. "Audio: %s",
  1028. codec_name);
  1029. switch (enc->channels) {
  1030. case 1:
  1031. strcpy(channels_str, "mono");
  1032. break;
  1033. case 2:
  1034. strcpy(channels_str, "stereo");
  1035. break;
  1036. case 6:
  1037. strcpy(channels_str, "5:1");
  1038. break;
  1039. default:
  1040. snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels);
  1041. break;
  1042. }
  1043. if (enc->sample_rate) {
  1044. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1045. ", %d Hz, %s",
  1046. enc->sample_rate,
  1047. channels_str);
  1048. }
  1049. /* for PCM codecs, compute bitrate directly */
  1050. switch(enc->codec_id) {
  1051. case CODEC_ID_PCM_S32LE:
  1052. case CODEC_ID_PCM_S32BE:
  1053. case CODEC_ID_PCM_U32LE:
  1054. case CODEC_ID_PCM_U32BE:
  1055. bitrate = enc->sample_rate * enc->channels * 32;
  1056. break;
  1057. case CODEC_ID_PCM_S24LE:
  1058. case CODEC_ID_PCM_S24BE:
  1059. case CODEC_ID_PCM_U24LE:
  1060. case CODEC_ID_PCM_U24BE:
  1061. case CODEC_ID_PCM_S24DAUD:
  1062. bitrate = enc->sample_rate * enc->channels * 24;
  1063. break;
  1064. case CODEC_ID_PCM_S16LE:
  1065. case CODEC_ID_PCM_S16BE:
  1066. case CODEC_ID_PCM_U16LE:
  1067. case CODEC_ID_PCM_U16BE:
  1068. bitrate = enc->sample_rate * enc->channels * 16;
  1069. break;
  1070. case CODEC_ID_PCM_S8:
  1071. case CODEC_ID_PCM_U8:
  1072. case CODEC_ID_PCM_ALAW:
  1073. case CODEC_ID_PCM_MULAW:
  1074. bitrate = enc->sample_rate * enc->channels * 8;
  1075. break;
  1076. default:
  1077. bitrate = enc->bit_rate;
  1078. break;
  1079. }
  1080. break;
  1081. case CODEC_TYPE_DATA:
  1082. snprintf(buf, buf_size, "Data: %s", codec_name);
  1083. bitrate = enc->bit_rate;
  1084. break;
  1085. case CODEC_TYPE_SUBTITLE:
  1086. snprintf(buf, buf_size, "Subtitle: %s", codec_name);
  1087. bitrate = enc->bit_rate;
  1088. break;
  1089. default:
  1090. snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
  1091. return;
  1092. }
  1093. if (encode) {
  1094. if (enc->flags & CODEC_FLAG_PASS1)
  1095. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1096. ", pass 1");
  1097. if (enc->flags & CODEC_FLAG_PASS2)
  1098. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1099. ", pass 2");
  1100. }
  1101. if (bitrate != 0) {
  1102. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1103. ", %d kb/s", bitrate / 1000);
  1104. }
  1105. }
  1106. unsigned avcodec_version( void )
  1107. {
  1108. return LIBAVCODEC_VERSION_INT;
  1109. }
  1110. unsigned avcodec_build( void )
  1111. {
  1112. return LIBAVCODEC_BUILD;
  1113. }
  1114. static void init_crcs(void){
  1115. #if LIBAVUTIL_VERSION_INT < (50<<16)
  1116. av_crc04C11DB7= av_mallocz_static(sizeof(AVCRC) * 257);
  1117. av_crc8005 = av_mallocz_static(sizeof(AVCRC) * 257);
  1118. av_crc07 = av_mallocz_static(sizeof(AVCRC) * 257);
  1119. #endif
  1120. av_crc_init(av_crc04C11DB7, 0, 32, AV_CRC_32_IEEE, sizeof(AVCRC)*257);
  1121. av_crc_init(av_crc8005 , 0, 16, AV_CRC_16 , sizeof(AVCRC)*257);
  1122. av_crc_init(av_crc07 , 0, 8, AV_CRC_8_ATM , sizeof(AVCRC)*257);
  1123. }
  1124. void avcodec_init(void)
  1125. {
  1126. static int inited = 0;
  1127. if (inited != 0)
  1128. return;
  1129. inited = 1;
  1130. dsputil_static_init();
  1131. init_crcs();
  1132. }
  1133. void avcodec_flush_buffers(AVCodecContext *avctx)
  1134. {
  1135. if(avctx->codec->flush)
  1136. avctx->codec->flush(avctx);
  1137. }
  1138. void avcodec_default_free_buffers(AVCodecContext *s){
  1139. int i, j;
  1140. if(s->internal_buffer==NULL) return;
  1141. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  1142. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  1143. for(j=0; j<4; j++){
  1144. av_freep(&buf->base[j]);
  1145. buf->data[j]= NULL;
  1146. }
  1147. }
  1148. av_freep(&s->internal_buffer);
  1149. s->internal_buffer_count=0;
  1150. }
  1151. char av_get_pict_type_char(int pict_type){
  1152. switch(pict_type){
  1153. case I_TYPE: return 'I';
  1154. case P_TYPE: return 'P';
  1155. case B_TYPE: return 'B';
  1156. case S_TYPE: return 'S';
  1157. case SI_TYPE:return 'i';
  1158. case SP_TYPE:return 'p';
  1159. default: return '?';
  1160. }
  1161. }
  1162. int av_get_bits_per_sample(enum CodecID codec_id){
  1163. switch(codec_id){
  1164. case CODEC_ID_ADPCM_SBPRO_2:
  1165. return 2;
  1166. case CODEC_ID_ADPCM_SBPRO_3:
  1167. return 3;
  1168. case CODEC_ID_ADPCM_SBPRO_4:
  1169. case CODEC_ID_ADPCM_CT:
  1170. return 4;
  1171. case CODEC_ID_PCM_ALAW:
  1172. case CODEC_ID_PCM_MULAW:
  1173. case CODEC_ID_PCM_S8:
  1174. case CODEC_ID_PCM_U8:
  1175. return 8;
  1176. case CODEC_ID_PCM_S16BE:
  1177. case CODEC_ID_PCM_S16LE:
  1178. case CODEC_ID_PCM_U16BE:
  1179. case CODEC_ID_PCM_U16LE:
  1180. return 16;
  1181. case CODEC_ID_PCM_S24DAUD:
  1182. case CODEC_ID_PCM_S24BE:
  1183. case CODEC_ID_PCM_S24LE:
  1184. case CODEC_ID_PCM_U24BE:
  1185. case CODEC_ID_PCM_U24LE:
  1186. return 24;
  1187. case CODEC_ID_PCM_S32BE:
  1188. case CODEC_ID_PCM_S32LE:
  1189. case CODEC_ID_PCM_U32BE:
  1190. case CODEC_ID_PCM_U32LE:
  1191. return 32;
  1192. default:
  1193. return 0;
  1194. }
  1195. }
  1196. int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
  1197. switch (sample_fmt) {
  1198. case SAMPLE_FMT_U8:
  1199. return 8;
  1200. case SAMPLE_FMT_S16:
  1201. return 16;
  1202. case SAMPLE_FMT_S24:
  1203. return 24;
  1204. case SAMPLE_FMT_S32:
  1205. case SAMPLE_FMT_FLT:
  1206. return 32;
  1207. default:
  1208. return 0;
  1209. }
  1210. }
  1211. #if !defined(HAVE_THREADS)
  1212. int avcodec_thread_init(AVCodecContext *s, int thread_count){
  1213. return -1;
  1214. }
  1215. #endif
  1216. unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  1217. {
  1218. unsigned int n = 0;
  1219. while(v >= 0xff) {
  1220. *s++ = 0xff;
  1221. v -= 0xff;
  1222. n++;
  1223. }
  1224. *s = v;
  1225. n++;
  1226. return n;
  1227. }
  1228. /* Wrapper to work around the lack of mkstemp() on mingw/cygin.
  1229. * Also, tries to create file in /tmp first, if possible.
  1230. * *prefix can be a character constant; *filename will be allocated internally.
  1231. * Returns file descriptor of opened file (or -1 on error)
  1232. * and opened file name in **filename. */
  1233. int av_tempfile(char *prefix, char **filename) {
  1234. int fd=-1;
  1235. #if !defined(HAVE_MKSTEMP)
  1236. *filename = tempnam(".", prefix);
  1237. #else
  1238. size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
  1239. *filename = av_malloc(len);
  1240. #endif
  1241. /* -----common section-----*/
  1242. if (*filename == NULL) {
  1243. av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
  1244. return -1;
  1245. }
  1246. #if !defined(HAVE_MKSTEMP)
  1247. fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
  1248. #else
  1249. snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
  1250. fd = mkstemp(*filename);
  1251. if (fd < 0) {
  1252. snprintf(*filename, len, "./%sXXXXXX", prefix);
  1253. fd = mkstemp(*filename);
  1254. }
  1255. #endif
  1256. /* -----common section-----*/
  1257. if (fd < 0) {
  1258. av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
  1259. return -1;
  1260. }
  1261. return fd; /* success */
  1262. }
  1263. typedef struct {
  1264. const char *abbr;
  1265. int width, height;
  1266. } VideoFrameSizeAbbr;
  1267. typedef struct {
  1268. const char *abbr;
  1269. int rate_num, rate_den;
  1270. } VideoFrameRateAbbr;
  1271. static VideoFrameSizeAbbr video_frame_size_abbrs[] = {
  1272. { "ntsc", 720, 480 },
  1273. { "pal", 720, 576 },
  1274. { "qntsc", 352, 240 }, /* VCD compliant NTSC */
  1275. { "qpal", 352, 288 }, /* VCD compliant PAL */
  1276. { "sntsc", 640, 480 }, /* square pixel NTSC */
  1277. { "spal", 768, 576 }, /* square pixel PAL */
  1278. { "film", 352, 240 },
  1279. { "ntsc-film", 352, 240 },
  1280. { "sqcif", 128, 96 },
  1281. { "qcif", 176, 144 },
  1282. { "cif", 352, 288 },
  1283. { "4cif", 704, 576 },
  1284. { "qqvga", 160, 120 },
  1285. { "qvga", 320, 240 },
  1286. { "vga", 640, 480 },
  1287. { "svga", 800, 600 },
  1288. { "xga", 1024, 768 },
  1289. { "uxga", 1600,1200 },
  1290. { "qxga", 2048,1536 },
  1291. { "sxga", 1280,1024 },
  1292. { "qsxga", 2560,2048 },
  1293. { "hsxga", 5120,4096 },
  1294. { "wvga", 852, 480 },
  1295. { "wxga", 1366, 768 },
  1296. { "wsxga", 1600,1024 },
  1297. { "wuxga", 1920,1200 },
  1298. { "woxga", 2560,1600 },
  1299. { "wqsxga", 3200,2048 },
  1300. { "wquxga", 3840,2400 },
  1301. { "whsxga", 6400,4096 },
  1302. { "whuxga", 7680,4800 },
  1303. { "cga", 320, 200 },
  1304. { "ega", 640, 350 },
  1305. { "hd480", 852, 480 },
  1306. { "hd720", 1280, 720 },
  1307. { "hd1080", 1920,1080 },
  1308. };
  1309. static VideoFrameRateAbbr video_frame_rate_abbrs[]= {
  1310. { "ntsc", 30000, 1001 },
  1311. { "pal", 25, 1 },
  1312. { "qntsc", 30000, 1001 }, /* VCD compliant NTSC */
  1313. { "qpal", 25, 1 }, /* VCD compliant PAL */
  1314. { "sntsc", 30000, 1001 }, /* square pixel NTSC */
  1315. { "spal", 25, 1 }, /* square pixel PAL */
  1316. { "film", 24, 1 },
  1317. { "ntsc-film", 24000, 1001 },
  1318. };
  1319. int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
  1320. {
  1321. int i;
  1322. int n = sizeof(video_frame_size_abbrs) / sizeof(VideoFrameSizeAbbr);
  1323. const char *p;
  1324. int frame_width = 0, frame_height = 0;
  1325. for(i=0;i<n;i++) {
  1326. if (!strcmp(video_frame_size_abbrs[i].abbr, str)) {
  1327. frame_width = video_frame_size_abbrs[i].width;
  1328. frame_height = video_frame_size_abbrs[i].height;
  1329. break;
  1330. }
  1331. }
  1332. if (i == n) {
  1333. p = str;
  1334. frame_width = strtol(p, (char **)&p, 10);
  1335. if (*p)
  1336. p++;
  1337. frame_height = strtol(p, (char **)&p, 10);
  1338. }
  1339. if (frame_width <= 0 || frame_height <= 0)
  1340. return -1;
  1341. *width_ptr = frame_width;
  1342. *height_ptr = frame_height;
  1343. return 0;
  1344. }
  1345. int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
  1346. {
  1347. int i;
  1348. int n = sizeof(video_frame_rate_abbrs) / sizeof(VideoFrameRateAbbr);
  1349. char* cp;
  1350. /* First, we check our abbreviation table */
  1351. for (i = 0; i < n; ++i)
  1352. if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) {
  1353. frame_rate->num = video_frame_rate_abbrs[i].rate_num;
  1354. frame_rate->den = video_frame_rate_abbrs[i].rate_den;
  1355. return 0;
  1356. }
  1357. /* Then, we try to parse it as fraction */
  1358. cp = strchr(arg, '/');
  1359. if (!cp)
  1360. cp = strchr(arg, ':');
  1361. if (cp) {
  1362. char* cpp;
  1363. frame_rate->num = strtol(arg, &cpp, 10);
  1364. if (cpp != arg || cpp == cp)
  1365. frame_rate->den = strtol(cp+1, &cpp, 10);
  1366. else
  1367. frame_rate->num = 0;
  1368. }
  1369. else {
  1370. /* Finally we give up and parse it as double */
  1371. AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
  1372. frame_rate->den = time_base.den;
  1373. frame_rate->num = time_base.num;
  1374. }
  1375. if (!frame_rate->num || !frame_rate->den)
  1376. return -1;
  1377. else
  1378. return 0;
  1379. }