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.

2928 lines
89KB

  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_H
  21. #define AVCODEC_H
  22. /**
  23. * @file avcodec.h
  24. * external API header
  25. */
  26. #include "avutil.h"
  27. #include <sys/types.h> /* size_t */
  28. #define AV_STRINGIFY(s) AV_TOSTRING(s)
  29. #define AV_TOSTRING(s) #s
  30. #define LIBAVCODEC_VERSION_INT ((51<<16)+(40<<8)+4)
  31. #define LIBAVCODEC_VERSION 51.40.4
  32. #define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT
  33. #define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
  34. #define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
  35. #define AV_TIME_BASE 1000000
  36. #define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
  37. /**
  38. *
  39. * If you add a codec ID to this list, add it so that
  40. * 1. no value of a existing codec ID changes (that would break ABI),
  41. * 2. it is as close as possible to similar codecs.
  42. */
  43. enum CodecID {
  44. CODEC_ID_NONE,
  45. CODEC_ID_MPEG1VIDEO,
  46. CODEC_ID_MPEG2VIDEO, /* preferred ID for MPEG-1/2 video decoding */
  47. CODEC_ID_MPEG2VIDEO_XVMC,
  48. CODEC_ID_H261,
  49. CODEC_ID_H263,
  50. CODEC_ID_RV10,
  51. CODEC_ID_RV20,
  52. CODEC_ID_MJPEG,
  53. CODEC_ID_MJPEGB,
  54. CODEC_ID_LJPEG,
  55. CODEC_ID_SP5X,
  56. CODEC_ID_JPEGLS,
  57. CODEC_ID_MPEG4,
  58. CODEC_ID_RAWVIDEO,
  59. CODEC_ID_MSMPEG4V1,
  60. CODEC_ID_MSMPEG4V2,
  61. CODEC_ID_MSMPEG4V3,
  62. CODEC_ID_WMV1,
  63. CODEC_ID_WMV2,
  64. CODEC_ID_H263P,
  65. CODEC_ID_H263I,
  66. CODEC_ID_FLV1,
  67. CODEC_ID_SVQ1,
  68. CODEC_ID_SVQ3,
  69. CODEC_ID_DVVIDEO,
  70. CODEC_ID_HUFFYUV,
  71. CODEC_ID_CYUV,
  72. CODEC_ID_H264,
  73. CODEC_ID_INDEO3,
  74. CODEC_ID_VP3,
  75. CODEC_ID_THEORA,
  76. CODEC_ID_ASV1,
  77. CODEC_ID_ASV2,
  78. CODEC_ID_FFV1,
  79. CODEC_ID_4XM,
  80. CODEC_ID_VCR1,
  81. CODEC_ID_CLJR,
  82. CODEC_ID_MDEC,
  83. CODEC_ID_ROQ,
  84. CODEC_ID_INTERPLAY_VIDEO,
  85. CODEC_ID_XAN_WC3,
  86. CODEC_ID_XAN_WC4,
  87. CODEC_ID_RPZA,
  88. CODEC_ID_CINEPAK,
  89. CODEC_ID_WS_VQA,
  90. CODEC_ID_MSRLE,
  91. CODEC_ID_MSVIDEO1,
  92. CODEC_ID_IDCIN,
  93. CODEC_ID_8BPS,
  94. CODEC_ID_SMC,
  95. CODEC_ID_FLIC,
  96. CODEC_ID_TRUEMOTION1,
  97. CODEC_ID_VMDVIDEO,
  98. CODEC_ID_MSZH,
  99. CODEC_ID_ZLIB,
  100. CODEC_ID_QTRLE,
  101. CODEC_ID_SNOW,
  102. CODEC_ID_TSCC,
  103. CODEC_ID_ULTI,
  104. CODEC_ID_QDRAW,
  105. CODEC_ID_VIXL,
  106. CODEC_ID_QPEG,
  107. CODEC_ID_XVID,
  108. CODEC_ID_PNG,
  109. CODEC_ID_PPM,
  110. CODEC_ID_PBM,
  111. CODEC_ID_PGM,
  112. CODEC_ID_PGMYUV,
  113. CODEC_ID_PAM,
  114. CODEC_ID_FFVHUFF,
  115. CODEC_ID_RV30,
  116. CODEC_ID_RV40,
  117. CODEC_ID_VC1,
  118. CODEC_ID_WMV3,
  119. CODEC_ID_LOCO,
  120. CODEC_ID_WNV1,
  121. CODEC_ID_AASC,
  122. CODEC_ID_INDEO2,
  123. CODEC_ID_FRAPS,
  124. CODEC_ID_TRUEMOTION2,
  125. CODEC_ID_BMP,
  126. CODEC_ID_CSCD,
  127. CODEC_ID_MMVIDEO,
  128. CODEC_ID_ZMBV,
  129. CODEC_ID_AVS,
  130. CODEC_ID_SMACKVIDEO,
  131. CODEC_ID_NUV,
  132. CODEC_ID_KMVC,
  133. CODEC_ID_FLASHSV,
  134. CODEC_ID_CAVS,
  135. CODEC_ID_JPEG2000,
  136. CODEC_ID_VMNC,
  137. CODEC_ID_VP5,
  138. CODEC_ID_VP6,
  139. CODEC_ID_VP6F,
  140. CODEC_ID_TARGA,
  141. CODEC_ID_DSICINVIDEO,
  142. CODEC_ID_TIERTEXSEQVIDEO,
  143. CODEC_ID_TIFF,
  144. CODEC_ID_GIF,
  145. CODEC_ID_FFH264,
  146. CODEC_ID_DXA,
  147. CODEC_ID_DNXHD,
  148. CODEC_ID_THP,
  149. CODEC_ID_SGI,
  150. CODEC_ID_C93,
  151. CODEC_ID_BETHSOFTVID,
  152. CODEC_ID_PTX,
  153. CODEC_ID_TXD,
  154. /* various PCM "codecs" */
  155. CODEC_ID_PCM_S16LE= 0x10000,
  156. CODEC_ID_PCM_S16BE,
  157. CODEC_ID_PCM_U16LE,
  158. CODEC_ID_PCM_U16BE,
  159. CODEC_ID_PCM_S8,
  160. CODEC_ID_PCM_U8,
  161. CODEC_ID_PCM_MULAW,
  162. CODEC_ID_PCM_ALAW,
  163. CODEC_ID_PCM_S32LE,
  164. CODEC_ID_PCM_S32BE,
  165. CODEC_ID_PCM_U32LE,
  166. CODEC_ID_PCM_U32BE,
  167. CODEC_ID_PCM_S24LE,
  168. CODEC_ID_PCM_S24BE,
  169. CODEC_ID_PCM_U24LE,
  170. CODEC_ID_PCM_U24BE,
  171. CODEC_ID_PCM_S24DAUD,
  172. /* various ADPCM codecs */
  173. CODEC_ID_ADPCM_IMA_QT= 0x11000,
  174. CODEC_ID_ADPCM_IMA_WAV,
  175. CODEC_ID_ADPCM_IMA_DK3,
  176. CODEC_ID_ADPCM_IMA_DK4,
  177. CODEC_ID_ADPCM_IMA_WS,
  178. CODEC_ID_ADPCM_IMA_SMJPEG,
  179. CODEC_ID_ADPCM_MS,
  180. CODEC_ID_ADPCM_4XM,
  181. CODEC_ID_ADPCM_XA,
  182. CODEC_ID_ADPCM_ADX,
  183. CODEC_ID_ADPCM_EA,
  184. CODEC_ID_ADPCM_G726,
  185. CODEC_ID_ADPCM_CT,
  186. CODEC_ID_ADPCM_SWF,
  187. CODEC_ID_ADPCM_YAMAHA,
  188. CODEC_ID_ADPCM_SBPRO_4,
  189. CODEC_ID_ADPCM_SBPRO_3,
  190. CODEC_ID_ADPCM_SBPRO_2,
  191. CODEC_ID_ADPCM_THP,
  192. /* AMR */
  193. CODEC_ID_AMR_NB= 0x12000,
  194. CODEC_ID_AMR_WB,
  195. /* RealAudio codecs*/
  196. CODEC_ID_RA_144= 0x13000,
  197. CODEC_ID_RA_288,
  198. /* various DPCM codecs */
  199. CODEC_ID_ROQ_DPCM= 0x14000,
  200. CODEC_ID_INTERPLAY_DPCM,
  201. CODEC_ID_XAN_DPCM,
  202. CODEC_ID_SOL_DPCM,
  203. CODEC_ID_MP2= 0x15000,
  204. CODEC_ID_MP3, /* preferred ID for decoding MPEG audio layer 1, 2 or 3 */
  205. CODEC_ID_AAC,
  206. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  207. CODEC_ID_MPEG4AAC,
  208. #endif
  209. CODEC_ID_AC3,
  210. CODEC_ID_DTS,
  211. CODEC_ID_VORBIS,
  212. CODEC_ID_DVAUDIO,
  213. CODEC_ID_WMAV1,
  214. CODEC_ID_WMAV2,
  215. CODEC_ID_MACE3,
  216. CODEC_ID_MACE6,
  217. CODEC_ID_VMDAUDIO,
  218. CODEC_ID_SONIC,
  219. CODEC_ID_SONIC_LS,
  220. CODEC_ID_FLAC,
  221. CODEC_ID_MP3ADU,
  222. CODEC_ID_MP3ON4,
  223. CODEC_ID_SHORTEN,
  224. CODEC_ID_ALAC,
  225. CODEC_ID_WESTWOOD_SND1,
  226. CODEC_ID_GSM, /* as in Berlin toast format */
  227. CODEC_ID_QDM2,
  228. CODEC_ID_COOK,
  229. CODEC_ID_TRUESPEECH,
  230. CODEC_ID_TTA,
  231. CODEC_ID_SMACKAUDIO,
  232. CODEC_ID_QCELP,
  233. CODEC_ID_WAVPACK,
  234. CODEC_ID_DSICINAUDIO,
  235. CODEC_ID_IMC,
  236. CODEC_ID_MUSEPACK7,
  237. CODEC_ID_MLP,
  238. CODEC_ID_GSM_MS, /* as found in WAV */
  239. CODEC_ID_ATRAC3,
  240. /* subtitle codecs */
  241. CODEC_ID_DVD_SUBTITLE= 0x17000,
  242. CODEC_ID_DVB_SUBTITLE,
  243. CODEC_ID_MPEG2TS= 0x20000, /* _FAKE_ codec to indicate a raw MPEG-2 TS
  244. * stream (only used by libavformat) */
  245. };
  246. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  247. /* CODEC_ID_MP3LAME is obsolete */
  248. #define CODEC_ID_MP3LAME CODEC_ID_MP3
  249. #define CODEC_ID_MPEG4AAC CODEC_ID_AAC
  250. #endif
  251. enum CodecType {
  252. CODEC_TYPE_UNKNOWN = -1,
  253. CODEC_TYPE_VIDEO,
  254. CODEC_TYPE_AUDIO,
  255. CODEC_TYPE_DATA,
  256. CODEC_TYPE_SUBTITLE,
  257. CODEC_TYPE_NB
  258. };
  259. /* Currently unused, may be used if 24/32 bits samples are ever supported. */
  260. /* all in native-endian format */
  261. enum SampleFormat {
  262. SAMPLE_FMT_NONE = -1,
  263. SAMPLE_FMT_U8, ///< unsigned 8 bits
  264. SAMPLE_FMT_S16, ///< signed 16 bits
  265. SAMPLE_FMT_S24, ///< signed 24 bits
  266. SAMPLE_FMT_S32, ///< signed 32 bits
  267. SAMPLE_FMT_FLT, ///< float
  268. };
  269. /* in bytes */
  270. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
  271. /**
  272. * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
  273. * This is mainly needed because some optimized bitstream readers read
  274. * 32 or 64 bit at once and could read over the end.<br>
  275. * Note: If the first 23 bits of the additional bytes are not 0, then damaged
  276. * MPEG bitstreams could cause overread and segfault.
  277. */
  278. #define FF_INPUT_BUFFER_PADDING_SIZE 8
  279. /**
  280. * minimum encoding buffer size
  281. * Used to avoid some checks during header writing.
  282. */
  283. #define FF_MIN_BUFFER_SIZE 16384
  284. /* motion estimation type, EPZS by default */
  285. enum Motion_Est_ID {
  286. ME_ZERO = 1,
  287. ME_FULL,
  288. ME_LOG,
  289. ME_PHODS,
  290. ME_EPZS,
  291. ME_X1,
  292. ME_HEX,
  293. ME_UMH,
  294. ME_ITER,
  295. };
  296. enum AVDiscard{
  297. /* We leave some space between them for extensions (drop some
  298. * keyframes for intra-only or drop just some bidir frames). */
  299. AVDISCARD_NONE =-16, ///< discard nothing
  300. AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi
  301. AVDISCARD_NONREF = 8, ///< discard all non reference
  302. AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
  303. AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
  304. AVDISCARD_ALL = 48, ///< discard all
  305. };
  306. typedef struct RcOverride{
  307. int start_frame;
  308. int end_frame;
  309. int qscale; // If this is 0 then quality_factor will be used instead.
  310. float quality_factor;
  311. } RcOverride;
  312. #define FF_MAX_B_FRAMES 16
  313. /* encoding support
  314. These flags can be passed in AVCodecContext.flags before initialization.
  315. Note: Not everything is supported yet.
  316. */
  317. #define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale.
  318. #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263.
  319. #define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
  320. #define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
  321. #define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>.
  322. #define CODEC_FLAG_PART 0x0080 ///< Use data partitioning.
  323. /* The parent program guarantees that the input for B-frames containing
  324. * streams is not written to for at least s->max_b_frames+1 frames, if
  325. * this is not set the input will be copied. */
  326. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  327. #define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
  328. #define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
  329. #define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG).
  330. #define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
  331. #define CODEC_FLAG_EMU_EDGE 0x4000///< Don't draw edges.
  332. #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
  333. #define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random location instead
  334. of only at frame boundaries. */
  335. #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization.
  336. #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
  337. #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
  338. #define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan.
  339. #define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< Use trellis quantization.
  340. #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
  341. #define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
  342. /* Fx : Flag for h263+ extra options */
  343. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  344. #define CODEC_FLAG_H263P_AIC 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction (remove this)
  345. #endif
  346. #define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
  347. #define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector
  348. #define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
  349. #define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
  350. #define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC
  351. #define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
  352. #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
  353. #define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
  354. #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
  355. #define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
  356. #define CODEC_FLAG_CLOSED_GOP ((int)0x80000000)
  357. #define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
  358. #define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
  359. #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
  360. #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
  361. #define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references.
  362. #define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames
  363. #define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
  364. #define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform
  365. #define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
  366. #define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
  367. #define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization
  368. #define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table.
  369. #define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
  370. #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
  371. #define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
  372. #define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
  373. #define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
  374. /* Unsupported options :
  375. * Syntax Arithmetic coding (SAC)
  376. * Reference Picture Selection
  377. * Independent Segment Decoding */
  378. /* /Fx */
  379. /* codec capabilities */
  380. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
  381. /**
  382. * Codec uses get_buffer() for allocating buffers.
  383. * direct rendering method 1
  384. */
  385. #define CODEC_CAP_DR1 0x0002
  386. /* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */
  387. #define CODEC_CAP_PARSE_ONLY 0x0004
  388. #define CODEC_CAP_TRUNCATED 0x0008
  389. /* Codec can export data for HW decoding (XvMC). */
  390. #define CODEC_CAP_HWACCEL 0x0010
  391. /**
  392. * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data.
  393. * If this is not set, the codec is guaranteed to never be fed with NULL data.
  394. */
  395. #define CODEC_CAP_DELAY 0x0020
  396. /**
  397. * Codec can be fed a final frame with a smaller size.
  398. * This can be used to prevent truncation of the last audio samples.
  399. */
  400. #define CODEC_CAP_SMALL_LAST_FRAME 0x0040
  401. //The following defines may change, don't expect compatibility if you use them.
  402. #define MB_TYPE_INTRA4x4 0x0001
  403. #define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
  404. #define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific
  405. #define MB_TYPE_16x16 0x0008
  406. #define MB_TYPE_16x8 0x0010
  407. #define MB_TYPE_8x16 0x0020
  408. #define MB_TYPE_8x8 0x0040
  409. #define MB_TYPE_INTERLACED 0x0080
  410. #define MB_TYPE_DIRECT2 0x0100 //FIXME
  411. #define MB_TYPE_ACPRED 0x0200
  412. #define MB_TYPE_GMC 0x0400
  413. #define MB_TYPE_SKIP 0x0800
  414. #define MB_TYPE_P0L0 0x1000
  415. #define MB_TYPE_P1L0 0x2000
  416. #define MB_TYPE_P0L1 0x4000
  417. #define MB_TYPE_P1L1 0x8000
  418. #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
  419. #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
  420. #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
  421. #define MB_TYPE_QUANT 0x00010000
  422. #define MB_TYPE_CBP 0x00020000
  423. //Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
  424. /**
  425. * Pan Scan area.
  426. * This specifies the area which should be displayed.
  427. * Note there may be multiple such areas for one frame.
  428. */
  429. typedef struct AVPanScan{
  430. /**
  431. * id
  432. * - encoding: Set by user.
  433. * - decoding: Set by libavcodec.
  434. */
  435. int id;
  436. /**
  437. * width and height in 1/16 pel
  438. * - encoding: Set by user.
  439. * - decoding: Set by libavcodec.
  440. */
  441. int width;
  442. int height;
  443. /**
  444. * position of the top left corner in 1/16 pel for up to 3 fields/frames
  445. * - encoding: Set by user.
  446. * - decoding: Set by libavcodec.
  447. */
  448. int16_t position[3][2];
  449. }AVPanScan;
  450. #define FF_COMMON_FRAME \
  451. /**\
  452. * pointer to the picture planes.\
  453. * This might be different from the first allocated byte\
  454. * - encoding: \
  455. * - decoding: \
  456. */\
  457. uint8_t *data[4];\
  458. int linesize[4];\
  459. /**\
  460. * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\
  461. * This isn't used by libavcodec unless the default get/release_buffer() is used.\
  462. * - encoding: \
  463. * - decoding: \
  464. */\
  465. uint8_t *base[4];\
  466. /**\
  467. * 1 -> keyframe, 0-> not\
  468. * - encoding: Set by libavcodec.\
  469. * - decoding: Set by libavcodec.\
  470. */\
  471. int key_frame;\
  472. \
  473. /**\
  474. * Picture type of the frame, see ?_TYPE below.\
  475. * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
  476. * - decoding: Set by libavcodec.\
  477. */\
  478. int pict_type;\
  479. \
  480. /**\
  481. * presentation timestamp in time_base units (time when frame should be shown to user)\
  482. * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\
  483. * - encoding: MUST be set by user.\
  484. * - decoding: Set by libavcodec.\
  485. */\
  486. int64_t pts;\
  487. \
  488. /**\
  489. * picture number in bitstream order\
  490. * - encoding: set by\
  491. * - decoding: Set by libavcodec.\
  492. */\
  493. int coded_picture_number;\
  494. /**\
  495. * picture number in display order\
  496. * - encoding: set by\
  497. * - decoding: Set by libavcodec.\
  498. */\
  499. int display_picture_number;\
  500. \
  501. /**\
  502. * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
  503. * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
  504. * - decoding: Set by libavcodec.\
  505. */\
  506. int quality; \
  507. \
  508. /**\
  509. * buffer age (1->was last buffer and dint change, 2->..., ...).\
  510. * Set to INT_MAX if the buffer has not been used yet.\
  511. * - encoding: unused\
  512. * - decoding: MUST be set by get_buffer().\
  513. */\
  514. int age;\
  515. \
  516. /**\
  517. * is this picture used as reference\
  518. * - encoding: unused\
  519. * - decoding: Set by libavcodec. (before get_buffer() call)).\
  520. */\
  521. int reference;\
  522. \
  523. /**\
  524. * QP table\
  525. * - encoding: unused\
  526. * - decoding: Set by libavcodec.\
  527. */\
  528. int8_t *qscale_table;\
  529. /**\
  530. * QP store stride\
  531. * - encoding: unused\
  532. * - decoding: Set by libavcodec.\
  533. */\
  534. int qstride;\
  535. \
  536. /**\
  537. * mbskip_table[mb]>=1 if MB didn't change\
  538. * stride= mb_width = (width+15)>>4\
  539. * - encoding: unused\
  540. * - decoding: Set by libavcodec.\
  541. */\
  542. uint8_t *mbskip_table;\
  543. \
  544. /**\
  545. * motion vector table\
  546. * @code\
  547. * example:\
  548. * int mv_sample_log2= 4 - motion_subsample_log2;\
  549. * int mb_width= (width+15)>>4;\
  550. * int mv_stride= (mb_width << mv_sample_log2) + 1;\
  551. * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\
  552. * @endcode\
  553. * - encoding: Set by user.\
  554. * - decoding: Set by libavcodec.\
  555. */\
  556. int16_t (*motion_val[2])[2];\
  557. \
  558. /**\
  559. * macroblock type table\
  560. * mb_type_base + mb_width + 2\
  561. * - encoding: Set by user.\
  562. * - decoding: Set by libavcodec.\
  563. */\
  564. uint32_t *mb_type;\
  565. \
  566. /**\
  567. * log2 of the size of the block which a single vector in motion_val represents: \
  568. * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\
  569. * - encoding: unused\
  570. * - decoding: Set by libavcodec.\
  571. */\
  572. uint8_t motion_subsample_log2;\
  573. \
  574. /**\
  575. * for some private data of the user\
  576. * - encoding: unused\
  577. * - decoding: Set by user.\
  578. */\
  579. void *opaque;\
  580. \
  581. /**\
  582. * error\
  583. * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\
  584. * - decoding: unused\
  585. */\
  586. uint64_t error[4];\
  587. \
  588. /**\
  589. * type of the buffer (to keep track of who has to deallocate data[*])\
  590. * - encoding: Set by the one who allocates it.\
  591. * - decoding: Set by the one who allocates it.\
  592. * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\
  593. */\
  594. int type;\
  595. \
  596. /**\
  597. * When decoding, this signals how much the picture must be delayed.\
  598. * extra_delay = repeat_pict / (2*fps)\
  599. * - encoding: unused\
  600. * - decoding: Set by libavcodec.\
  601. */\
  602. int repeat_pict;\
  603. \
  604. /**\
  605. * \
  606. */\
  607. int qscale_type;\
  608. \
  609. /**\
  610. * The content of the picture is interlaced.\
  611. * - encoding: Set by user.\
  612. * - decoding: Set by libavcodec. (default 0)\
  613. */\
  614. int interlaced_frame;\
  615. \
  616. /**\
  617. * If the content is interlaced, is top field displayed first.\
  618. * - encoding: Set by user.\
  619. * - decoding: Set by libavcodec.\
  620. */\
  621. int top_field_first;\
  622. \
  623. /**\
  624. * Pan scan.\
  625. * - encoding: Set by user.\
  626. * - decoding: Set by libavcodec.\
  627. */\
  628. AVPanScan *pan_scan;\
  629. \
  630. /**\
  631. * Tell user application that palette has changed from previous frame.\
  632. * - encoding: ??? (no palette-enabled encoder yet)\
  633. * - decoding: Set by libavcodec. (default 0).\
  634. */\
  635. int palette_has_changed;\
  636. \
  637. /**\
  638. * codec suggestion on buffer type if != 0\
  639. * - encoding: unused\
  640. * - decoding: Set by libavcodec. (before get_buffer() call)).\
  641. */\
  642. int buffer_hints;\
  643. \
  644. /**\
  645. * DCT coefficients\
  646. * - encoding: unused\
  647. * - decoding: Set by libavcodec.\
  648. */\
  649. short *dct_coeff;\
  650. \
  651. /**\
  652. * motion referece frame index\
  653. * - encoding: Set by user.\
  654. * - decoding: Set by libavcodec.\
  655. */\
  656. int8_t *ref_index[2];
  657. #define FF_QSCALE_TYPE_MPEG1 0
  658. #define FF_QSCALE_TYPE_MPEG2 1
  659. #define FF_QSCALE_TYPE_H264 2
  660. #define FF_BUFFER_TYPE_INTERNAL 1
  661. #define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user)
  662. #define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
  663. #define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
  664. #define FF_I_TYPE 1 // Intra
  665. #define FF_P_TYPE 2 // Predicted
  666. #define FF_B_TYPE 3 // Bi-dir predicted
  667. #define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
  668. #define FF_SI_TYPE 5
  669. #define FF_SP_TYPE 6
  670. #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore).
  671. #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
  672. #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
  673. #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
  674. /**
  675. * Audio Video Frame.
  676. */
  677. typedef struct AVFrame {
  678. FF_COMMON_FRAME
  679. } AVFrame;
  680. #define DEFAULT_FRAME_RATE_BASE 1001000
  681. /**
  682. * main external API structure
  683. */
  684. typedef struct AVCodecContext {
  685. /**
  686. * information on struct for av_log
  687. * - set by avcodec_alloc_context
  688. */
  689. AVClass *av_class;
  690. /**
  691. * the average bitrate
  692. * - encoding: Set by user; unused for constant quantizer encoding.
  693. * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
  694. */
  695. int bit_rate;
  696. /**
  697. * number of bits the bitstream is allowed to diverge from the reference.
  698. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  699. * - encoding: Set by user; unused for constant quantizer encoding.
  700. * - decoding: unused
  701. */
  702. int bit_rate_tolerance;
  703. /**
  704. * CODEC_FLAG_*.
  705. * - encoding: Set by user.
  706. * - decoding: Set by user.
  707. */
  708. int flags;
  709. /**
  710. * Some codecs need additional format info. It is stored here.
  711. * If any muxer uses this then ALL demuxers/parsers AND encoders for the
  712. * specific codec MUST set it correctly otherwise stream copy breaks.
  713. * In general use of this field by muxers is not recommanded.
  714. * - encoding: Set by libavcodec.
  715. * - decoding: Set by libavcodec. (FIXME: Is this OK?)
  716. */
  717. int sub_id;
  718. /**
  719. * Motion estimation algorithm used for video coding.
  720. * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
  721. * 8 (umh), 9 (iter) [7, 8 are x264 specific, 9 is snow specific]
  722. * - encoding: MUST be set by user.
  723. * - decoding: unused
  724. */
  725. int me_method;
  726. /**
  727. * some codecs need / can use extradata like Huffman tables.
  728. * mjpeg: Huffman tables
  729. * rv10: additional flags
  730. * mpeg4: global headers (they can be in the bitstream or here)
  731. * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
  732. * than extradata_size to avoid prolems if it is read with the bitstream reader.
  733. * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
  734. * - encoding: Set/allocated/freed by libavcodec.
  735. * - decoding: Set/allocated/freed by user.
  736. */
  737. uint8_t *extradata;
  738. int extradata_size;
  739. /**
  740. * This is the fundamental unit of time (in seconds) in terms
  741. * of which frame timestamps are represented. For fixed-fps content,
  742. * timebase should be 1/framerate and timestamp increments should be
  743. * identically 1.
  744. * - encoding: MUST be set by user.
  745. * - decoding: Set by libavcodec.
  746. */
  747. AVRational time_base;
  748. /* video only */
  749. /**
  750. * picture width / height.
  751. * - encoding: MUST be set by user.
  752. * - decoding: Set by libavcodec.
  753. * Note: For compatibility it is possible to set this instead of
  754. * coded_width/height before decoding.
  755. */
  756. int width, height;
  757. #define FF_ASPECT_EXTENDED 15
  758. /**
  759. * the number of pictures in a group of pictures, or 0 for intra_only
  760. * - encoding: Set by user.
  761. * - decoding: unused
  762. */
  763. int gop_size;
  764. /**
  765. * Pixel format, see PIX_FMT_xxx.
  766. * - encoding: Set by user.
  767. * - decoding: Set by libavcodec.
  768. */
  769. enum PixelFormat pix_fmt;
  770. /**
  771. * Frame rate emulation. If not zero, the lower layer (i.e. format handler)
  772. * has to read frames at native frame rate.
  773. * - encoding: Set by user.
  774. * - decoding: unused
  775. */
  776. int rate_emu;
  777. /**
  778. * If non NULL, 'draw_horiz_band' is called by the libavcodec
  779. * decoder to draw a horizontal band. It improves cache usage. Not
  780. * all codecs can do that. You must check the codec capabilities
  781. * beforehand.
  782. * - encoding: unused
  783. * - decoding: Set by user.
  784. * @param height the height of the slice
  785. * @param y the y position of the slice
  786. * @param type 1->top field, 2->bottom field, 3->frame
  787. * @param offset offset into the AVFrame.data from which the slice should be read
  788. */
  789. void (*draw_horiz_band)(struct AVCodecContext *s,
  790. const AVFrame *src, int offset[4],
  791. int y, int type, int height);
  792. /* audio only */
  793. int sample_rate; ///< samples per second
  794. int channels;
  795. /**
  796. * audio sample format
  797. * - encoding: Set by user.
  798. * - decoding: Set by libavcodec.
  799. */
  800. enum SampleFormat sample_fmt; ///< sample format, currently unused
  801. /* The following data should not be initialized. */
  802. /**
  803. * Samples per packet, initialized when calling 'init'.
  804. */
  805. int frame_size;
  806. int frame_number; ///< audio or video frame number
  807. int real_pict_num; ///< Returns the real picture number of previous encoded frame.
  808. /**
  809. * Number of frames the decoded output will be delayed relative to
  810. * the encoded input.
  811. * - encoding: Set by libavcodec.
  812. * - decoding: unused
  813. */
  814. int delay;
  815. /* - encoding parameters */
  816. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  817. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  818. /**
  819. * minimum quantizer
  820. * - encoding: Set by user.
  821. * - decoding: unused
  822. */
  823. int qmin;
  824. /**
  825. * maximum quantizer
  826. * - encoding: Set by user.
  827. * - decoding: unused
  828. */
  829. int qmax;
  830. /**
  831. * maximum quantizer difference between frames
  832. * - encoding: Set by user.
  833. * - decoding: unused
  834. */
  835. int max_qdiff;
  836. /**
  837. * maximum number of B-frames between non-B-frames
  838. * Note: The output will be delayed by max_b_frames+1 relative to the input.
  839. * - encoding: Set by user.
  840. * - decoding: unused
  841. */
  842. int max_b_frames;
  843. /**
  844. * qscale factor between IP and B-frames
  845. * - encoding: Set by user.
  846. * - decoding: unused
  847. */
  848. float b_quant_factor;
  849. /** obsolete FIXME remove */
  850. int rc_strategy;
  851. #define FF_RC_STRATEGY_XVID 1
  852. int b_frame_strategy;
  853. /**
  854. * hurry up amount
  855. * - encoding: unused
  856. * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header
  857. * @deprecated Deprecated in favor of skip_idct and skip_frame.
  858. */
  859. int hurry_up;
  860. struct AVCodec *codec;
  861. void *priv_data;
  862. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  863. /* unused, FIXME remove*/
  864. int rtp_mode;
  865. #endif
  866. int rtp_payload_size; /* The size of the RTP payload: the coder will */
  867. /* do its best to deliver a chunk with size */
  868. /* below rtp_payload_size, the chunk will start */
  869. /* with a start code on some codecs like H.263. */
  870. /* This doesn't take account of any particular */
  871. /* headers inside the transmitted RTP payload. */
  872. /* The RTP callback: This function is called */
  873. /* every time the encoder has a packet to send. */
  874. /* It depends on the encoder if the data starts */
  875. /* with a Start Code (it should). H.263 does. */
  876. /* mb_nb contains the number of macroblocks */
  877. /* encoded in the RTP payload. */
  878. void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
  879. /* statistics, used for 2-pass encoding */
  880. int mv_bits;
  881. int header_bits;
  882. int i_tex_bits;
  883. int p_tex_bits;
  884. int i_count;
  885. int p_count;
  886. int skip_count;
  887. int misc_bits;
  888. /**
  889. * number of bits used for the previously encoded frame
  890. * - encoding: Set by libavcodec.
  891. * - decoding: unused
  892. */
  893. int frame_bits;
  894. /**
  895. * Private data of the user, can be used to carry app specific stuff.
  896. * - encoding: Set by user.
  897. * - decoding: Set by user.
  898. */
  899. void *opaque;
  900. char codec_name[32];
  901. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  902. enum CodecID codec_id; /* see CODEC_ID_xxx */
  903. /**
  904. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  905. * This is used to work around some encoder bugs.
  906. * A demuxer should set this to what is stored in the field used to identify the codec.
  907. * If there are multiple such fields in a container then the demuxer should choose the one
  908. * which maximizes the information about the used codec.
  909. * If the codec tag field in a container is larger then 32 bits then the demuxer should
  910. * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
  911. * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
  912. * first.
  913. * - encoding: Set by user, if not then the default based on codec_id will be used.
  914. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  915. */
  916. unsigned int codec_tag;
  917. /**
  918. * Work around bugs in encoders which sometimes cannot be detected automatically.
  919. * - encoding: Set by user
  920. * - decoding: Set by user
  921. */
  922. int workaround_bugs;
  923. #define FF_BUG_AUTODETECT 1 ///< autodetection
  924. #define FF_BUG_OLD_MSMPEG4 2
  925. #define FF_BUG_XVID_ILACE 4
  926. #define FF_BUG_UMP4 8
  927. #define FF_BUG_NO_PADDING 16
  928. #define FF_BUG_AMV 32
  929. #define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
  930. #define FF_BUG_QPEL_CHROMA 64
  931. #define FF_BUG_STD_QPEL 128
  932. #define FF_BUG_QPEL_CHROMA2 256
  933. #define FF_BUG_DIRECT_BLOCKSIZE 512
  934. #define FF_BUG_EDGE 1024
  935. #define FF_BUG_HPEL_CHROMA 2048
  936. #define FF_BUG_DC_CLIP 4096
  937. #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
  938. //#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%.
  939. /**
  940. * luma single coefficient elimination threshold
  941. * - encoding: Set by user.
  942. * - decoding: unused
  943. */
  944. int luma_elim_threshold;
  945. /**
  946. * chroma single coeff elimination threshold
  947. * - encoding: Set by user.
  948. * - decoding: unused
  949. */
  950. int chroma_elim_threshold;
  951. /**
  952. * strictly follow the standard (MPEG4, ...).
  953. * - encoding: Set by user.
  954. * - decoding: unused
  955. */
  956. int strict_std_compliance;
  957. #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to a older more strict version of the spec or reference software.
  958. #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
  959. #define FF_COMPLIANCE_NORMAL 0
  960. #define FF_COMPLIANCE_INOFFICIAL -1 ///< Allow inofficial extensions.
  961. #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
  962. /**
  963. * qscale offset between IP and B-frames
  964. * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
  965. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  966. * - encoding: Set by user.
  967. * - decoding: unused
  968. */
  969. float b_quant_offset;
  970. /**
  971. * Error resilience; higher values will detect more errors but may
  972. * misdetect some more or less valid parts as errors.
  973. * - encoding: unused
  974. * - decoding: Set by user.
  975. */
  976. int error_resilience;
  977. #define FF_ER_CAREFUL 1
  978. #define FF_ER_COMPLIANT 2
  979. #define FF_ER_AGGRESSIVE 3
  980. #define FF_ER_VERY_AGGRESSIVE 4
  981. /**
  982. * Called at the beginning of each frame to get a buffer for it.
  983. * If pic.reference is set then the frame will be read later by libavcodec.
  984. * avcodec_align_dimensions() should be used to find the required width and
  985. * height, as they normally need to be rounded up to the next multiple of 16.
  986. * - encoding: unused
  987. * - decoding: Set by libavcodec., user can override.
  988. */
  989. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  990. /**
  991. * Called to release buffers which where allocated with get_buffer.
  992. * A released buffer can be reused in get_buffer().
  993. * pic.data[*] must be set to NULL.
  994. * - encoding: unused
  995. * - decoding: Set by libavcodec., user can override.
  996. */
  997. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  998. /**
  999. * If 1 the stream has a 1 frame delay during decoding.
  1000. * - encoding: Set by libavcodec.
  1001. * - decoding: Set by libavcodec.
  1002. */
  1003. int has_b_frames;
  1004. /**
  1005. * number of bytes per packet if constant and known or 0
  1006. * Used by some WAV based audio codecs.
  1007. */
  1008. int block_align;
  1009. int parse_only; /* - decoding only: If true, only parsing is done
  1010. (function avcodec_parse_frame()). The frame
  1011. data is returned. Only MPEG codecs support this now. */
  1012. /**
  1013. * 0-> h263 quant 1-> mpeg quant
  1014. * - encoding: Set by user.
  1015. * - decoding: unused
  1016. */
  1017. int mpeg_quant;
  1018. /**
  1019. * pass1 encoding statistics output buffer
  1020. * - encoding: Set by libavcodec.
  1021. * - decoding: unused
  1022. */
  1023. char *stats_out;
  1024. /**
  1025. * pass2 encoding statistics input buffer
  1026. * Concatenated stuff from stats_out of pass1 should be placed here.
  1027. * - encoding: Allocated/set/freed by user.
  1028. * - decoding: unused
  1029. */
  1030. char *stats_in;
  1031. /**
  1032. * ratecontrol qmin qmax limiting method
  1033. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax.
  1034. * - encoding: Set by user.
  1035. * - decoding: unused
  1036. */
  1037. float rc_qsquish;
  1038. float rc_qmod_amp;
  1039. int rc_qmod_freq;
  1040. /**
  1041. * ratecontrol override, see RcOverride
  1042. * - encoding: Allocated/set/freed by user.
  1043. * - decoding: unused
  1044. */
  1045. RcOverride *rc_override;
  1046. int rc_override_count;
  1047. /**
  1048. * rate control equation
  1049. * - encoding: Set by user
  1050. * - decoding: unused
  1051. */
  1052. char *rc_eq;
  1053. /**
  1054. * maximum bitrate
  1055. * - encoding: Set by user.
  1056. * - decoding: unused
  1057. */
  1058. int rc_max_rate;
  1059. /**
  1060. * minimum bitrate
  1061. * - encoding: Set by user.
  1062. * - decoding: unused
  1063. */
  1064. int rc_min_rate;
  1065. /**
  1066. * decoder bitstream buffer size
  1067. * - encoding: Set by user.
  1068. * - decoding: unused
  1069. */
  1070. int rc_buffer_size;
  1071. float rc_buffer_aggressivity;
  1072. /**
  1073. * qscale factor between P and I-frames
  1074. * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
  1075. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  1076. * - encoding: Set by user.
  1077. * - decoding: unused
  1078. */
  1079. float i_quant_factor;
  1080. /**
  1081. * qscale offset between P and I-frames
  1082. * - encoding: Set by user.
  1083. * - decoding: unused
  1084. */
  1085. float i_quant_offset;
  1086. /**
  1087. * initial complexity for pass1 ratecontrol
  1088. * - encoding: Set by user.
  1089. * - decoding: unused
  1090. */
  1091. float rc_initial_cplx;
  1092. /**
  1093. * DCT algorithm, see FF_DCT_* below
  1094. * - encoding: Set by user.
  1095. * - decoding: unused
  1096. */
  1097. int dct_algo;
  1098. #define FF_DCT_AUTO 0
  1099. #define FF_DCT_FASTINT 1
  1100. #define FF_DCT_INT 2
  1101. #define FF_DCT_MMX 3
  1102. #define FF_DCT_MLIB 4
  1103. #define FF_DCT_ALTIVEC 5
  1104. #define FF_DCT_FAAN 6
  1105. /**
  1106. * luminance masking (0-> disabled)
  1107. * - encoding: Set by user.
  1108. * - decoding: unused
  1109. */
  1110. float lumi_masking;
  1111. /**
  1112. * temporary complexity masking (0-> disabled)
  1113. * - encoding: Set by user.
  1114. * - decoding: unused
  1115. */
  1116. float temporal_cplx_masking;
  1117. /**
  1118. * spatial complexity masking (0-> disabled)
  1119. * - encoding: Set by user.
  1120. * - decoding: unused
  1121. */
  1122. float spatial_cplx_masking;
  1123. /**
  1124. * p block masking (0-> disabled)
  1125. * - encoding: Set by user.
  1126. * - decoding: unused
  1127. */
  1128. float p_masking;
  1129. /**
  1130. * darkness masking (0-> disabled)
  1131. * - encoding: Set by user.
  1132. * - decoding: unused
  1133. */
  1134. float dark_masking;
  1135. /* for binary compatibility */
  1136. int unused;
  1137. /**
  1138. * IDCT algorithm, see FF_IDCT_* below.
  1139. * - encoding: Set by user.
  1140. * - decoding: Set by user.
  1141. */
  1142. int idct_algo;
  1143. #define FF_IDCT_AUTO 0
  1144. #define FF_IDCT_INT 1
  1145. #define FF_IDCT_SIMPLE 2
  1146. #define FF_IDCT_SIMPLEMMX 3
  1147. #define FF_IDCT_LIBMPEG2MMX 4
  1148. #define FF_IDCT_PS2 5
  1149. #define FF_IDCT_MLIB 6
  1150. #define FF_IDCT_ARM 7
  1151. #define FF_IDCT_ALTIVEC 8
  1152. #define FF_IDCT_SH4 9
  1153. #define FF_IDCT_SIMPLEARM 10
  1154. #define FF_IDCT_H264 11
  1155. #define FF_IDCT_VP3 12
  1156. #define FF_IDCT_IPP 13
  1157. #define FF_IDCT_XVIDMMX 14
  1158. #define FF_IDCT_CAVS 15
  1159. #define FF_IDCT_SIMPLEARMV5TE 16
  1160. #define FF_IDCT_SIMPLEARMV6 17
  1161. /**
  1162. * slice count
  1163. * - encoding: Set by libavcodec.
  1164. * - decoding: Set by user (or 0).
  1165. */
  1166. int slice_count;
  1167. /**
  1168. * slice offsets in the frame in bytes
  1169. * - encoding: Set/allocated by libavcodec.
  1170. * - decoding: Set/allocated by user (or NULL).
  1171. */
  1172. int *slice_offset;
  1173. /**
  1174. * error concealment flags
  1175. * - encoding: unused
  1176. * - decoding: Set by user.
  1177. */
  1178. int error_concealment;
  1179. #define FF_EC_GUESS_MVS 1
  1180. #define FF_EC_DEBLOCK 2
  1181. /**
  1182. * dsp_mask could be add used to disable unwanted CPU features
  1183. * CPU features (i.e. MMX, SSE. ...)
  1184. *
  1185. * With the FORCE flag you may instead enable given CPU features.
  1186. * (Dangerous: Usable in case of misdetection, improper usage however will
  1187. * result into program crash.)
  1188. */
  1189. unsigned dsp_mask;
  1190. #define FF_MM_FORCE 0x80000000 /* Force usage of selected flags (OR) */
  1191. /* lower 16 bits - CPU features */
  1192. #define FF_MM_MMX 0x0001 /* standard MMX */
  1193. #define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */
  1194. #define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
  1195. #define FF_MM_SSE 0x0008 /* SSE functions */
  1196. #define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */
  1197. #define FF_MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */
  1198. #define FF_MM_SSE3 0x0040 /* Prescott SSE3 functions */
  1199. #define FF_MM_SSSE3 0x0080 /* Conroe SSSE3 functions */
  1200. #define FF_MM_IWMMXT 0x0100 /* XScale IWMMXT */
  1201. /**
  1202. * bits per sample/pixel from the demuxer (needed for huffyuv).
  1203. * - encoding: Set by libavcodec.
  1204. * - decoding: Set by user.
  1205. */
  1206. int bits_per_sample;
  1207. /**
  1208. * prediction method (needed for huffyuv)
  1209. * - encoding: Set by user.
  1210. * - decoding: unused
  1211. */
  1212. int prediction_method;
  1213. #define FF_PRED_LEFT 0
  1214. #define FF_PRED_PLANE 1
  1215. #define FF_PRED_MEDIAN 2
  1216. /**
  1217. * sample aspect ratio (0 if unknown)
  1218. * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
  1219. * - encoding: Set by user.
  1220. * - decoding: Set by libavcodec.
  1221. */
  1222. AVRational sample_aspect_ratio;
  1223. /**
  1224. * the picture in the bitstream
  1225. * - encoding: Set by libavcodec.
  1226. * - decoding: Set by libavcodec.
  1227. */
  1228. AVFrame *coded_frame;
  1229. /**
  1230. * debug
  1231. * - encoding: Set by user.
  1232. * - decoding: Set by user.
  1233. */
  1234. int debug;
  1235. #define FF_DEBUG_PICT_INFO 1
  1236. #define FF_DEBUG_RC 2
  1237. #define FF_DEBUG_BITSTREAM 4
  1238. #define FF_DEBUG_MB_TYPE 8
  1239. #define FF_DEBUG_QP 16
  1240. #define FF_DEBUG_MV 32
  1241. #define FF_DEBUG_DCT_COEFF 0x00000040
  1242. #define FF_DEBUG_SKIP 0x00000080
  1243. #define FF_DEBUG_STARTCODE 0x00000100
  1244. #define FF_DEBUG_PTS 0x00000200
  1245. #define FF_DEBUG_ER 0x00000400
  1246. #define FF_DEBUG_MMCO 0x00000800
  1247. #define FF_DEBUG_BUGS 0x00001000
  1248. #define FF_DEBUG_VIS_QP 0x00002000
  1249. #define FF_DEBUG_VIS_MB_TYPE 0x00004000
  1250. /**
  1251. * debug
  1252. * - encoding: Set by user.
  1253. * - decoding: Set by user.
  1254. */
  1255. int debug_mv;
  1256. #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
  1257. #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
  1258. #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
  1259. /**
  1260. * error
  1261. * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
  1262. * - decoding: unused
  1263. */
  1264. uint64_t error[4];
  1265. /**
  1266. * minimum MB quantizer
  1267. * - encoding: unused
  1268. * - decoding: unused
  1269. */
  1270. int mb_qmin;
  1271. /**
  1272. * maximum MB quantizer
  1273. * - encoding: unused
  1274. * - decoding: unused
  1275. */
  1276. int mb_qmax;
  1277. /**
  1278. * motion estimation comparison function
  1279. * - encoding: Set by user.
  1280. * - decoding: unused
  1281. */
  1282. int me_cmp;
  1283. /**
  1284. * subpixel motion estimation comparison function
  1285. * - encoding: Set by user.
  1286. * - decoding: unused
  1287. */
  1288. int me_sub_cmp;
  1289. /**
  1290. * macroblock comparison function (not supported yet)
  1291. * - encoding: Set by user.
  1292. * - decoding: unused
  1293. */
  1294. int mb_cmp;
  1295. /**
  1296. * interlaced DCT comparison function
  1297. * - encoding: Set by user.
  1298. * - decoding: unused
  1299. */
  1300. int ildct_cmp;
  1301. #define FF_CMP_SAD 0
  1302. #define FF_CMP_SSE 1
  1303. #define FF_CMP_SATD 2
  1304. #define FF_CMP_DCT 3
  1305. #define FF_CMP_PSNR 4
  1306. #define FF_CMP_BIT 5
  1307. #define FF_CMP_RD 6
  1308. #define FF_CMP_ZERO 7
  1309. #define FF_CMP_VSAD 8
  1310. #define FF_CMP_VSSE 9
  1311. #define FF_CMP_NSSE 10
  1312. #define FF_CMP_W53 11
  1313. #define FF_CMP_W97 12
  1314. #define FF_CMP_DCTMAX 13
  1315. #define FF_CMP_DCT264 14
  1316. #define FF_CMP_CHROMA 256
  1317. /**
  1318. * ME diamond size & shape
  1319. * - encoding: Set by user.
  1320. * - decoding: unused
  1321. */
  1322. int dia_size;
  1323. /**
  1324. * amount of previous MV predictors (2a+1 x 2a+1 square)
  1325. * - encoding: Set by user.
  1326. * - decoding: unused
  1327. */
  1328. int last_predictor_count;
  1329. /**
  1330. * prepass for motion estimation
  1331. * - encoding: Set by user.
  1332. * - decoding: unused
  1333. */
  1334. int pre_me;
  1335. /**
  1336. * motion estimation prepass comparison function
  1337. * - encoding: Set by user.
  1338. * - decoding: unused
  1339. */
  1340. int me_pre_cmp;
  1341. /**
  1342. * ME prepass diamond size & shape
  1343. * - encoding: Set by user.
  1344. * - decoding: unused
  1345. */
  1346. int pre_dia_size;
  1347. /**
  1348. * subpel ME quality
  1349. * - encoding: Set by user.
  1350. * - decoding: unused
  1351. */
  1352. int me_subpel_quality;
  1353. /**
  1354. * callback to negotiate the pixelFormat
  1355. * @param fmt is the list of formats which are supported by the codec,
  1356. * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
  1357. * The first is always the native one.
  1358. * @return the chosen format
  1359. * - encoding: unused
  1360. * - decoding: Set by user, if not set the native format will be chosen.
  1361. */
  1362. enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
  1363. /**
  1364. * DTG active format information (additional aspect ratio
  1365. * information only used in DVB MPEG-2 transport streams)
  1366. * 0 if not set.
  1367. *
  1368. * - encoding: unused
  1369. * - decoding: Set by decoder.
  1370. */
  1371. int dtg_active_format;
  1372. #define FF_DTG_AFD_SAME 8
  1373. #define FF_DTG_AFD_4_3 9
  1374. #define FF_DTG_AFD_16_9 10
  1375. #define FF_DTG_AFD_14_9 11
  1376. #define FF_DTG_AFD_4_3_SP_14_9 13
  1377. #define FF_DTG_AFD_16_9_SP_14_9 14
  1378. #define FF_DTG_AFD_SP_4_3 15
  1379. /**
  1380. * maximum motion estimation search range in subpel units
  1381. * If 0 then no limit.
  1382. *
  1383. * - encoding: Set by user.
  1384. * - decoding: unused
  1385. */
  1386. int me_range;
  1387. /**
  1388. * intra quantizer bias
  1389. * - encoding: Set by user.
  1390. * - decoding: unused
  1391. */
  1392. int intra_quant_bias;
  1393. #define FF_DEFAULT_QUANT_BIAS 999999
  1394. /**
  1395. * inter quantizer bias
  1396. * - encoding: Set by user.
  1397. * - decoding: unused
  1398. */
  1399. int inter_quant_bias;
  1400. /**
  1401. * color table ID
  1402. * - encoding: unused
  1403. * - decoding: Which clrtable should be used for 8bit RGB images.
  1404. * Tables have to be stored somewhere. FIXME
  1405. */
  1406. int color_table_id;
  1407. /**
  1408. * internal_buffer count
  1409. * Don't touch, used by libavcodec default_get_buffer().
  1410. */
  1411. int internal_buffer_count;
  1412. /**
  1413. * internal_buffers
  1414. * Don't touch, used by libavcodec default_get_buffer().
  1415. */
  1416. void *internal_buffer;
  1417. #define FF_LAMBDA_SHIFT 7
  1418. #define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
  1419. #define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
  1420. #define FF_LAMBDA_MAX (256*128-1)
  1421. #define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
  1422. /**
  1423. * Global quality for codecs which cannot change it per frame.
  1424. * This should be proportional to MPEG-1/2/4 qscale.
  1425. * - encoding: Set by user.
  1426. * - decoding: unused
  1427. */
  1428. int global_quality;
  1429. #define FF_CODER_TYPE_VLC 0
  1430. #define FF_CODER_TYPE_AC 1
  1431. #define FF_CODER_TYPE_RAW 2
  1432. #define FF_CODER_TYPE_RLE 3
  1433. #define FF_CODER_TYPE_DEFLATE 4
  1434. /**
  1435. * coder type
  1436. * - encoding: Set by user.
  1437. * - decoding: unused
  1438. */
  1439. int coder_type;
  1440. /**
  1441. * context model
  1442. * - encoding: Set by user.
  1443. * - decoding: unused
  1444. */
  1445. int context_model;
  1446. #if 0
  1447. /**
  1448. *
  1449. * - encoding: unused
  1450. * - decoding: Set by user.
  1451. */
  1452. uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size);
  1453. #endif
  1454. /**
  1455. * slice flags
  1456. * - encoding: unused
  1457. * - decoding: Set by user.
  1458. */
  1459. int slice_flags;
  1460. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  1461. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
  1462. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  1463. /**
  1464. * XVideo Motion Acceleration
  1465. * - encoding: forbidden
  1466. * - decoding: set by decoder
  1467. */
  1468. int xvmc_acceleration;
  1469. /**
  1470. * macroblock decision mode
  1471. * - encoding: Set by user.
  1472. * - decoding: unused
  1473. */
  1474. int mb_decision;
  1475. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  1476. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  1477. #define FF_MB_DECISION_RD 2 ///< rate distoration
  1478. /**
  1479. * custom intra quantization matrix
  1480. * - encoding: Set by user, can be NULL.
  1481. * - decoding: Set by libavcodec.
  1482. */
  1483. uint16_t *intra_matrix;
  1484. /**
  1485. * custom inter quantization matrix
  1486. * - encoding: Set by user, can be NULL.
  1487. * - decoding: Set by libavcodec.
  1488. */
  1489. uint16_t *inter_matrix;
  1490. /**
  1491. * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  1492. * This is used to work around some encoder bugs.
  1493. * - encoding: unused
  1494. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  1495. */
  1496. unsigned int stream_codec_tag;
  1497. /**
  1498. * scene change detection threshold
  1499. * 0 is default, larger means fewer detected scene changes.
  1500. * - encoding: Set by user.
  1501. * - decoding: unused
  1502. */
  1503. int scenechange_threshold;
  1504. /**
  1505. * minimum Lagrange multipler
  1506. * - encoding: Set by user.
  1507. * - decoding: unused
  1508. */
  1509. int lmin;
  1510. /**
  1511. * maximum Lagrange multipler
  1512. * - encoding: Set by user.
  1513. * - decoding: unused
  1514. */
  1515. int lmax;
  1516. /**
  1517. * palette control structure
  1518. * - encoding: ??? (no palette-enabled encoder yet)
  1519. * - decoding: Set by user.
  1520. */
  1521. struct AVPaletteControl *palctrl;
  1522. /**
  1523. * noise reduction strength
  1524. * - encoding: Set by user.
  1525. * - decoding: unused
  1526. */
  1527. int noise_reduction;
  1528. /**
  1529. * Called at the beginning of a frame to get cr buffer for it.
  1530. * Buffer type (size, hints) must be the same. libavcodec won't check it.
  1531. * libavcodec will pass previous buffer in pic, function should return
  1532. * same buffer or new buffer with old frame "painted" into it.
  1533. * If pic.data[0] == NULL must behave like get_buffer().
  1534. * - encoding: unused
  1535. * - decoding: Set by libavcodec., user can override
  1536. */
  1537. int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
  1538. /**
  1539. * Number of bits which should be loaded into the rc buffer before decoding starts.
  1540. * - encoding: Set by user.
  1541. * - decoding: unused
  1542. */
  1543. int rc_initial_buffer_occupancy;
  1544. /**
  1545. *
  1546. * - encoding: Set by user.
  1547. * - decoding: unused
  1548. */
  1549. int inter_threshold;
  1550. /**
  1551. * CODEC_FLAG2_*
  1552. * - encoding: Set by user.
  1553. * - decoding: Set by user.
  1554. */
  1555. int flags2;
  1556. /**
  1557. * Simulates errors in the bitstream to test error concealment.
  1558. * - encoding: Set by user.
  1559. * - decoding: unused
  1560. */
  1561. int error_rate;
  1562. /**
  1563. * MP3 antialias algorithm, see FF_AA_* below.
  1564. * - encoding: unused
  1565. * - decoding: Set by user.
  1566. */
  1567. int antialias_algo;
  1568. #define FF_AA_AUTO 0
  1569. #define FF_AA_FASTINT 1 //not implemented yet
  1570. #define FF_AA_INT 2
  1571. #define FF_AA_FLOAT 3
  1572. /**
  1573. * quantizer noise shaping
  1574. * - encoding: Set by user.
  1575. * - decoding: unused
  1576. */
  1577. int quantizer_noise_shaping;
  1578. /**
  1579. * thread count
  1580. * is used to decide how many independent tasks should be passed to execute()
  1581. * - encoding: Set by user.
  1582. * - decoding: Set by user.
  1583. */
  1584. int thread_count;
  1585. /**
  1586. * The codec may call this to execute several independent things.
  1587. * It will return only after finishing all tasks.
  1588. * The user may replace this with some multithreaded implementation,
  1589. * the default implementation will execute the parts serially.
  1590. * @param count the number of things to execute
  1591. * - encoding: Set by libavcodec, user can override.
  1592. * - decoding: Set by libavcodec, user can override.
  1593. */
  1594. int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void **arg2, int *ret, int count);
  1595. /**
  1596. * thread opaque
  1597. * Can be used by execute() to store some per AVCodecContext stuff.
  1598. * - encoding: set by execute()
  1599. * - decoding: set by execute()
  1600. */
  1601. void *thread_opaque;
  1602. /**
  1603. * Motion estimation threshold below which no motion estimation is
  1604. * performed, but instead the user specified motion vectors are used.
  1605. *
  1606. * - encoding: Set by user.
  1607. * - decoding: unused
  1608. */
  1609. int me_threshold;
  1610. /**
  1611. * Macroblock threshold below which the user specified macroblock types will be used.
  1612. * - encoding: Set by user.
  1613. * - decoding: unused
  1614. */
  1615. int mb_threshold;
  1616. /**
  1617. * precision of the intra DC coefficient - 8
  1618. * - encoding: Set by user.
  1619. * - decoding: unused
  1620. */
  1621. int intra_dc_precision;
  1622. /**
  1623. * noise vs. sse weight for the nsse comparsion function
  1624. * - encoding: Set by user.
  1625. * - decoding: unused
  1626. */
  1627. int nsse_weight;
  1628. /**
  1629. * Number of macroblock rows at the top which are skipped.
  1630. * - encoding: unused
  1631. * - decoding: Set by user.
  1632. */
  1633. int skip_top;
  1634. /**
  1635. * Number of macroblock rows at the bottom which are skipped.
  1636. * - encoding: unused
  1637. * - decoding: Set by user.
  1638. */
  1639. int skip_bottom;
  1640. /**
  1641. * profile
  1642. * - encoding: Set by user.
  1643. * - decoding: Set by libavcodec.
  1644. */
  1645. int profile;
  1646. #define FF_PROFILE_UNKNOWN -99
  1647. #define FF_PROFILE_AAC_MAIN 0
  1648. #define FF_PROFILE_AAC_LOW 1
  1649. #define FF_PROFILE_AAC_SSR 2
  1650. #define FF_PROFILE_AAC_LTP 3
  1651. /**
  1652. * level
  1653. * - encoding: Set by user.
  1654. * - decoding: Set by libavcodec.
  1655. */
  1656. int level;
  1657. #define FF_LEVEL_UNKNOWN -99
  1658. /**
  1659. * low resolution decoding, 1-> 1/2 size, 2->1/4 size
  1660. * - encoding: unused
  1661. * - decoding: Set by user.
  1662. */
  1663. int lowres;
  1664. /**
  1665. * Bitstream width / height, may be different from width/height if lowres
  1666. * or other things are used.
  1667. * - encoding: unused
  1668. * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
  1669. */
  1670. int coded_width, coded_height;
  1671. /**
  1672. * frame skip threshold
  1673. * - encoding: Set by user.
  1674. * - decoding: unused
  1675. */
  1676. int frame_skip_threshold;
  1677. /**
  1678. * frame skip factor
  1679. * - encoding: Set by user.
  1680. * - decoding: unused
  1681. */
  1682. int frame_skip_factor;
  1683. /**
  1684. * frame skip exponent
  1685. * - encoding: Set by user.
  1686. * - decoding: unused
  1687. */
  1688. int frame_skip_exp;
  1689. /**
  1690. * frame skip comparison function
  1691. * - encoding: Set by user.
  1692. * - decoding: unused
  1693. */
  1694. int frame_skip_cmp;
  1695. /**
  1696. * Border processing masking, raises the quantizer for mbs on the borders
  1697. * of the picture.
  1698. * - encoding: Set by user.
  1699. * - decoding: unused
  1700. */
  1701. float border_masking;
  1702. /**
  1703. * minimum MB lagrange multipler
  1704. * - encoding: Set by user.
  1705. * - decoding: unused
  1706. */
  1707. int mb_lmin;
  1708. /**
  1709. * maximum MB lagrange multipler
  1710. * - encoding: Set by user.
  1711. * - decoding: unused
  1712. */
  1713. int mb_lmax;
  1714. /**
  1715. *
  1716. * - encoding: Set by user.
  1717. * - decoding: unused
  1718. */
  1719. int me_penalty_compensation;
  1720. /**
  1721. *
  1722. * - encoding: unused
  1723. * - decoding: Set by user.
  1724. */
  1725. enum AVDiscard skip_loop_filter;
  1726. /**
  1727. *
  1728. * - encoding: unused
  1729. * - decoding: Set by user.
  1730. */
  1731. enum AVDiscard skip_idct;
  1732. /**
  1733. *
  1734. * - encoding: unused
  1735. * - decoding: Set by user.
  1736. */
  1737. enum AVDiscard skip_frame;
  1738. /**
  1739. *
  1740. * - encoding: Set by user.
  1741. * - decoding: unused
  1742. */
  1743. int bidir_refine;
  1744. /**
  1745. *
  1746. * - encoding: Set by user.
  1747. * - decoding: unused
  1748. */
  1749. int brd_scale;
  1750. /**
  1751. * constant rate factor - quality-based VBR - values ~correspond to qps
  1752. * - encoding: Set by user.
  1753. * - decoding: unused
  1754. */
  1755. float crf;
  1756. /**
  1757. * constant quantization parameter rate control method
  1758. * - encoding: Set by user.
  1759. * - decoding: unused
  1760. */
  1761. int cqp;
  1762. /**
  1763. * minimum GOP size
  1764. * - encoding: Set by user.
  1765. * - decoding: unused
  1766. */
  1767. int keyint_min;
  1768. /**
  1769. * number of reference frames
  1770. * - encoding: Set by user.
  1771. * - decoding: unused
  1772. */
  1773. int refs;
  1774. /**
  1775. * chroma qp offset from luma
  1776. * - encoding: Set by user.
  1777. * - decoding: unused
  1778. */
  1779. int chromaoffset;
  1780. /**
  1781. * Influences how often B-frames are used.
  1782. * - encoding: Set by user.
  1783. * - decoding: unused
  1784. */
  1785. int bframebias;
  1786. /**
  1787. * trellis RD quantization
  1788. * - encoding: Set by user.
  1789. * - decoding: unused
  1790. */
  1791. int trellis;
  1792. /**
  1793. * Reduce fluctuations in qp (before curve compression).
  1794. * - encoding: Set by user.
  1795. * - decoding: unused
  1796. */
  1797. float complexityblur;
  1798. /**
  1799. * in-loop deblocking filter alphac0 parameter
  1800. * alpha is in the range -6...6
  1801. * - encoding: Set by user.
  1802. * - decoding: unused
  1803. */
  1804. int deblockalpha;
  1805. /**
  1806. * in-loop deblocking filter beta parameter
  1807. * beta is in the range -6...6
  1808. * - encoding: Set by user.
  1809. * - decoding: unused
  1810. */
  1811. int deblockbeta;
  1812. /**
  1813. * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
  1814. * - encoding: Set by user.
  1815. * - decoding: unused
  1816. */
  1817. int partitions;
  1818. #define X264_PART_I4X4 0x001 /* Analyse i4x4 */
  1819. #define X264_PART_I8X8 0x002 /* Analyse i8x8 (requires 8x8 transform) */
  1820. #define X264_PART_P8X8 0x010 /* Analyse p16x8, p8x16 and p8x8 */
  1821. #define X264_PART_P4X4 0x020 /* Analyse p8x4, p4x8, p4x4 */
  1822. #define X264_PART_B8X8 0x100 /* Analyse b16x8, b8x16 and b8x8 */
  1823. /**
  1824. * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal)
  1825. * - encoding: Set by user.
  1826. * - decoding: unused
  1827. */
  1828. int directpred;
  1829. /**
  1830. * Audio cutoff bandwidth (0 means "automatic"), currently used only by FAAC.
  1831. * - encoding: Set by user.
  1832. * - decoding: unused
  1833. */
  1834. int cutoff;
  1835. /**
  1836. * Multiplied by qscale for each frame and added to scene_change_score.
  1837. * - encoding: Set by user.
  1838. * - decoding: unused
  1839. */
  1840. int scenechange_factor;
  1841. /**
  1842. *
  1843. * Note: Value depends upon the compare function used for fullpel ME.
  1844. * - encoding: Set by user.
  1845. * - decoding: unused
  1846. */
  1847. int mv0_threshold;
  1848. /**
  1849. * Adjusts sensitivity of b_frame_strategy 1.
  1850. * - encoding: Set by user.
  1851. * - decoding: unused
  1852. */
  1853. int b_sensitivity;
  1854. /**
  1855. * - encoding: Set by user.
  1856. * - decoding: unused
  1857. */
  1858. int compression_level;
  1859. #define FF_COMPRESSION_DEFAULT -1
  1860. /**
  1861. * Sets whether to use LPC mode - used by FLAC encoder.
  1862. * - encoding: Set by user.
  1863. * - decoding: unused
  1864. */
  1865. int use_lpc;
  1866. /**
  1867. * LPC coefficient precision - used by FLAC encoder
  1868. * - encoding: Set by user.
  1869. * - decoding: unused
  1870. */
  1871. int lpc_coeff_precision;
  1872. /**
  1873. * - encoding: Set by user.
  1874. * - decoding: unused
  1875. */
  1876. int min_prediction_order;
  1877. /**
  1878. * - encoding: Set by user.
  1879. * - decoding: unused
  1880. */
  1881. int max_prediction_order;
  1882. /**
  1883. * search method for selecting prediction order
  1884. * - encoding: Set by user.
  1885. * - decoding: unused
  1886. */
  1887. int prediction_order_method;
  1888. /**
  1889. * - encoding: Set by user.
  1890. * - decoding: unused
  1891. */
  1892. int min_partition_order;
  1893. /**
  1894. * - encoding: Set by user.
  1895. * - decoding: unused
  1896. */
  1897. int max_partition_order;
  1898. /**
  1899. * GOP timecode frame start number, in non drop frame format
  1900. * - encoding: Set by user.
  1901. * - decoding: unused
  1902. */
  1903. int64_t timecode_frame_start;
  1904. } AVCodecContext;
  1905. /**
  1906. * AVCodec.
  1907. */
  1908. typedef struct AVCodec {
  1909. const char *name;
  1910. enum CodecType type;
  1911. enum CodecID id;
  1912. int priv_data_size;
  1913. int (*init)(AVCodecContext *);
  1914. int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
  1915. int (*close)(AVCodecContext *);
  1916. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  1917. uint8_t *buf, int buf_size);
  1918. int capabilities;
  1919. struct AVCodec *next;
  1920. void (*flush)(AVCodecContext *);
  1921. const AVRational *supported_framerates; ///array of supported framerates, or NULL if any, array is terminated by {0,0}
  1922. const enum PixelFormat *pix_fmts; ///array of supported pixel formats, or NULL if unknown, array is terminanted by -1
  1923. } AVCodec;
  1924. /**
  1925. * four components are given, that's all.
  1926. * the last component is alpha
  1927. */
  1928. typedef struct AVPicture {
  1929. uint8_t *data[4];
  1930. int linesize[4]; ///< number of bytes per line
  1931. } AVPicture;
  1932. /**
  1933. * AVPaletteControl
  1934. * This structure defines a method for communicating palette changes
  1935. * between and demuxer and a decoder.
  1936. *
  1937. * @deprecated Use AVPacket to send palette changes instead.
  1938. * This is totally broken.
  1939. */
  1940. #define AVPALETTE_SIZE 1024
  1941. #define AVPALETTE_COUNT 256
  1942. typedef struct AVPaletteControl {
  1943. /* Demuxer sets this to 1 to indicate the palette has changed;
  1944. * decoder resets to 0. */
  1945. int palette_changed;
  1946. /* 4-byte ARGB palette entries, stored in native byte order; note that
  1947. * the individual palette components should be on a 8-bit scale; if
  1948. * the palette data comes from an IBM VGA native format, the component
  1949. * data is probably 6 bits in size and needs to be scaled. */
  1950. unsigned int palette[AVPALETTE_COUNT];
  1951. } AVPaletteControl attribute_deprecated;
  1952. typedef struct AVSubtitleRect {
  1953. uint16_t x;
  1954. uint16_t y;
  1955. uint16_t w;
  1956. uint16_t h;
  1957. uint16_t nb_colors;
  1958. int linesize;
  1959. uint32_t *rgba_palette;
  1960. uint8_t *bitmap;
  1961. } AVSubtitleRect;
  1962. typedef struct AVSubtitle {
  1963. uint16_t format; /* 0 = graphics */
  1964. uint32_t start_display_time; /* relative to packet pts, in ms */
  1965. uint32_t end_display_time; /* relative to packet pts, in ms */
  1966. uint32_t num_rects;
  1967. AVSubtitleRect *rects;
  1968. } AVSubtitle;
  1969. /* resample.c */
  1970. struct ReSampleContext;
  1971. struct AVResampleContext;
  1972. typedef struct ReSampleContext ReSampleContext;
  1973. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  1974. int output_rate, int input_rate);
  1975. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  1976. void audio_resample_close(ReSampleContext *s);
  1977. struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
  1978. int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
  1979. void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
  1980. void av_resample_close(struct AVResampleContext *c);
  1981. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  1982. /* YUV420 format is assumed ! */
  1983. /**
  1984. * @deprecated Use the software scaler (swscale) instead.
  1985. */
  1986. struct ImgReSampleContext attribute_deprecated;
  1987. /**
  1988. * @deprecated Use the software scaler (swscale) instead.
  1989. */
  1990. typedef struct ImgReSampleContext ImgReSampleContext attribute_deprecated;
  1991. /**
  1992. * @deprecated Use the software scaler (swscale) instead.
  1993. */
  1994. attribute_deprecated ImgReSampleContext *img_resample_init(int output_width, int output_height,
  1995. int input_width, int input_height);
  1996. /**
  1997. * @deprecated Use the software scaler (swscale) instead.
  1998. */
  1999. attribute_deprecated ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  2000. int iwidth, int iheight,
  2001. int topBand, int bottomBand,
  2002. int leftBand, int rightBand,
  2003. int padtop, int padbottom,
  2004. int padleft, int padright);
  2005. /**
  2006. * @deprecated Use the software scaler (swscale) instead.
  2007. */
  2008. attribute_deprecated void img_resample(ImgReSampleContext *s,
  2009. AVPicture *output, const AVPicture *input);
  2010. /**
  2011. * @deprecated Use the software scaler (swscale) instead.
  2012. */
  2013. attribute_deprecated void img_resample_close(ImgReSampleContext *s);
  2014. #endif
  2015. /**
  2016. * Allocate memory for a picture. Call avpicture_free to free it.
  2017. *
  2018. * @param picture the picture to be filled in
  2019. * @param pix_fmt the format of the picture
  2020. * @param width the width of the picture
  2021. * @param height the height of the picture
  2022. * @return zero if successful, a negative value if not
  2023. */
  2024. int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height);
  2025. /**
  2026. * Free a picture previously allocated by avpicture_alloc().
  2027. *
  2028. * @param picture the AVPicture to be freed
  2029. */
  2030. void avpicture_free(AVPicture *picture);
  2031. /**
  2032. * Fill in the AVPicture fields.
  2033. * The fields of the given AVPicture are filled in by using the 'ptr' address
  2034. * which points to the image data buffer. Depending on the specified picture
  2035. * format, one or multiple image data pointers and line sizes will be set.
  2036. * If a planar format is specified, several pointers will be set pointing to
  2037. * the different picture planes and the line sizes of the different planes
  2038. * will be stored in the lines_sizes array.
  2039. *
  2040. * @param picture AVPicture whose fields are to be filled in
  2041. * @param ptr Buffer which will contain or contains the actual image data
  2042. * @param pix_fmt The format in which the picture data is stored.
  2043. * @param width the width of the image in pixels
  2044. * @param height the height of the image in pixels
  2045. * @return size of the image data in bytes
  2046. */
  2047. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  2048. int pix_fmt, int width, int height);
  2049. int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
  2050. unsigned char *dest, int dest_size);
  2051. /**
  2052. * Calculate the size in bytes that a picture of the given width and height
  2053. * would occupy if stored in the given picture format.
  2054. *
  2055. * @param pix_fmt the given picture format
  2056. * @param width the width of the image
  2057. * @param height the height of the image
  2058. * @return Image data size in bytes
  2059. */
  2060. int avpicture_get_size(int pix_fmt, int width, int height);
  2061. void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
  2062. const char *avcodec_get_pix_fmt_name(int pix_fmt);
  2063. void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
  2064. enum PixelFormat avcodec_get_pix_fmt(const char* name);
  2065. unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p);
  2066. #define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
  2067. #define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
  2068. #define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
  2069. #define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
  2070. #define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
  2071. #define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
  2072. /**
  2073. * Computes what kind of losses will occur when converting from one specific
  2074. * pixel format to another.
  2075. * When converting from one pixel format to another, information loss may occur.
  2076. * For example, when converting from RGB24 to GRAY, the color information will
  2077. * be lost. Similarly, other losses occur when converting from some formats to
  2078. * other formats. These losses can involve loss of chroma, but also loss of
  2079. * resolution, loss of color depth, loss due to the color space conversion, loss
  2080. * of the alpha bits or loss due to color quantization.
  2081. * avcodec_get_fix_fmt_loss() informs you about the various types of losses
  2082. * which will occur when converting from one pixel format to another.
  2083. *
  2084. * @param[in] dst_pix_fmt destination pixel format
  2085. * @param[in] src_pix_fmt source pixel format
  2086. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  2087. * @return Combination of flags informing you what kind of losses will occur.
  2088. */
  2089. int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
  2090. int has_alpha);
  2091. /**
  2092. * Finds the best pixel format to convert to given a certain source pixel
  2093. * format. When converting from one pixel format to another, information loss
  2094. * may occur. For example, when converting from RGB24 to GRAY, the color
  2095. * information will be lost. Similarly, other losses occur when converting from
  2096. * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
  2097. * the given pixel formats should be used to suffer the least amount of loss.
  2098. * The pixel formats from which it chooses one, are determined by the
  2099. * \p pix_fmt_mask parameter.
  2100. *
  2101. * @code
  2102. * src_pix_fmt = PIX_FMT_YUV420P;
  2103. * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
  2104. * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
  2105. * @endcode
  2106. *
  2107. * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
  2108. * @param[in] src_pix_fmt source pixel format
  2109. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  2110. * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
  2111. * @return The best pixel format to convert to or -1 if none was found.
  2112. */
  2113. int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
  2114. int has_alpha, int *loss_ptr);
  2115. /**
  2116. * Print in buf the string corresponding to the pixel format with
  2117. * number pix_fmt, or an header if pix_fmt is negative.
  2118. *
  2119. * @param buf[in] the buffer where to write the string
  2120. * @param buf_size[in] the size of buf
  2121. * @param pix_fmt[in] the number of the pixel format to print the corresponding info string, or
  2122. * a negative value to print the corresponding header.
  2123. * Meaningful values for obtaining a pixel format info vary from 0 to PIX_FMT_NB -1.
  2124. */
  2125. void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt);
  2126. #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
  2127. #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
  2128. /**
  2129. * Tell if an image really has transparent alpha values.
  2130. * @return ored mask of FF_ALPHA_xxx constants
  2131. */
  2132. int img_get_alpha_info(const AVPicture *src,
  2133. int pix_fmt, int width, int height);
  2134. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  2135. /**
  2136. * convert among pixel formats
  2137. * @deprecated Use the software scaler (swscale) instead.
  2138. */
  2139. attribute_deprecated int img_convert(AVPicture *dst, int dst_pix_fmt,
  2140. const AVPicture *src, int pix_fmt,
  2141. int width, int height);
  2142. #endif
  2143. /* deinterlace a picture */
  2144. /* deinterlace - if not supported return -1 */
  2145. int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
  2146. int pix_fmt, int width, int height);
  2147. /* external high level API */
  2148. extern AVCodec *first_avcodec;
  2149. /* returns LIBAVCODEC_VERSION_INT constant */
  2150. unsigned avcodec_version(void);
  2151. /* returns LIBAVCODEC_BUILD constant */
  2152. unsigned avcodec_build(void);
  2153. /**
  2154. * Initializes libavcodec.
  2155. *
  2156. * @warning This function \e must be called before any other libavcodec
  2157. * function.
  2158. */
  2159. void avcodec_init(void);
  2160. void register_avcodec(AVCodec *format);
  2161. /**
  2162. * Finds an encoder with a matching codec ID.
  2163. *
  2164. * @param id CodecID of the requested encoder
  2165. * @return An encoder if one was found, NULL otherwise.
  2166. */
  2167. AVCodec *avcodec_find_encoder(enum CodecID id);
  2168. /**
  2169. * Finds an encoder with the specified name.
  2170. *
  2171. * @param name name of the requested encoder
  2172. * @return An encoder if one was found, NULL otherwise.
  2173. */
  2174. AVCodec *avcodec_find_encoder_by_name(const char *name);
  2175. /**
  2176. * Finds a decoder with a matching codec ID.
  2177. *
  2178. * @param id CodecID of the requested decoder
  2179. * @return A decoder if one was found, NULL otherwise.
  2180. */
  2181. AVCodec *avcodec_find_decoder(enum CodecID id);
  2182. /**
  2183. * Finds an decoder with the specified name.
  2184. *
  2185. * @param name name of the requested decoder
  2186. * @return A decoder if one was found, NULL otherwise.
  2187. */
  2188. AVCodec *avcodec_find_decoder_by_name(const char *name);
  2189. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  2190. /**
  2191. * Sets the fields of the given AVCodecContext to default values.
  2192. *
  2193. * @param s The AVCodecContext of which the fields should be set to default values.
  2194. */
  2195. void avcodec_get_context_defaults(AVCodecContext *s);
  2196. /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
  2197. * we WILL change its arguments and name a few times! */
  2198. void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType);
  2199. /**
  2200. * Allocates an AVCodecContext and sets its fields to default values. The
  2201. * resulting struct can be deallocated by simply calling av_free().
  2202. *
  2203. * @return An AVCodecContext filled with default values or NULL on failure.
  2204. * @see avcodec_get_context_defaults
  2205. */
  2206. AVCodecContext *avcodec_alloc_context(void);
  2207. /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
  2208. * we WILL change its arguments and name a few times! */
  2209. AVCodecContext *avcodec_alloc_context2(enum CodecType);
  2210. /**
  2211. * Sets the fields of the given AVFrame to default values.
  2212. *
  2213. * @param pic The AVFrame of which the fields should be set to default values.
  2214. */
  2215. void avcodec_get_frame_defaults(AVFrame *pic);
  2216. /**
  2217. * Allocates an AVFrame and sets its fields to default values. The resulting
  2218. * struct can be deallocated by simply calling av_free().
  2219. *
  2220. * @return An AVFrame filled with default values or NULL on failure.
  2221. * @see avcodec_get_frame_defaults
  2222. */
  2223. AVFrame *avcodec_alloc_frame(void);
  2224. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
  2225. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
  2226. int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
  2227. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
  2228. /**
  2229. * Checks if the given dimension of a picture is valid, meaning that all
  2230. * bytes of the picture can be addressed with a signed int.
  2231. *
  2232. * @param[in] w Width of the picture.
  2233. * @param[in] h Height of the picture.
  2234. * @return Zero if valid, a negative value if invalid.
  2235. */
  2236. int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h);
  2237. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
  2238. int avcodec_thread_init(AVCodecContext *s, int thread_count);
  2239. void avcodec_thread_free(AVCodecContext *s);
  2240. int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
  2241. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
  2242. //FIXME func typedef
  2243. /**
  2244. * Initializes the AVCodecContext to use the given AVCodec. Prior to using this
  2245. * function the context has to be allocated.
  2246. *
  2247. * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
  2248. * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  2249. * retrieving a codec.
  2250. *
  2251. * @warning This function is not thread safe!
  2252. *
  2253. * @code
  2254. * codec = avcodec_find_decoder(CODEC_ID_H264);
  2255. * if (!codec)
  2256. * exit(1);
  2257. *
  2258. * context = avcodec_alloc_context();
  2259. *
  2260. * if (avcodec_open(context, codec) < 0)
  2261. * exit(1);
  2262. * @endcode
  2263. *
  2264. * @param avctx The context which will be set up to use the given codec.
  2265. * @param codec The codec to use within the context.
  2266. * @return zero on success, a negative value on error
  2267. * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder
  2268. */
  2269. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  2270. /**
  2271. * @deprecated Use avcodec_decode_audio2() instead.
  2272. */
  2273. attribute_deprecated int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  2274. int *frame_size_ptr,
  2275. uint8_t *buf, int buf_size);
  2276. /**
  2277. * Decodes an audio frame from \p buf into \p samples.
  2278. * The avcodec_decode_audio2() function decodes an audio frame from the input
  2279. * buffer \p buf of size \p buf_size. To decode it, it makes use of the
  2280. * audio codec which was coupled with \p avctx using avcodec_open(). The
  2281. * resulting decoded frame is stored in output buffer \p samples. If no frame
  2282. * could be decompressed, \p frame_size_ptr is zero. Otherwise, it is the
  2283. * decompressed frame size in \e bytes.
  2284. *
  2285. * @warning You \e must set \p frame_size_ptr to the allocated size of the
  2286. * output buffer before calling avcodec_decode_audio2().
  2287. *
  2288. * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than
  2289. * the actual read bytes because some optimized bitstream readers read 32 or 64
  2290. * bits at once and could read over the end.
  2291. *
  2292. * @warning The end of the input buffer \p buf should be set to 0 to ensure that
  2293. * no overreading happens for damaged MPEG streams.
  2294. *
  2295. * @note You might have to align the input buffer \p buf and output buffer \p
  2296. * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
  2297. * necessary at all, on others it won't work at all if not aligned and on others
  2298. * it will work but it will have an impact on performance. In practice, the
  2299. * bitstream should have 4 byte alignment at minimum and all sample data should
  2300. * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If
  2301. * the linesize is not a multiple of 16 then there's no sense in aligning the
  2302. * start of the buffer to 16.
  2303. *
  2304. * @param avctx the codec context
  2305. * @param[out] samples the output buffer
  2306. * @param[in,out] frame_size_ptr the output buffer size in bytes
  2307. * @param[in] buf the input buffer
  2308. * @param[in] buf_size the input buffer size in bytes
  2309. * @return On error a negative value is returned, otherwise the number of bytes
  2310. * used or zero if no frame could be decompressed.
  2311. */
  2312. int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
  2313. int *frame_size_ptr,
  2314. uint8_t *buf, int buf_size);
  2315. /**
  2316. * Decodes a video frame from \p buf into \p picture.
  2317. * The avcodec_decode_video() function decodes a video frame from the input
  2318. * buffer \p buf of size \p buf_size. To decode it, it makes use of the
  2319. * video codec which was coupled with \p avctx using avcodec_open(). The
  2320. * resulting decoded frame is stored in \p picture.
  2321. *
  2322. * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than
  2323. * the actual read bytes because some optimized bitstream readers read 32 or 64
  2324. * bits at once and could read over the end.
  2325. *
  2326. * @warning The end of the input buffer \p buf should be set to 0 to ensure that
  2327. * no overreading happens for damaged MPEG streams.
  2328. *
  2329. * @note You might have to align the input buffer \p buf and output buffer \p
  2330. * samples. The alignment requirements depend on the CPU: on some CPUs it isn't
  2331. * necessary at all, on others it won't work at all if not aligned and on others
  2332. * it will work but it will have an impact on performance. In practice, the
  2333. * bitstream should have 4 byte alignment at minimum and all sample data should
  2334. * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If
  2335. * the linesize is not a multiple of 16 then there's no sense in aligning the
  2336. * start of the buffer to 16.
  2337. *
  2338. * @param avctx the codec context
  2339. * @param[out] picture The AVFrame in which the decoded video frame will be stored.
  2340. * @param[in] buf the input buffer
  2341. * @param[in] buf_size the size of the input buffer in bytes
  2342. * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
  2343. * @return On error a negative value is returned, otherwise the number of bytes
  2344. * used or zero if no frame could be decompressed.
  2345. */
  2346. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  2347. int *got_picture_ptr,
  2348. uint8_t *buf, int buf_size);
  2349. /* Decode a subtitle message. Return -1 if error, otherwise return the
  2350. * number of bytes used. If no subtitle could be decompressed,
  2351. * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
  2352. int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
  2353. int *got_sub_ptr,
  2354. const uint8_t *buf, int buf_size);
  2355. int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
  2356. int *data_size_ptr,
  2357. uint8_t *buf, int buf_size);
  2358. /**
  2359. * Encodes an audio frame from \p samples into \p buf.
  2360. * The avcodec_encode_audio() function encodes an audio frame from the input
  2361. * buffer \p samples. To encode it, it makes use of the audio codec which was
  2362. * coupled with \p avctx using avcodec_open(). The resulting encoded frame is
  2363. * stored in output buffer \p buf.
  2364. *
  2365. * @note The output buffer should be at least \c FF_MIN_BUFFER_SIZE bytes large.
  2366. *
  2367. * @param avctx the codec context
  2368. * @param[out] buf the output buffer
  2369. * @param[in] buf_size the output buffer size
  2370. * @param[in] samples the input buffer containing the samples
  2371. * @return On error a negative value is returned, on succes zero or the number
  2372. * of bytes used from the input buffer.
  2373. */
  2374. int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  2375. const short *samples);
  2376. /**
  2377. * Encodes a video frame from \p pict into \p buf.
  2378. * The avcodec_encode_video() function encodes a video frame from the input
  2379. * \p pict. To encode it, it makes use of the video codec which was coupled with
  2380. * \p avctx using avcodec_open(). The resulting encoded bytes representing the
  2381. * frame are stored in the output buffer \p buf. The input picture should be
  2382. * stored using a specific format, namely \c avctx.pix_fmt.
  2383. *
  2384. * @param avctx the codec context
  2385. * @param[out] buf the output buffer for the bitstream of encoded frame
  2386. * @param[in] buf_size the size of the output buffer in bytes
  2387. * @param[in] pict the input picture to encode
  2388. * @return On error a negative value is returned, on success zero or the number
  2389. * of bytes used from the input buffer.
  2390. */
  2391. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  2392. const AVFrame *pict);
  2393. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  2394. const AVSubtitle *sub);
  2395. int avcodec_close(AVCodecContext *avctx);
  2396. void avcodec_register_all(void);
  2397. /**
  2398. * Flush buffers, should be called when seeking or when switching to a different stream.
  2399. */
  2400. void avcodec_flush_buffers(AVCodecContext *avctx);
  2401. void avcodec_default_free_buffers(AVCodecContext *s);
  2402. /* misc useful functions */
  2403. /**
  2404. * Returns a single letter to describe the given picture type \p pict_type.
  2405. *
  2406. * @param[in] pict_type the picture type
  2407. * @return A single character representing the picture type.
  2408. */
  2409. char av_get_pict_type_char(int pict_type);
  2410. /**
  2411. * Returns codec bits per sample.
  2412. *
  2413. * @param[in] codec_id the codec
  2414. * @return Number of bits per sample or zero if unknown for the given codec.
  2415. */
  2416. int av_get_bits_per_sample(enum CodecID codec_id);
  2417. /* frame parsing */
  2418. typedef struct AVCodecParserContext {
  2419. void *priv_data;
  2420. struct AVCodecParser *parser;
  2421. int64_t frame_offset; /* offset of the current frame */
  2422. int64_t cur_offset; /* current offset
  2423. (incremented by each av_parser_parse()) */
  2424. int64_t last_frame_offset; /* offset of the last frame */
  2425. /* video info */
  2426. int pict_type; /* XXX: Put it back in AVCodecContext. */
  2427. int repeat_pict; /* XXX: Put it back in AVCodecContext. */
  2428. int64_t pts; /* pts of the current frame */
  2429. int64_t dts; /* dts of the current frame */
  2430. /* private data */
  2431. int64_t last_pts;
  2432. int64_t last_dts;
  2433. int fetch_timestamp;
  2434. #define AV_PARSER_PTS_NB 4
  2435. int cur_frame_start_index;
  2436. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
  2437. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
  2438. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
  2439. int flags;
  2440. #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
  2441. int64_t offset; ///< byte offset from starting packet start
  2442. int64_t last_offset;
  2443. } AVCodecParserContext;
  2444. typedef struct AVCodecParser {
  2445. int codec_ids[5]; /* several codec IDs are permitted */
  2446. int priv_data_size;
  2447. int (*parser_init)(AVCodecParserContext *s);
  2448. int (*parser_parse)(AVCodecParserContext *s,
  2449. AVCodecContext *avctx,
  2450. const uint8_t **poutbuf, int *poutbuf_size,
  2451. const uint8_t *buf, int buf_size);
  2452. void (*parser_close)(AVCodecParserContext *s);
  2453. int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  2454. struct AVCodecParser *next;
  2455. } AVCodecParser;
  2456. extern AVCodecParser *av_first_parser;
  2457. void av_register_codec_parser(AVCodecParser *parser);
  2458. AVCodecParserContext *av_parser_init(int codec_id);
  2459. int av_parser_parse(AVCodecParserContext *s,
  2460. AVCodecContext *avctx,
  2461. uint8_t **poutbuf, int *poutbuf_size,
  2462. const uint8_t *buf, int buf_size,
  2463. int64_t pts, int64_t dts);
  2464. int av_parser_change(AVCodecParserContext *s,
  2465. AVCodecContext *avctx,
  2466. uint8_t **poutbuf, int *poutbuf_size,
  2467. const uint8_t *buf, int buf_size, int keyframe);
  2468. void av_parser_close(AVCodecParserContext *s);
  2469. extern AVCodecParser aac_parser;
  2470. extern AVCodecParser ac3_parser;
  2471. extern AVCodecParser cavsvideo_parser;
  2472. extern AVCodecParser dca_parser;
  2473. extern AVCodecParser dvbsub_parser;
  2474. extern AVCodecParser dvdsub_parser;
  2475. extern AVCodecParser h261_parser;
  2476. extern AVCodecParser h263_parser;
  2477. extern AVCodecParser h264_parser;
  2478. extern AVCodecParser mjpeg_parser;
  2479. extern AVCodecParser mpeg4video_parser;
  2480. extern AVCodecParser mpegaudio_parser;
  2481. extern AVCodecParser mpegvideo_parser;
  2482. extern AVCodecParser pnm_parser;
  2483. extern AVCodecParser vc1_parser;
  2484. typedef struct AVBitStreamFilterContext {
  2485. void *priv_data;
  2486. struct AVBitStreamFilter *filter;
  2487. AVCodecParserContext *parser;
  2488. struct AVBitStreamFilterContext *next;
  2489. } AVBitStreamFilterContext;
  2490. typedef struct AVBitStreamFilter {
  2491. const char *name;
  2492. int priv_data_size;
  2493. int (*filter)(AVBitStreamFilterContext *bsfc,
  2494. AVCodecContext *avctx, const char *args,
  2495. uint8_t **poutbuf, int *poutbuf_size,
  2496. const uint8_t *buf, int buf_size, int keyframe);
  2497. struct AVBitStreamFilter *next;
  2498. } AVBitStreamFilter;
  2499. extern AVBitStreamFilter *av_first_bitstream_filter;
  2500. void av_register_bitstream_filter(AVBitStreamFilter *bsf);
  2501. AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
  2502. int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
  2503. AVCodecContext *avctx, const char *args,
  2504. uint8_t **poutbuf, int *poutbuf_size,
  2505. const uint8_t *buf, int buf_size, int keyframe);
  2506. void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
  2507. extern AVBitStreamFilter dump_extradata_bsf;
  2508. extern AVBitStreamFilter remove_extradata_bsf;
  2509. extern AVBitStreamFilter noise_bsf;
  2510. extern AVBitStreamFilter mp3_header_compress_bsf;
  2511. extern AVBitStreamFilter mp3_header_decompress_bsf;
  2512. extern AVBitStreamFilter mjpega_dump_header_bsf;
  2513. extern AVBitStreamFilter imx_dump_header_bsf;
  2514. /* memory */
  2515. /**
  2516. * Reallocates the given block if it is not large enough, otherwise it
  2517. * does nothing.
  2518. *
  2519. * @see av_realloc
  2520. */
  2521. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
  2522. /* for static data only */
  2523. /**
  2524. * Frees all static arrays and resets their pointers to 0.
  2525. * Call this function to release all statically allocated tables.
  2526. *
  2527. * @deprecated. Code which uses av_free_static is broken/missdesigned
  2528. * and should correctly use static arrays
  2529. *
  2530. */
  2531. attribute_deprecated void av_free_static(void);
  2532. /**
  2533. * Allocation of static arrays.
  2534. *
  2535. * @warning Do not use for normal allocation.
  2536. *
  2537. * @param[in] size The amount of memory you need in bytes.
  2538. * @return block of memory of the requested size
  2539. * @deprecated. Code which uses av_mallocz_static is broken/missdesigned
  2540. * and should correctly use static arrays
  2541. */
  2542. attribute_deprecated void *av_mallocz_static(unsigned int size);
  2543. /**
  2544. * Copy image 'src' to 'dst'.
  2545. */
  2546. void av_picture_copy(AVPicture *dst, const AVPicture *src,
  2547. int pix_fmt, int width, int height);
  2548. /**
  2549. * Crop image top and left side.
  2550. */
  2551. int av_picture_crop(AVPicture *dst, const AVPicture *src,
  2552. int pix_fmt, int top_band, int left_band);
  2553. /**
  2554. * Pad image.
  2555. */
  2556. int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt,
  2557. int padtop, int padbottom, int padleft, int padright, int *color);
  2558. #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
  2559. /**
  2560. * @deprecated Use the software scaler (swscale) instead.
  2561. */
  2562. attribute_deprecated void img_copy(AVPicture *dst, const AVPicture *src,
  2563. int pix_fmt, int width, int height);
  2564. /**
  2565. * @deprecated Use the software scaler (swscale) instead.
  2566. */
  2567. attribute_deprecated int img_crop(AVPicture *dst, const AVPicture *src,
  2568. int pix_fmt, int top_band, int left_band);
  2569. /**
  2570. * @deprecated Use the software scaler (swscale) instead.
  2571. */
  2572. attribute_deprecated int img_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt,
  2573. int padtop, int padbottom, int padleft, int padright, int *color);
  2574. #endif
  2575. extern unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
  2576. /**
  2577. * Parses \p str and put in \p width_ptr and \p height_ptr the detected values.
  2578. *
  2579. * @return 0 in case of a successfull parsing, a negative value otherwise
  2580. * @param[in] str the string to parse: it has to be a string in the format
  2581. * <width>x<height> or a valid video frame size abbreviation.
  2582. * @param[in,out] width_ptr pointer to the variable which will contain the detected
  2583. * frame width value
  2584. * @param[in,out] height_ptr pointer to the variable which will contain the detected
  2585. * frame height value
  2586. */
  2587. int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str);
  2588. /**
  2589. * Parses \p str and put in \p frame_rate the detected values.
  2590. *
  2591. * @return 0 in case of a successfull parsing, a negative value otherwise
  2592. * @param[in] str the string to parse: it has to be a string in the format
  2593. * <frame_rate_nom>/<frame_rate_den>, a float number or a valid video rate abbreviation
  2594. * @param[in,out] frame_rate pointer to the AVRational which will contain the detected
  2595. * frame rate
  2596. */
  2597. int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
  2598. /* error handling */
  2599. #if EINVAL > 0
  2600. #define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */
  2601. #define AVUNERROR(e) (-(e)) /**< Returns a POSIX error code from a library function error return value. */
  2602. #else
  2603. /* Some platforms have E* and errno already negated. */
  2604. #define AVERROR(e) (e)
  2605. #define AVUNERROR(e) (e)
  2606. #endif
  2607. #define AVERROR_UNKNOWN AVERROR(EINVAL) /**< unknown error */
  2608. #define AVERROR_IO AVERROR(EIO) /**< I/O error */
  2609. #define AVERROR_NUMEXPECTED AVERROR(EDOM) /**< Number syntax expected in filename. */
  2610. #define AVERROR_INVALIDDATA AVERROR(EINVAL) /**< invalid data found */
  2611. #define AVERROR_NOMEM AVERROR(ENOMEM) /**< not enough memory */
  2612. #define AVERROR_NOFMT AVERROR(EILSEQ) /**< unknown format */
  2613. #define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< Operation not supported. */
  2614. #define AVERROR_NOENT AVERROR(ENOENT) /**< No such file or directory. */
  2615. #endif /* AVCODEC_H */