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.

1536 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 "integer.h"
  29. #include "opt.h"
  30. #include "crc.h"
  31. #include "imgconvert.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. ptr= av_realloc(ptr, *size);
  63. if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
  64. *size= 0;
  65. return ptr;
  66. }
  67. static unsigned int last_static = 0;
  68. static unsigned int allocated_static = 0;
  69. static void** array_static = NULL;
  70. void *av_mallocz_static(unsigned int size)
  71. {
  72. void *ptr = av_mallocz(size);
  73. if(ptr){
  74. array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1));
  75. if(!array_static)
  76. return NULL;
  77. array_static[last_static++] = ptr;
  78. }
  79. return ptr;
  80. }
  81. void *ff_realloc_static(void *ptr, unsigned int size)
  82. {
  83. int i;
  84. if(!ptr)
  85. return av_mallocz_static(size);
  86. /* Look for the old ptr */
  87. for(i = 0; i < last_static; i++) {
  88. if(array_static[i] == ptr) {
  89. array_static[i] = av_realloc(array_static[i], size);
  90. return array_static[i];
  91. }
  92. }
  93. return NULL;
  94. }
  95. void av_free_static(void)
  96. {
  97. while(last_static){
  98. av_freep(&array_static[--last_static]);
  99. }
  100. av_freep(&array_static);
  101. }
  102. /**
  103. * Call av_free_static automatically before it's too late
  104. */
  105. static void do_free(void) __attribute__ ((destructor));
  106. static void do_free(void)
  107. {
  108. av_free_static();
  109. }
  110. /* encoder management */
  111. AVCodec *first_avcodec = NULL;
  112. AVCodec *av_codec_next(AVCodec *c){
  113. if(c) return c->next;
  114. else return first_avcodec;
  115. }
  116. void register_avcodec(AVCodec *format)
  117. {
  118. AVCodec **p;
  119. p = &first_avcodec;
  120. while (*p != NULL) p = &(*p)->next;
  121. *p = format;
  122. format->next = NULL;
  123. }
  124. void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
  125. s->coded_width = width;
  126. s->coded_height= height;
  127. s->width = -((-width )>>s->lowres);
  128. s->height= -((-height)>>s->lowres);
  129. }
  130. typedef struct InternalBuffer{
  131. int last_pic_num;
  132. uint8_t *base[4];
  133. uint8_t *data[4];
  134. int linesize[4];
  135. int width, height;
  136. enum PixelFormat pix_fmt;
  137. }InternalBuffer;
  138. #define INTERNAL_BUFFER_SIZE 32
  139. #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
  140. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
  141. int w_align= 1;
  142. int h_align= 1;
  143. switch(s->pix_fmt){
  144. case PIX_FMT_YUV420P:
  145. case PIX_FMT_YUYV422:
  146. case PIX_FMT_UYVY422:
  147. case PIX_FMT_YUV422P:
  148. case PIX_FMT_YUV444P:
  149. case PIX_FMT_GRAY8:
  150. case PIX_FMT_GRAY16BE:
  151. case PIX_FMT_GRAY16LE:
  152. case PIX_FMT_YUVJ420P:
  153. case PIX_FMT_YUVJ422P:
  154. case PIX_FMT_YUVJ444P:
  155. case PIX_FMT_YUVA420P:
  156. w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
  157. h_align= 16;
  158. break;
  159. case PIX_FMT_YUV411P:
  160. case PIX_FMT_UYYVYY411:
  161. w_align=32;
  162. h_align=8;
  163. break;
  164. case PIX_FMT_YUV410P:
  165. if(s->codec_id == CODEC_ID_SVQ1){
  166. w_align=64;
  167. h_align=64;
  168. }
  169. case PIX_FMT_RGB555:
  170. if(s->codec_id == CODEC_ID_RPZA){
  171. w_align=4;
  172. h_align=4;
  173. }
  174. case PIX_FMT_PAL8:
  175. if(s->codec_id == CODEC_ID_SMC){
  176. w_align=4;
  177. h_align=4;
  178. }
  179. break;
  180. case PIX_FMT_BGR24:
  181. if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
  182. w_align=4;
  183. h_align=4;
  184. }
  185. break;
  186. default:
  187. w_align= 1;
  188. h_align= 1;
  189. break;
  190. }
  191. *width = ALIGN(*width , w_align);
  192. *height= ALIGN(*height, h_align);
  193. }
  194. int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
  195. if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/4)
  196. return 0;
  197. av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h);
  198. return -1;
  199. }
  200. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
  201. int i;
  202. int w= s->width;
  203. int h= s->height;
  204. InternalBuffer *buf;
  205. int *picture_number;
  206. if(pic->data[0]!=NULL) {
  207. av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
  208. return -1;
  209. }
  210. if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
  211. av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
  212. return -1;
  213. }
  214. if(avcodec_check_dimensions(s,w,h))
  215. return -1;
  216. if(s->internal_buffer==NULL){
  217. s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
  218. }
  219. #if 0
  220. s->internal_buffer= av_fast_realloc(
  221. s->internal_buffer,
  222. &s->internal_buffer_size,
  223. sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
  224. );
  225. #endif
  226. buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  227. picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack
  228. (*picture_number)++;
  229. if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
  230. for(i=0; i<4; i++){
  231. av_freep(&buf->base[i]);
  232. buf->data[i]= NULL;
  233. }
  234. }
  235. if(buf->base[0]){
  236. pic->age= *picture_number - buf->last_pic_num;
  237. buf->last_pic_num= *picture_number;
  238. }else{
  239. int h_chroma_shift, v_chroma_shift;
  240. int size[4] = {0};
  241. int tmpsize;
  242. AVPicture picture;
  243. avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
  244. avcodec_align_dimensions(s, &w, &h);
  245. if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
  246. w+= EDGE_WIDTH*2;
  247. h+= EDGE_WIDTH*2;
  248. }
  249. avcodec_align_dimensions(s, &w, &h);
  250. ff_fill_linesize(&picture, s->pix_fmt, w);
  251. for (i=0; i<4; i++)
  252. picture.linesize[i] = ALIGN(picture.linesize[i], STRIDE_ALIGN);
  253. tmpsize = ff_fill_pointer(&picture, NULL, s->pix_fmt, h);
  254. for (i=0; i<3 && picture.data[i+1]; i++)
  255. size[i] = picture.data[i+1] - picture.data[i];
  256. size[i] = tmpsize - (picture.data[i] - picture.data[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<4 && 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<4; 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, 0, UINT_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, A|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. {"faani", "floating point AAN IDCT", 0, FF_OPT_TYPE_CONST, FF_IDCT_FAAN, INT_MIN, INT_MAX, V|D|E, "idct"},
  533. {"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  534. {"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
  535. {"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
  536. {"deblock", "use strong deblock filter for damaged MBs", 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"},
  537. {"bits_per_sample", NULL, OFFSET(bits_per_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  538. {"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"},
  539. {"left", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"},
  540. {"plane", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"},
  541. {"median", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"},
  542. {"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E},
  543. {"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"},
  544. {"pict", "picture info", 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"},
  545. {"rc", "rate control", 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"},
  546. {"bitstream", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"},
  547. {"mb_type", "macroblock (MB) type", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
  548. {"qp", "per-block quantization parameter (QP)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"},
  549. {"mv", "motion vector", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"},
  550. {"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"},
  551. {"skip", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"},
  552. {"startcode", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"},
  553. {"pts", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"},
  554. {"er", "error resilience", 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"},
  555. {"mmco", "memory management control operations (H.264)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"},
  556. {"bugs", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"},
  557. {"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"},
  558. {"vis_mb_type", "visualize block types", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
  559. {"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"},
  560. {"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"},
  561. {"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"},
  562. {"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"},
  563. {"mb_qmin", "obsolete, use qmin", OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  564. {"mb_qmax", "obsolete, use qmax", OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  565. {"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  566. {"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  567. {"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  568. {"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  569. {"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  570. {"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},
  571. {"preme", "pre motion estimation", OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  572. {"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  573. {"sad", "sum of absolute differences, fast (default)", 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  574. {"sse", "sum of squared errors", 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  575. {"satd", "sum of absolute Hadamard transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  576. {"dct", "sum of absolute DCT transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  577. {"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"},
  578. {"bit", "number of bits needed for the block", 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  579. {"rd", "rate distortion optimal, slow", 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  580. {"zero", "0", 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"},
  581. {"vsad", "sum of absolute vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  582. {"vsse","sum of squared vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  583. {"nsse", "noise preserving sum of squared differences", 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  584. #ifdef CONFIG_SNOW_ENCODER
  585. {"w53", "5/3 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"},
  586. {"w97", "9/7 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"},
  587. #endif
  588. {"dctmax", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
  589. {"chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"},
  590. {"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},
  591. {"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
  592. {"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  593. {"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  594. {"ibias", "intra quant bias", OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
  595. {"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E},
  596. {"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  597. {"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  598. {"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  599. {"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
  600. {"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
  601. {"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
  602. {"raw", "raw (no encoding)", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RAW, INT_MIN, INT_MAX, V|E, "coder"},
  603. {"rle", "run-length coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RLE, INT_MIN, INT_MAX, V|E, "coder"},
  604. {"deflate", "deflate-based coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_DEFLATE, INT_MIN, INT_MAX, V|E, "coder"},
  605. {"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  606. {"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  607. {"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  608. {"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"},
  609. {"simple", "use mbcmp (default)", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"},
  610. {"bits", "use fewest bits", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"},
  611. {"rd", "use best rate distortion", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"},
  612. {"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  613. {"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  614. {"lmin", "min lagrange factor (VBR)", OFFSET(lmin), FF_OPT_TYPE_INT, 2*FF_QP2LAMBDA, 0, INT_MAX, V|E},
  615. {"lmax", "max lagrange factor (VBR)", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E},
  616. {"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  617. {"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},
  618. {"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  619. {"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR, 0, UINT_MAX, V|A|E|D, "flags2"},
  620. {"error", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  621. {"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"},
  622. {"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"},
  623. {"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"},
  624. {"int", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"},
  625. {"float", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"},
  626. {"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  627. {"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E|D},
  628. {"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  629. {"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  630. {"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
  631. {"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
  632. {"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},
  633. {"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},
  634. {"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
  635. {"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
  636. {"aac_main", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_MAIN, INT_MIN, INT_MAX, A|E, "profile"},
  637. {"aac_low", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LOW, INT_MIN, INT_MAX, A|E, "profile"},
  638. {"aac_ssr", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_SSR, INT_MIN, INT_MAX, A|E, "profile"},
  639. {"aac_ltp", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LTP, INT_MIN, INT_MAX, A|E, "profile"},
  640. {"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
  641. {"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
  642. {"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},
  643. {"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  644. {"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  645. {"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  646. {"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
  647. {"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
  648. {"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 2, 1, FF_LAMBDA_MAX, V|E},
  649. {"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 31, 1, FF_LAMBDA_MAX, V|E},
  650. {"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, 256, INT_MIN, INT_MAX, V|E},
  651. {"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 0, 4, V|E},
  652. {"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, DEFAULT, 0, 10, V|E},
  653. {"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E},
  654. {"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, V|E},
  655. {"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, 25, INT_MIN, INT_MAX, V|E},
  656. {"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E},
  657. {"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  658. {"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  659. {"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
  660. {"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal)", OFFSET(directpred), FF_OPT_TYPE_INT, 2, INT_MIN, INT_MAX, V|E},
  661. {"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"},
  662. {"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"},
  663. {"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"},
  664. {"dct8x8", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
  665. {"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"},
  666. {"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"},
  667. {"brdo", "b-frame rate-distortion optimization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BRDO, INT_MIN, INT_MAX, V|E, "flags2"},
  668. {"skiprd", "RD optimal MB level residual skipping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"},
  669. {"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E},
  670. {"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
  671. {"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
  672. {"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "partitions"},
  673. {"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I4X4, INT_MIN, INT_MAX, V|E, "partitions"},
  674. {"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I8X8, INT_MIN, INT_MAX, V|E, "partitions"},
  675. {"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"},
  676. {"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"},
  677. {"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
  678. {"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},
  679. {"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E},
  680. {"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
  681. {"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
  682. {"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E},
  683. {"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  684. {"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
  685. {"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  686. {"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  687. {"prediction_order_method", "search method for selecting prediction order", OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  688. {"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  689. {"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
  690. {"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},
  691. {"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
  692. {"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"},
  693. {"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D},
  694. {"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D},
  695. {"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"},
  696. {NULL},
  697. };
  698. #undef A
  699. #undef V
  700. #undef S
  701. #undef E
  702. #undef D
  703. #undef DEFAULT
  704. static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
  705. void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){
  706. int flags=0;
  707. memset(s, 0, sizeof(AVCodecContext));
  708. s->av_class= &av_codec_context_class;
  709. s->codec_type = codec_type;
  710. if(codec_type == CODEC_TYPE_AUDIO)
  711. flags= AV_OPT_FLAG_AUDIO_PARAM;
  712. else if(codec_type == CODEC_TYPE_VIDEO)
  713. flags= AV_OPT_FLAG_VIDEO_PARAM;
  714. else if(codec_type == CODEC_TYPE_SUBTITLE)
  715. flags= AV_OPT_FLAG_SUBTITLE_PARAM;
  716. av_opt_set_defaults2(s, flags, flags);
  717. s->rc_eq= "tex^qComp";
  718. s->time_base= (AVRational){0,1};
  719. s->get_buffer= avcodec_default_get_buffer;
  720. s->release_buffer= avcodec_default_release_buffer;
  721. s->get_format= avcodec_default_get_format;
  722. s->execute= avcodec_default_execute;
  723. s->sample_aspect_ratio= (AVRational){0,1};
  724. s->pix_fmt= PIX_FMT_NONE;
  725. s->sample_fmt= SAMPLE_FMT_S16; // FIXME: set to NONE
  726. s->palctrl = NULL;
  727. s->reget_buffer= avcodec_default_reget_buffer;
  728. }
  729. AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
  730. AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
  731. if(avctx==NULL) return NULL;
  732. avcodec_get_context_defaults2(avctx, codec_type);
  733. return avctx;
  734. }
  735. void avcodec_get_context_defaults(AVCodecContext *s){
  736. avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);
  737. }
  738. AVCodecContext *avcodec_alloc_context(void){
  739. return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);
  740. }
  741. void avcodec_get_frame_defaults(AVFrame *pic){
  742. memset(pic, 0, sizeof(AVFrame));
  743. pic->pts= AV_NOPTS_VALUE;
  744. pic->key_frame= 1;
  745. }
  746. AVFrame *avcodec_alloc_frame(void){
  747. AVFrame *pic= av_malloc(sizeof(AVFrame));
  748. if(pic==NULL) return NULL;
  749. avcodec_get_frame_defaults(pic);
  750. return pic;
  751. }
  752. int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
  753. {
  754. int ret= -1;
  755. entangled_thread_counter++;
  756. if(entangled_thread_counter != 1){
  757. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  758. goto end;
  759. }
  760. if(avctx->codec || !codec)
  761. goto end;
  762. if (codec->priv_data_size > 0) {
  763. avctx->priv_data = av_mallocz(codec->priv_data_size);
  764. if (!avctx->priv_data) {
  765. ret = AVERROR(ENOMEM);
  766. goto end;
  767. }
  768. } else {
  769. avctx->priv_data = NULL;
  770. }
  771. if(avctx->coded_width && avctx->coded_height)
  772. avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
  773. else if(avctx->width && avctx->height)
  774. avcodec_set_dimensions(avctx, avctx->width, avctx->height);
  775. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){
  776. av_freep(&avctx->priv_data);
  777. ret = AVERROR(EINVAL);
  778. goto end;
  779. }
  780. avctx->codec = codec;
  781. avctx->codec_id = codec->id;
  782. avctx->frame_number = 0;
  783. if(avctx->codec->init){
  784. ret = avctx->codec->init(avctx);
  785. if (ret < 0) {
  786. av_freep(&avctx->priv_data);
  787. avctx->codec= NULL;
  788. goto end;
  789. }
  790. }
  791. ret=0;
  792. end:
  793. entangled_thread_counter--;
  794. return ret;
  795. }
  796. int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  797. const short *samples)
  798. {
  799. if(buf_size < FF_MIN_BUFFER_SIZE && 0){
  800. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  801. return -1;
  802. }
  803. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
  804. int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
  805. avctx->frame_number++;
  806. return ret;
  807. }else
  808. return 0;
  809. }
  810. int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  811. const AVFrame *pict)
  812. {
  813. if(buf_size < FF_MIN_BUFFER_SIZE){
  814. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  815. return -1;
  816. }
  817. if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))
  818. return -1;
  819. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
  820. int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
  821. avctx->frame_number++;
  822. emms_c(); //needed to avoid an emms_c() call before every return;
  823. return ret;
  824. }else
  825. return 0;
  826. }
  827. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  828. const AVSubtitle *sub)
  829. {
  830. int ret;
  831. ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub);
  832. avctx->frame_number++;
  833. return ret;
  834. }
  835. int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  836. int *got_picture_ptr,
  837. const uint8_t *buf, int buf_size)
  838. {
  839. int ret;
  840. *got_picture_ptr= 0;
  841. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
  842. return -1;
  843. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
  844. ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
  845. buf, buf_size);
  846. emms_c(); //needed to avoid an emms_c() call before every return;
  847. if (*got_picture_ptr)
  848. avctx->frame_number++;
  849. }else
  850. ret= 0;
  851. return ret;
  852. }
  853. int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
  854. int *frame_size_ptr,
  855. const uint8_t *buf, int buf_size)
  856. {
  857. int ret;
  858. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
  859. //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
  860. if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
  861. av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
  862. return -1;
  863. }
  864. if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
  865. *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
  866. av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
  867. return -1;
  868. }
  869. ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
  870. buf, buf_size);
  871. avctx->frame_number++;
  872. }else{
  873. ret= 0;
  874. *frame_size_ptr=0;
  875. }
  876. return ret;
  877. }
  878. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  879. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  880. int *frame_size_ptr,
  881. const uint8_t *buf, int buf_size){
  882. *frame_size_ptr= AVCODEC_MAX_AUDIO_FRAME_SIZE;
  883. return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, buf_size);
  884. }
  885. #endif
  886. int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
  887. int *got_sub_ptr,
  888. const uint8_t *buf, int buf_size)
  889. {
  890. int ret;
  891. *got_sub_ptr = 0;
  892. ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
  893. buf, buf_size);
  894. if (*got_sub_ptr)
  895. avctx->frame_number++;
  896. return ret;
  897. }
  898. int avcodec_close(AVCodecContext *avctx)
  899. {
  900. entangled_thread_counter++;
  901. if(entangled_thread_counter != 1){
  902. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  903. entangled_thread_counter--;
  904. return -1;
  905. }
  906. if (ENABLE_THREADS && avctx->thread_opaque)
  907. avcodec_thread_free(avctx);
  908. if (avctx->codec->close)
  909. avctx->codec->close(avctx);
  910. avcodec_default_free_buffers(avctx);
  911. av_freep(&avctx->priv_data);
  912. avctx->codec = NULL;
  913. entangled_thread_counter--;
  914. return 0;
  915. }
  916. AVCodec *avcodec_find_encoder(enum CodecID id)
  917. {
  918. AVCodec *p;
  919. p = first_avcodec;
  920. while (p) {
  921. if (p->encode != NULL && p->id == id)
  922. return p;
  923. p = p->next;
  924. }
  925. return NULL;
  926. }
  927. AVCodec *avcodec_find_encoder_by_name(const char *name)
  928. {
  929. AVCodec *p;
  930. p = first_avcodec;
  931. while (p) {
  932. if (p->encode != NULL && strcmp(name,p->name) == 0)
  933. return p;
  934. p = p->next;
  935. }
  936. return NULL;
  937. }
  938. AVCodec *avcodec_find_decoder(enum CodecID id)
  939. {
  940. AVCodec *p;
  941. p = first_avcodec;
  942. while (p) {
  943. if (p->decode != NULL && p->id == id)
  944. return p;
  945. p = p->next;
  946. }
  947. return NULL;
  948. }
  949. AVCodec *avcodec_find_decoder_by_name(const char *name)
  950. {
  951. AVCodec *p;
  952. p = first_avcodec;
  953. while (p) {
  954. if (p->decode != NULL && strcmp(name,p->name) == 0)
  955. return p;
  956. p = p->next;
  957. }
  958. return NULL;
  959. }
  960. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  961. {
  962. const char *codec_name;
  963. AVCodec *p;
  964. char buf1[32];
  965. char channels_str[100];
  966. int bitrate;
  967. AVRational display_aspect_ratio;
  968. if (encode)
  969. p = avcodec_find_encoder(enc->codec_id);
  970. else
  971. p = avcodec_find_decoder(enc->codec_id);
  972. if (p) {
  973. codec_name = p->name;
  974. if (!encode && enc->codec_id == CODEC_ID_MP3) {
  975. if (enc->sub_id == 2)
  976. codec_name = "mp2";
  977. else if (enc->sub_id == 1)
  978. codec_name = "mp1";
  979. }
  980. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  981. /* fake mpeg2 transport stream codec (currently not
  982. registered) */
  983. codec_name = "mpeg2ts";
  984. } else if (enc->codec_name[0] != '\0') {
  985. codec_name = enc->codec_name;
  986. } else {
  987. /* output avi tags */
  988. if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
  989. && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
  990. snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
  991. enc->codec_tag & 0xff,
  992. (enc->codec_tag >> 8) & 0xff,
  993. (enc->codec_tag >> 16) & 0xff,
  994. (enc->codec_tag >> 24) & 0xff,
  995. enc->codec_tag);
  996. } else {
  997. snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
  998. }
  999. codec_name = buf1;
  1000. }
  1001. switch(enc->codec_type) {
  1002. case CODEC_TYPE_VIDEO:
  1003. snprintf(buf, buf_size,
  1004. "Video: %s%s",
  1005. codec_name, enc->mb_decision ? " (hq)" : "");
  1006. if (enc->pix_fmt != PIX_FMT_NONE) {
  1007. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1008. ", %s",
  1009. avcodec_get_pix_fmt_name(enc->pix_fmt));
  1010. }
  1011. if (enc->width) {
  1012. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1013. ", %dx%d",
  1014. enc->width, enc->height);
  1015. if (enc->sample_aspect_ratio.num) {
  1016. av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
  1017. enc->width*enc->sample_aspect_ratio.num,
  1018. enc->height*enc->sample_aspect_ratio.den,
  1019. 1024*1024);
  1020. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1021. " [PAR %d:%d DAR %d:%d]",
  1022. enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
  1023. display_aspect_ratio.num, display_aspect_ratio.den);
  1024. }
  1025. if(av_log_get_level() >= AV_LOG_DEBUG){
  1026. int g= ff_gcd(enc->time_base.num, enc->time_base.den);
  1027. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1028. ", %d/%d",
  1029. enc->time_base.num/g, enc->time_base.den/g);
  1030. }
  1031. }
  1032. if (encode) {
  1033. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1034. ", q=%d-%d", enc->qmin, enc->qmax);
  1035. }
  1036. bitrate = enc->bit_rate;
  1037. break;
  1038. case CODEC_TYPE_AUDIO:
  1039. snprintf(buf, buf_size,
  1040. "Audio: %s",
  1041. codec_name);
  1042. switch (enc->channels) {
  1043. case 1:
  1044. strcpy(channels_str, "mono");
  1045. break;
  1046. case 2:
  1047. strcpy(channels_str, "stereo");
  1048. break;
  1049. case 6:
  1050. strcpy(channels_str, "5:1");
  1051. break;
  1052. default:
  1053. snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels);
  1054. break;
  1055. }
  1056. if (enc->sample_rate) {
  1057. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1058. ", %d Hz, %s",
  1059. enc->sample_rate,
  1060. channels_str);
  1061. }
  1062. /* for PCM codecs, compute bitrate directly */
  1063. switch(enc->codec_id) {
  1064. case CODEC_ID_PCM_S32LE:
  1065. case CODEC_ID_PCM_S32BE:
  1066. case CODEC_ID_PCM_U32LE:
  1067. case CODEC_ID_PCM_U32BE:
  1068. bitrate = enc->sample_rate * enc->channels * 32;
  1069. break;
  1070. case CODEC_ID_PCM_S24LE:
  1071. case CODEC_ID_PCM_S24BE:
  1072. case CODEC_ID_PCM_U24LE:
  1073. case CODEC_ID_PCM_U24BE:
  1074. case CODEC_ID_PCM_S24DAUD:
  1075. bitrate = enc->sample_rate * enc->channels * 24;
  1076. break;
  1077. case CODEC_ID_PCM_S16LE:
  1078. case CODEC_ID_PCM_S16BE:
  1079. case CODEC_ID_PCM_S16LE_PLANAR:
  1080. case CODEC_ID_PCM_U16LE:
  1081. case CODEC_ID_PCM_U16BE:
  1082. bitrate = enc->sample_rate * enc->channels * 16;
  1083. break;
  1084. case CODEC_ID_PCM_S8:
  1085. case CODEC_ID_PCM_U8:
  1086. case CODEC_ID_PCM_ALAW:
  1087. case CODEC_ID_PCM_MULAW:
  1088. bitrate = enc->sample_rate * enc->channels * 8;
  1089. break;
  1090. default:
  1091. bitrate = enc->bit_rate;
  1092. break;
  1093. }
  1094. break;
  1095. case CODEC_TYPE_DATA:
  1096. snprintf(buf, buf_size, "Data: %s", codec_name);
  1097. bitrate = enc->bit_rate;
  1098. break;
  1099. case CODEC_TYPE_SUBTITLE:
  1100. snprintf(buf, buf_size, "Subtitle: %s", codec_name);
  1101. bitrate = enc->bit_rate;
  1102. break;
  1103. case CODEC_TYPE_ATTACHMENT:
  1104. snprintf(buf, buf_size, "Attachment: %s", codec_name);
  1105. bitrate = enc->bit_rate;
  1106. break;
  1107. default:
  1108. snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
  1109. return;
  1110. }
  1111. if (encode) {
  1112. if (enc->flags & CODEC_FLAG_PASS1)
  1113. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1114. ", pass 1");
  1115. if (enc->flags & CODEC_FLAG_PASS2)
  1116. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1117. ", pass 2");
  1118. }
  1119. if (bitrate != 0) {
  1120. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1121. ", %d kb/s", bitrate / 1000);
  1122. }
  1123. }
  1124. unsigned avcodec_version( void )
  1125. {
  1126. return LIBAVCODEC_VERSION_INT;
  1127. }
  1128. unsigned avcodec_build( void )
  1129. {
  1130. return LIBAVCODEC_BUILD;
  1131. }
  1132. void avcodec_init(void)
  1133. {
  1134. static int initialized = 0;
  1135. if (initialized != 0)
  1136. return;
  1137. initialized = 1;
  1138. dsputil_static_init();
  1139. }
  1140. void avcodec_flush_buffers(AVCodecContext *avctx)
  1141. {
  1142. if(avctx->codec->flush)
  1143. avctx->codec->flush(avctx);
  1144. }
  1145. void avcodec_default_free_buffers(AVCodecContext *s){
  1146. int i, j;
  1147. if(s->internal_buffer==NULL) return;
  1148. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  1149. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  1150. for(j=0; j<4; j++){
  1151. av_freep(&buf->base[j]);
  1152. buf->data[j]= NULL;
  1153. }
  1154. }
  1155. av_freep(&s->internal_buffer);
  1156. s->internal_buffer_count=0;
  1157. }
  1158. char av_get_pict_type_char(int pict_type){
  1159. switch(pict_type){
  1160. case FF_I_TYPE: return 'I';
  1161. case FF_P_TYPE: return 'P';
  1162. case FF_B_TYPE: return 'B';
  1163. case FF_S_TYPE: return 'S';
  1164. case FF_SI_TYPE:return 'i';
  1165. case FF_SP_TYPE:return 'p';
  1166. case FF_BI_TYPE:return 'b';
  1167. default: return '?';
  1168. }
  1169. }
  1170. int av_get_bits_per_sample(enum CodecID codec_id){
  1171. switch(codec_id){
  1172. case CODEC_ID_ADPCM_SBPRO_2:
  1173. return 2;
  1174. case CODEC_ID_ADPCM_SBPRO_3:
  1175. return 3;
  1176. case CODEC_ID_ADPCM_SBPRO_4:
  1177. case CODEC_ID_ADPCM_CT:
  1178. return 4;
  1179. case CODEC_ID_PCM_ALAW:
  1180. case CODEC_ID_PCM_MULAW:
  1181. case CODEC_ID_PCM_S8:
  1182. case CODEC_ID_PCM_U8:
  1183. return 8;
  1184. case CODEC_ID_PCM_S16BE:
  1185. case CODEC_ID_PCM_S16LE:
  1186. case CODEC_ID_PCM_S16LE_PLANAR:
  1187. case CODEC_ID_PCM_U16BE:
  1188. case CODEC_ID_PCM_U16LE:
  1189. return 16;
  1190. case CODEC_ID_PCM_S24DAUD:
  1191. case CODEC_ID_PCM_S24BE:
  1192. case CODEC_ID_PCM_S24LE:
  1193. case CODEC_ID_PCM_U24BE:
  1194. case CODEC_ID_PCM_U24LE:
  1195. return 24;
  1196. case CODEC_ID_PCM_S32BE:
  1197. case CODEC_ID_PCM_S32LE:
  1198. case CODEC_ID_PCM_U32BE:
  1199. case CODEC_ID_PCM_U32LE:
  1200. return 32;
  1201. default:
  1202. return 0;
  1203. }
  1204. }
  1205. int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
  1206. switch (sample_fmt) {
  1207. case SAMPLE_FMT_U8:
  1208. return 8;
  1209. case SAMPLE_FMT_S16:
  1210. return 16;
  1211. case SAMPLE_FMT_S24:
  1212. return 24;
  1213. case SAMPLE_FMT_S32:
  1214. case SAMPLE_FMT_FLT:
  1215. return 32;
  1216. default:
  1217. return 0;
  1218. }
  1219. }
  1220. #if !defined(HAVE_THREADS)
  1221. int avcodec_thread_init(AVCodecContext *s, int thread_count){
  1222. return -1;
  1223. }
  1224. #endif
  1225. unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  1226. {
  1227. unsigned int n = 0;
  1228. while(v >= 0xff) {
  1229. *s++ = 0xff;
  1230. v -= 0xff;
  1231. n++;
  1232. }
  1233. *s = v;
  1234. n++;
  1235. return n;
  1236. }
  1237. /* Wrapper to work around the lack of mkstemp() on mingw/cygin.
  1238. * Also, tries to create file in /tmp first, if possible.
  1239. * *prefix can be a character constant; *filename will be allocated internally.
  1240. * Returns file descriptor of opened file (or -1 on error)
  1241. * and opened file name in **filename. */
  1242. int av_tempfile(char *prefix, char **filename) {
  1243. int fd=-1;
  1244. #if !defined(HAVE_MKSTEMP)
  1245. *filename = tempnam(".", prefix);
  1246. #else
  1247. size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
  1248. *filename = av_malloc(len);
  1249. #endif
  1250. /* -----common section-----*/
  1251. if (*filename == NULL) {
  1252. av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
  1253. return -1;
  1254. }
  1255. #if !defined(HAVE_MKSTEMP)
  1256. fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
  1257. #else
  1258. snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
  1259. fd = mkstemp(*filename);
  1260. if (fd < 0) {
  1261. snprintf(*filename, len, "./%sXXXXXX", prefix);
  1262. fd = mkstemp(*filename);
  1263. }
  1264. #endif
  1265. /* -----common section-----*/
  1266. if (fd < 0) {
  1267. av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
  1268. return -1;
  1269. }
  1270. return fd; /* success */
  1271. }
  1272. typedef struct {
  1273. const char *abbr;
  1274. int width, height;
  1275. } VideoFrameSizeAbbr;
  1276. typedef struct {
  1277. const char *abbr;
  1278. int rate_num, rate_den;
  1279. } VideoFrameRateAbbr;
  1280. static VideoFrameSizeAbbr video_frame_size_abbrs[] = {
  1281. { "ntsc", 720, 480 },
  1282. { "pal", 720, 576 },
  1283. { "qntsc", 352, 240 }, /* VCD compliant NTSC */
  1284. { "qpal", 352, 288 }, /* VCD compliant PAL */
  1285. { "sntsc", 640, 480 }, /* square pixel NTSC */
  1286. { "spal", 768, 576 }, /* square pixel PAL */
  1287. { "film", 352, 240 },
  1288. { "ntsc-film", 352, 240 },
  1289. { "sqcif", 128, 96 },
  1290. { "qcif", 176, 144 },
  1291. { "cif", 352, 288 },
  1292. { "4cif", 704, 576 },
  1293. { "qqvga", 160, 120 },
  1294. { "qvga", 320, 240 },
  1295. { "vga", 640, 480 },
  1296. { "svga", 800, 600 },
  1297. { "xga", 1024, 768 },
  1298. { "uxga", 1600,1200 },
  1299. { "qxga", 2048,1536 },
  1300. { "sxga", 1280,1024 },
  1301. { "qsxga", 2560,2048 },
  1302. { "hsxga", 5120,4096 },
  1303. { "wvga", 852, 480 },
  1304. { "wxga", 1366, 768 },
  1305. { "wsxga", 1600,1024 },
  1306. { "wuxga", 1920,1200 },
  1307. { "woxga", 2560,1600 },
  1308. { "wqsxga", 3200,2048 },
  1309. { "wquxga", 3840,2400 },
  1310. { "whsxga", 6400,4096 },
  1311. { "whuxga", 7680,4800 },
  1312. { "cga", 320, 200 },
  1313. { "ega", 640, 350 },
  1314. { "hd480", 852, 480 },
  1315. { "hd720", 1280, 720 },
  1316. { "hd1080", 1920,1080 },
  1317. };
  1318. static VideoFrameRateAbbr video_frame_rate_abbrs[]= {
  1319. { "ntsc", 30000, 1001 },
  1320. { "pal", 25, 1 },
  1321. { "qntsc", 30000, 1001 }, /* VCD compliant NTSC */
  1322. { "qpal", 25, 1 }, /* VCD compliant PAL */
  1323. { "sntsc", 30000, 1001 }, /* square pixel NTSC */
  1324. { "spal", 25, 1 }, /* square pixel PAL */
  1325. { "film", 24, 1 },
  1326. { "ntsc-film", 24000, 1001 },
  1327. };
  1328. int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
  1329. {
  1330. int i;
  1331. int n = sizeof(video_frame_size_abbrs) / sizeof(VideoFrameSizeAbbr);
  1332. const char *p;
  1333. int frame_width = 0, frame_height = 0;
  1334. for(i=0;i<n;i++) {
  1335. if (!strcmp(video_frame_size_abbrs[i].abbr, str)) {
  1336. frame_width = video_frame_size_abbrs[i].width;
  1337. frame_height = video_frame_size_abbrs[i].height;
  1338. break;
  1339. }
  1340. }
  1341. if (i == n) {
  1342. p = str;
  1343. frame_width = strtol(p, (char **)&p, 10);
  1344. if (*p)
  1345. p++;
  1346. frame_height = strtol(p, (char **)&p, 10);
  1347. }
  1348. if (frame_width <= 0 || frame_height <= 0)
  1349. return -1;
  1350. *width_ptr = frame_width;
  1351. *height_ptr = frame_height;
  1352. return 0;
  1353. }
  1354. int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
  1355. {
  1356. int i;
  1357. int n = sizeof(video_frame_rate_abbrs) / sizeof(VideoFrameRateAbbr);
  1358. char* cp;
  1359. /* First, we check our abbreviation table */
  1360. for (i = 0; i < n; ++i)
  1361. if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) {
  1362. frame_rate->num = video_frame_rate_abbrs[i].rate_num;
  1363. frame_rate->den = video_frame_rate_abbrs[i].rate_den;
  1364. return 0;
  1365. }
  1366. /* Then, we try to parse it as fraction */
  1367. cp = strchr(arg, '/');
  1368. if (!cp)
  1369. cp = strchr(arg, ':');
  1370. if (cp) {
  1371. char* cpp;
  1372. frame_rate->num = strtol(arg, &cpp, 10);
  1373. if (cpp != arg || cpp == cp)
  1374. frame_rate->den = strtol(cp+1, &cpp, 10);
  1375. else
  1376. frame_rate->num = 0;
  1377. }
  1378. else {
  1379. /* Finally we give up and parse it as double */
  1380. AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
  1381. frame_rate->den = time_base.den;
  1382. frame_rate->num = time_base.num;
  1383. }
  1384. if (!frame_rate->num || !frame_rate->den)
  1385. return -1;
  1386. else
  1387. return 0;
  1388. }