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.

4539 lines
151KB

  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 Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_AVCODEC_H
  21. #define AVCODEC_AVCODEC_H
  22. /**
  23. * @file
  24. * external API header
  25. */
  26. #include <errno.h>
  27. #include "libavutil/samplefmt.h"
  28. #include "libavutil/avutil.h"
  29. #include "libavutil/cpu.h"
  30. #include "libavutil/dict.h"
  31. #include "libavutil/log.h"
  32. #include "libavutil/pixfmt.h"
  33. #include "libavutil/rational.h"
  34. #include "libavutil/audioconvert.h"
  35. #include "libavcodec/version.h"
  36. /**
  37. * @defgroup libavc Encoding/Decoding Library
  38. * @{
  39. *
  40. * @defgroup lavc_decoding Decoding
  41. * @{
  42. * @}
  43. *
  44. * @defgroup lavc_encoding Encoding
  45. * @{
  46. * @}
  47. *
  48. * @defgroup lavc_codec Codecs
  49. * @{
  50. * @defgroup lavc_codec_native Native Codecs
  51. * @{
  52. * @}
  53. * @defgroup lavc_codec_wrappers External library wrappers
  54. * @{
  55. * @}
  56. * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
  57. * @{
  58. * @}
  59. * @}
  60. * @defgroup lavc_internal Internal
  61. * @{
  62. * @}
  63. * @}
  64. *
  65. */
  66. /**
  67. * Identify the syntax and semantics of the bitstream.
  68. * The principle is roughly:
  69. * Two decoders with the same ID can decode the same streams.
  70. * Two encoders with the same ID can encode compatible streams.
  71. * There may be slight deviations from the principle due to implementation
  72. * details.
  73. *
  74. * If you add a codec ID to this list, add it so that
  75. * 1. no value of a existing codec ID changes (that would break ABI),
  76. * 2. Give it a value which when taken as ASCII is recognized uniquely by a human as this specific codec.
  77. * This ensures that 2 forks can independently add CodecIDs without producing conflicts.
  78. */
  79. enum CodecID {
  80. CODEC_ID_NONE,
  81. /* video codecs */
  82. CODEC_ID_MPEG1VIDEO,
  83. CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
  84. CODEC_ID_MPEG2VIDEO_XVMC,
  85. CODEC_ID_H261,
  86. CODEC_ID_H263,
  87. CODEC_ID_RV10,
  88. CODEC_ID_RV20,
  89. CODEC_ID_MJPEG,
  90. CODEC_ID_MJPEGB,
  91. CODEC_ID_LJPEG,
  92. CODEC_ID_SP5X,
  93. CODEC_ID_JPEGLS,
  94. CODEC_ID_MPEG4,
  95. CODEC_ID_RAWVIDEO,
  96. CODEC_ID_MSMPEG4V1,
  97. CODEC_ID_MSMPEG4V2,
  98. CODEC_ID_MSMPEG4V3,
  99. CODEC_ID_WMV1,
  100. CODEC_ID_WMV2,
  101. CODEC_ID_H263P,
  102. CODEC_ID_H263I,
  103. CODEC_ID_FLV1,
  104. CODEC_ID_SVQ1,
  105. CODEC_ID_SVQ3,
  106. CODEC_ID_DVVIDEO,
  107. CODEC_ID_HUFFYUV,
  108. CODEC_ID_CYUV,
  109. CODEC_ID_H264,
  110. CODEC_ID_INDEO3,
  111. CODEC_ID_VP3,
  112. CODEC_ID_THEORA,
  113. CODEC_ID_ASV1,
  114. CODEC_ID_ASV2,
  115. CODEC_ID_FFV1,
  116. CODEC_ID_4XM,
  117. CODEC_ID_VCR1,
  118. CODEC_ID_CLJR,
  119. CODEC_ID_MDEC,
  120. CODEC_ID_ROQ,
  121. CODEC_ID_INTERPLAY_VIDEO,
  122. CODEC_ID_XAN_WC3,
  123. CODEC_ID_XAN_WC4,
  124. CODEC_ID_RPZA,
  125. CODEC_ID_CINEPAK,
  126. CODEC_ID_WS_VQA,
  127. CODEC_ID_MSRLE,
  128. CODEC_ID_MSVIDEO1,
  129. CODEC_ID_IDCIN,
  130. CODEC_ID_8BPS,
  131. CODEC_ID_SMC,
  132. CODEC_ID_FLIC,
  133. CODEC_ID_TRUEMOTION1,
  134. CODEC_ID_VMDVIDEO,
  135. CODEC_ID_MSZH,
  136. CODEC_ID_ZLIB,
  137. CODEC_ID_QTRLE,
  138. CODEC_ID_SNOW,
  139. CODEC_ID_TSCC,
  140. CODEC_ID_ULTI,
  141. CODEC_ID_QDRAW,
  142. CODEC_ID_VIXL,
  143. CODEC_ID_QPEG,
  144. CODEC_ID_PNG,
  145. CODEC_ID_PPM,
  146. CODEC_ID_PBM,
  147. CODEC_ID_PGM,
  148. CODEC_ID_PGMYUV,
  149. CODEC_ID_PAM,
  150. CODEC_ID_FFVHUFF,
  151. CODEC_ID_RV30,
  152. CODEC_ID_RV40,
  153. CODEC_ID_VC1,
  154. CODEC_ID_WMV3,
  155. CODEC_ID_LOCO,
  156. CODEC_ID_WNV1,
  157. CODEC_ID_AASC,
  158. CODEC_ID_INDEO2,
  159. CODEC_ID_FRAPS,
  160. CODEC_ID_TRUEMOTION2,
  161. CODEC_ID_BMP,
  162. CODEC_ID_CSCD,
  163. CODEC_ID_MMVIDEO,
  164. CODEC_ID_ZMBV,
  165. CODEC_ID_AVS,
  166. CODEC_ID_SMACKVIDEO,
  167. CODEC_ID_NUV,
  168. CODEC_ID_KMVC,
  169. CODEC_ID_FLASHSV,
  170. CODEC_ID_CAVS,
  171. CODEC_ID_JPEG2000,
  172. CODEC_ID_VMNC,
  173. CODEC_ID_VP5,
  174. CODEC_ID_VP6,
  175. CODEC_ID_VP6F,
  176. CODEC_ID_TARGA,
  177. CODEC_ID_DSICINVIDEO,
  178. CODEC_ID_TIERTEXSEQVIDEO,
  179. CODEC_ID_TIFF,
  180. CODEC_ID_GIF,
  181. CODEC_ID_DXA,
  182. CODEC_ID_DNXHD,
  183. CODEC_ID_THP,
  184. CODEC_ID_SGI,
  185. CODEC_ID_C93,
  186. CODEC_ID_BETHSOFTVID,
  187. CODEC_ID_PTX,
  188. CODEC_ID_TXD,
  189. CODEC_ID_VP6A,
  190. CODEC_ID_AMV,
  191. CODEC_ID_VB,
  192. CODEC_ID_PCX,
  193. CODEC_ID_SUNRAST,
  194. CODEC_ID_INDEO4,
  195. CODEC_ID_INDEO5,
  196. CODEC_ID_MIMIC,
  197. CODEC_ID_RL2,
  198. CODEC_ID_ESCAPE124,
  199. CODEC_ID_DIRAC,
  200. CODEC_ID_BFI,
  201. CODEC_ID_CMV,
  202. CODEC_ID_MOTIONPIXELS,
  203. CODEC_ID_TGV,
  204. CODEC_ID_TGQ,
  205. CODEC_ID_TQI,
  206. CODEC_ID_AURA,
  207. CODEC_ID_AURA2,
  208. CODEC_ID_V210X,
  209. CODEC_ID_TMV,
  210. CODEC_ID_V210,
  211. CODEC_ID_DPX,
  212. CODEC_ID_MAD,
  213. CODEC_ID_FRWU,
  214. CODEC_ID_FLASHSV2,
  215. CODEC_ID_CDGRAPHICS,
  216. CODEC_ID_R210,
  217. CODEC_ID_ANM,
  218. CODEC_ID_BINKVIDEO,
  219. CODEC_ID_IFF_ILBM,
  220. CODEC_ID_IFF_BYTERUN1,
  221. CODEC_ID_KGV1,
  222. CODEC_ID_YOP,
  223. CODEC_ID_VP8,
  224. CODEC_ID_PICTOR,
  225. CODEC_ID_ANSI,
  226. CODEC_ID_A64_MULTI,
  227. CODEC_ID_A64_MULTI5,
  228. CODEC_ID_R10K,
  229. CODEC_ID_MXPEG,
  230. CODEC_ID_LAGARITH,
  231. CODEC_ID_PRORES,
  232. CODEC_ID_JV,
  233. CODEC_ID_DFA,
  234. CODEC_ID_WMV3IMAGE,
  235. CODEC_ID_VC1IMAGE,
  236. CODEC_ID_UTVIDEO,
  237. CODEC_ID_BMV_VIDEO,
  238. CODEC_ID_VBLE,
  239. CODEC_ID_DXTORY,
  240. CODEC_ID_V410,
  241. CODEC_ID_XWD,
  242. CODEC_ID_CDXL,
  243. CODEC_ID_XBM,
  244. CODEC_ID_ZEROCODEC,
  245. CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
  246. CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'),
  247. CODEC_ID_EXR = MKBETAG('0','E','X','R'),
  248. CODEC_ID_AVRP = MKBETAG('A','V','R','P'),
  249. CODEC_ID_G2M = MKBETAG( 0 ,'G','2','M'),
  250. CODEC_ID_AYUV = MKBETAG('A','Y','U','V'),
  251. CODEC_ID_V308 = MKBETAG('V','3','0','8'),
  252. CODEC_ID_V408 = MKBETAG('V','4','0','8'),
  253. CODEC_ID_YUV4 = MKBETAG('Y','U','V','4'),
  254. /* various PCM "codecs" */
  255. CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
  256. CODEC_ID_PCM_S16LE = 0x10000,
  257. CODEC_ID_PCM_S16BE,
  258. CODEC_ID_PCM_U16LE,
  259. CODEC_ID_PCM_U16BE,
  260. CODEC_ID_PCM_S8,
  261. CODEC_ID_PCM_U8,
  262. CODEC_ID_PCM_MULAW,
  263. CODEC_ID_PCM_ALAW,
  264. CODEC_ID_PCM_S32LE,
  265. CODEC_ID_PCM_S32BE,
  266. CODEC_ID_PCM_U32LE,
  267. CODEC_ID_PCM_U32BE,
  268. CODEC_ID_PCM_S24LE,
  269. CODEC_ID_PCM_S24BE,
  270. CODEC_ID_PCM_U24LE,
  271. CODEC_ID_PCM_U24BE,
  272. CODEC_ID_PCM_S24DAUD,
  273. CODEC_ID_PCM_ZORK,
  274. CODEC_ID_PCM_S16LE_PLANAR,
  275. CODEC_ID_PCM_DVD,
  276. CODEC_ID_PCM_F32BE,
  277. CODEC_ID_PCM_F32LE,
  278. CODEC_ID_PCM_F64BE,
  279. CODEC_ID_PCM_F64LE,
  280. CODEC_ID_PCM_BLURAY,
  281. CODEC_ID_PCM_LXF,
  282. CODEC_ID_S302M,
  283. CODEC_ID_PCM_S8_PLANAR,
  284. /* various ADPCM codecs */
  285. CODEC_ID_ADPCM_IMA_QT = 0x11000,
  286. CODEC_ID_ADPCM_IMA_WAV,
  287. CODEC_ID_ADPCM_IMA_DK3,
  288. CODEC_ID_ADPCM_IMA_DK4,
  289. CODEC_ID_ADPCM_IMA_WS,
  290. CODEC_ID_ADPCM_IMA_SMJPEG,
  291. CODEC_ID_ADPCM_MS,
  292. CODEC_ID_ADPCM_4XM,
  293. CODEC_ID_ADPCM_XA,
  294. CODEC_ID_ADPCM_ADX,
  295. CODEC_ID_ADPCM_EA,
  296. CODEC_ID_ADPCM_G726,
  297. CODEC_ID_ADPCM_CT,
  298. CODEC_ID_ADPCM_SWF,
  299. CODEC_ID_ADPCM_YAMAHA,
  300. CODEC_ID_ADPCM_SBPRO_4,
  301. CODEC_ID_ADPCM_SBPRO_3,
  302. CODEC_ID_ADPCM_SBPRO_2,
  303. CODEC_ID_ADPCM_THP,
  304. CODEC_ID_ADPCM_IMA_AMV,
  305. CODEC_ID_ADPCM_EA_R1,
  306. CODEC_ID_ADPCM_EA_R3,
  307. CODEC_ID_ADPCM_EA_R2,
  308. CODEC_ID_ADPCM_IMA_EA_SEAD,
  309. CODEC_ID_ADPCM_IMA_EA_EACS,
  310. CODEC_ID_ADPCM_EA_XAS,
  311. CODEC_ID_ADPCM_EA_MAXIS_XA,
  312. CODEC_ID_ADPCM_IMA_ISS,
  313. CODEC_ID_ADPCM_G722,
  314. CODEC_ID_ADPCM_IMA_APC,
  315. /* AMR */
  316. CODEC_ID_AMR_NB = 0x12000,
  317. CODEC_ID_AMR_WB,
  318. /* RealAudio codecs*/
  319. CODEC_ID_RA_144 = 0x13000,
  320. CODEC_ID_RA_288,
  321. /* various DPCM codecs */
  322. CODEC_ID_ROQ_DPCM = 0x14000,
  323. CODEC_ID_INTERPLAY_DPCM,
  324. CODEC_ID_XAN_DPCM,
  325. CODEC_ID_SOL_DPCM,
  326. /* audio codecs */
  327. CODEC_ID_MP2 = 0x15000,
  328. CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
  329. CODEC_ID_AAC,
  330. CODEC_ID_AC3,
  331. CODEC_ID_DTS,
  332. CODEC_ID_VORBIS,
  333. CODEC_ID_DVAUDIO,
  334. CODEC_ID_WMAV1,
  335. CODEC_ID_WMAV2,
  336. CODEC_ID_MACE3,
  337. CODEC_ID_MACE6,
  338. CODEC_ID_VMDAUDIO,
  339. CODEC_ID_FLAC,
  340. CODEC_ID_MP3ADU,
  341. CODEC_ID_MP3ON4,
  342. CODEC_ID_SHORTEN,
  343. CODEC_ID_ALAC,
  344. CODEC_ID_WESTWOOD_SND1,
  345. CODEC_ID_GSM, ///< as in Berlin toast format
  346. CODEC_ID_QDM2,
  347. CODEC_ID_COOK,
  348. CODEC_ID_TRUESPEECH,
  349. CODEC_ID_TTA,
  350. CODEC_ID_SMACKAUDIO,
  351. CODEC_ID_QCELP,
  352. CODEC_ID_WAVPACK,
  353. CODEC_ID_DSICINAUDIO,
  354. CODEC_ID_IMC,
  355. CODEC_ID_MUSEPACK7,
  356. CODEC_ID_MLP,
  357. CODEC_ID_GSM_MS, /* as found in WAV */
  358. CODEC_ID_ATRAC3,
  359. CODEC_ID_VOXWARE,
  360. CODEC_ID_APE,
  361. CODEC_ID_NELLYMOSER,
  362. CODEC_ID_MUSEPACK8,
  363. CODEC_ID_SPEEX,
  364. CODEC_ID_WMAVOICE,
  365. CODEC_ID_WMAPRO,
  366. CODEC_ID_WMALOSSLESS,
  367. CODEC_ID_ATRAC3P,
  368. CODEC_ID_EAC3,
  369. CODEC_ID_SIPR,
  370. CODEC_ID_MP1,
  371. CODEC_ID_TWINVQ,
  372. CODEC_ID_TRUEHD,
  373. CODEC_ID_MP4ALS,
  374. CODEC_ID_ATRAC1,
  375. CODEC_ID_BINKAUDIO_RDFT,
  376. CODEC_ID_BINKAUDIO_DCT,
  377. CODEC_ID_AAC_LATM,
  378. CODEC_ID_QDMC,
  379. CODEC_ID_CELT,
  380. CODEC_ID_G723_1,
  381. CODEC_ID_G729,
  382. CODEC_ID_8SVX_EXP,
  383. CODEC_ID_8SVX_FIB,
  384. CODEC_ID_BMV_AUDIO,
  385. CODEC_ID_RALF,
  386. CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'),
  387. CODEC_ID_8SVX_RAW = MKBETAG('8','S','V','X'),
  388. CODEC_ID_SONIC = MKBETAG('S','O','N','C'),
  389. CODEC_ID_SONIC_LS = MKBETAG('S','O','N','L'),
  390. /* subtitle codecs */
  391. CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs.
  392. CODEC_ID_DVD_SUBTITLE = 0x17000,
  393. CODEC_ID_DVB_SUBTITLE,
  394. CODEC_ID_TEXT, ///< raw UTF-8 text
  395. CODEC_ID_XSUB,
  396. CODEC_ID_SSA,
  397. CODEC_ID_MOV_TEXT,
  398. CODEC_ID_HDMV_PGS_SUBTITLE,
  399. CODEC_ID_DVB_TELETEXT,
  400. CODEC_ID_SRT,
  401. CODEC_ID_MICRODVD = MKBETAG('m','D','V','D'),
  402. /* other specific kind of codecs (generally used for attachments) */
  403. CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs.
  404. CODEC_ID_TTF = 0x18000,
  405. CODEC_ID_BINTEXT = MKBETAG('B','T','X','T'),
  406. CODEC_ID_XBIN = MKBETAG('X','B','I','N'),
  407. CODEC_ID_IDF = MKBETAG( 0 ,'I','D','F'),
  408. CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it
  409. CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
  410. * stream (only used by libavformat) */
  411. CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
  412. * stream (only used by libavformat) */
  413. CODEC_ID_FFMETADATA = 0x21000, ///< Dummy codec for streams containing only metadata information.
  414. };
  415. #if FF_API_OLD_DECODE_AUDIO
  416. /* in bytes */
  417. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
  418. #endif
  419. /**
  420. * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
  421. * This is mainly needed because some optimized bitstream readers read
  422. * 32 or 64 bit at once and could read over the end.<br>
  423. * Note: If the first 23 bits of the additional bytes are not 0, then damaged
  424. * MPEG bitstreams could cause overread and segfault.
  425. */
  426. #define FF_INPUT_BUFFER_PADDING_SIZE 16
  427. /**
  428. * minimum encoding buffer size
  429. * Used to avoid some checks during header writing.
  430. */
  431. #define FF_MIN_BUFFER_SIZE 16384
  432. /**
  433. * motion estimation type.
  434. */
  435. enum Motion_Est_ID {
  436. ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed
  437. ME_FULL,
  438. ME_LOG,
  439. ME_PHODS,
  440. ME_EPZS, ///< enhanced predictive zonal search
  441. ME_X1, ///< reserved for experiments
  442. ME_HEX, ///< hexagon based search
  443. ME_UMH, ///< uneven multi-hexagon search
  444. ME_ITER, ///< iterative search
  445. ME_TESA, ///< transformed exhaustive search algorithm
  446. };
  447. enum AVDiscard{
  448. /* We leave some space between them for extensions (drop some
  449. * keyframes for intra-only or drop just some bidir frames). */
  450. AVDISCARD_NONE =-16, ///< discard nothing
  451. AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi
  452. AVDISCARD_NONREF = 8, ///< discard all non reference
  453. AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
  454. AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
  455. AVDISCARD_ALL = 48, ///< discard all
  456. };
  457. enum AVColorPrimaries{
  458. AVCOL_PRI_BT709 =1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
  459. AVCOL_PRI_UNSPECIFIED=2,
  460. AVCOL_PRI_BT470M =4,
  461. AVCOL_PRI_BT470BG =5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
  462. AVCOL_PRI_SMPTE170M =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
  463. AVCOL_PRI_SMPTE240M =7, ///< functionally identical to above
  464. AVCOL_PRI_FILM =8,
  465. AVCOL_PRI_NB , ///< Not part of ABI
  466. };
  467. enum AVColorTransferCharacteristic{
  468. AVCOL_TRC_BT709 =1, ///< also ITU-R BT1361
  469. AVCOL_TRC_UNSPECIFIED=2,
  470. AVCOL_TRC_GAMMA22 =4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
  471. AVCOL_TRC_GAMMA28 =5, ///< also ITU-R BT470BG
  472. AVCOL_TRC_SMPTE240M =7,
  473. AVCOL_TRC_NB , ///< Not part of ABI
  474. };
  475. enum AVColorSpace{
  476. AVCOL_SPC_RGB =0,
  477. AVCOL_SPC_BT709 =1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
  478. AVCOL_SPC_UNSPECIFIED=2,
  479. AVCOL_SPC_FCC =4,
  480. AVCOL_SPC_BT470BG =5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
  481. AVCOL_SPC_SMPTE170M =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
  482. AVCOL_SPC_SMPTE240M =7,
  483. AVCOL_SPC_YCGCO =8,
  484. AVCOL_SPC_NB , ///< Not part of ABI
  485. };
  486. enum AVColorRange{
  487. AVCOL_RANGE_UNSPECIFIED=0,
  488. AVCOL_RANGE_MPEG =1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
  489. AVCOL_RANGE_JPEG =2, ///< the normal 2^n-1 "JPEG" YUV ranges
  490. AVCOL_RANGE_NB , ///< Not part of ABI
  491. };
  492. /**
  493. * X X 3 4 X X are luma samples,
  494. * 1 2 1-6 are possible chroma positions
  495. * X X 5 6 X 0 is undefined/unknown position
  496. */
  497. enum AVChromaLocation{
  498. AVCHROMA_LOC_UNSPECIFIED=0,
  499. AVCHROMA_LOC_LEFT =1, ///< mpeg2/4, h264 default
  500. AVCHROMA_LOC_CENTER =2, ///< mpeg1, jpeg, h263
  501. AVCHROMA_LOC_TOPLEFT =3, ///< DV
  502. AVCHROMA_LOC_TOP =4,
  503. AVCHROMA_LOC_BOTTOMLEFT =5,
  504. AVCHROMA_LOC_BOTTOM =6,
  505. AVCHROMA_LOC_NB , ///< Not part of ABI
  506. };
  507. enum AVAudioServiceType {
  508. AV_AUDIO_SERVICE_TYPE_MAIN = 0,
  509. AV_AUDIO_SERVICE_TYPE_EFFECTS = 1,
  510. AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2,
  511. AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED = 3,
  512. AV_AUDIO_SERVICE_TYPE_DIALOGUE = 4,
  513. AV_AUDIO_SERVICE_TYPE_COMMENTARY = 5,
  514. AV_AUDIO_SERVICE_TYPE_EMERGENCY = 6,
  515. AV_AUDIO_SERVICE_TYPE_VOICE_OVER = 7,
  516. AV_AUDIO_SERVICE_TYPE_KARAOKE = 8,
  517. AV_AUDIO_SERVICE_TYPE_NB , ///< Not part of ABI
  518. };
  519. typedef struct RcOverride{
  520. int start_frame;
  521. int end_frame;
  522. int qscale; // If this is 0 then quality_factor will be used instead.
  523. float quality_factor;
  524. } RcOverride;
  525. #define FF_MAX_B_FRAMES 16
  526. /* encoding support
  527. These flags can be passed in AVCodecContext.flags before initialization.
  528. Note: Not everything is supported yet.
  529. */
  530. #define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale.
  531. #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263.
  532. #define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
  533. #define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
  534. #define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>.
  535. /**
  536. * The parent program guarantees that the input for B-frames containing
  537. * streams is not written to for at least s->max_b_frames+1 frames, if
  538. * this is not set the input will be copied.
  539. */
  540. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  541. #define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
  542. #define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
  543. #define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
  544. #define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges.
  545. #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
  546. #define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random
  547. location instead of only at frame boundaries. */
  548. #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization.
  549. #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
  550. #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
  551. #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
  552. #define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
  553. /* Fx : Flag for h263+ extra options */
  554. #define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
  555. #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
  556. #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
  557. #define CODEC_FLAG_CLOSED_GOP 0x80000000
  558. #define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
  559. #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
  560. #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
  561. #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!!
  562. #if FF_API_MPV_GLOBAL_OPTS
  563. #define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
  564. #define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
  565. #define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
  566. #define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
  567. #endif
  568. #define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
  569. #define CODEC_FLAG2_SHOW_ALL 0x00400000 ///< Show all frames before the first keyframe
  570. /* Unsupported options :
  571. * Syntax Arithmetic coding (SAC)
  572. * Reference Picture Selection
  573. * Independent Segment Decoding */
  574. /* /Fx */
  575. /* codec capabilities */
  576. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
  577. /**
  578. * Codec uses get_buffer() for allocating buffers and supports custom allocators.
  579. * If not set, it might not use get_buffer() at all or use operations that
  580. * assume the buffer was allocated by avcodec_default_get_buffer.
  581. */
  582. #define CODEC_CAP_DR1 0x0002
  583. #define CODEC_CAP_TRUNCATED 0x0008
  584. /* Codec can export data for HW decoding (XvMC). */
  585. #define CODEC_CAP_HWACCEL 0x0010
  586. /**
  587. * Encoder or decoder requires flushing with NULL input at the end in order to
  588. * give the complete and correct output.
  589. *
  590. * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
  591. * with NULL data. The user can still send NULL data to the public encode
  592. * or decode function, but libavcodec will not pass it along to the codec
  593. * unless this flag is set.
  594. *
  595. * Decoders:
  596. * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
  597. * avpkt->size=0 at the end to get the delayed data until the decoder no longer
  598. * returns frames.
  599. *
  600. * Encoders:
  601. * The encoder needs to be fed with NULL data at the end of encoding until the
  602. * encoder no longer returns data.
  603. *
  604. * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
  605. * flag also means that the encoder must set the pts and duration for
  606. * each output packet. If this flag is not set, the pts and duration will
  607. * be determined by libavcodec from the input frame.
  608. */
  609. #define CODEC_CAP_DELAY 0x0020
  610. /**
  611. * Codec can be fed a final frame with a smaller size.
  612. * This can be used to prevent truncation of the last audio samples.
  613. */
  614. #define CODEC_CAP_SMALL_LAST_FRAME 0x0040
  615. /**
  616. * Codec can export data for HW decoding (VDPAU).
  617. */
  618. #define CODEC_CAP_HWACCEL_VDPAU 0x0080
  619. /**
  620. * Codec can output multiple frames per AVPacket
  621. * Normally demuxers return one frame at a time, demuxers which do not do
  622. * are connected to a parser to split what they return into proper frames.
  623. * This flag is reserved to the very rare category of codecs which have a
  624. * bitstream that cannot be split into frames without timeconsuming
  625. * operations like full decoding. Demuxers carring such bitstreams thus
  626. * may return multiple frames in a packet. This has many disadvantages like
  627. * prohibiting stream copy in many cases thus it should only be considered
  628. * as a last resort.
  629. */
  630. #define CODEC_CAP_SUBFRAMES 0x0100
  631. /**
  632. * Codec is experimental and is thus avoided in favor of non experimental
  633. * encoders
  634. */
  635. #define CODEC_CAP_EXPERIMENTAL 0x0200
  636. /**
  637. * Codec should fill in channel configuration and samplerate instead of container
  638. */
  639. #define CODEC_CAP_CHANNEL_CONF 0x0400
  640. /**
  641. * Codec is able to deal with negative linesizes
  642. */
  643. #define CODEC_CAP_NEG_LINESIZES 0x0800
  644. /**
  645. * Codec supports frame-level multithreading.
  646. */
  647. #define CODEC_CAP_FRAME_THREADS 0x1000
  648. /**
  649. * Codec supports slice-based (or partition-based) multithreading.
  650. */
  651. #define CODEC_CAP_SLICE_THREADS 0x2000
  652. /**
  653. * Codec supports changed parameters at any point.
  654. */
  655. #define CODEC_CAP_PARAM_CHANGE 0x4000
  656. /**
  657. * Codec supports avctx->thread_count == 0 (auto).
  658. */
  659. #define CODEC_CAP_AUTO_THREADS 0x8000
  660. /**
  661. * Audio encoder supports receiving a different number of samples in each call.
  662. */
  663. #define CODEC_CAP_VARIABLE_FRAME_SIZE 0x10000
  664. /**
  665. * Codec is lossless.
  666. */
  667. #define CODEC_CAP_LOSSLESS 0x80000000
  668. //The following defines may change, don't expect compatibility if you use them.
  669. #define MB_TYPE_INTRA4x4 0x0001
  670. #define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
  671. #define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific
  672. #define MB_TYPE_16x16 0x0008
  673. #define MB_TYPE_16x8 0x0010
  674. #define MB_TYPE_8x16 0x0020
  675. #define MB_TYPE_8x8 0x0040
  676. #define MB_TYPE_INTERLACED 0x0080
  677. #define MB_TYPE_DIRECT2 0x0100 //FIXME
  678. #define MB_TYPE_ACPRED 0x0200
  679. #define MB_TYPE_GMC 0x0400
  680. #define MB_TYPE_SKIP 0x0800
  681. #define MB_TYPE_P0L0 0x1000
  682. #define MB_TYPE_P1L0 0x2000
  683. #define MB_TYPE_P0L1 0x4000
  684. #define MB_TYPE_P1L1 0x8000
  685. #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
  686. #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
  687. #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
  688. #define MB_TYPE_QUANT 0x00010000
  689. #define MB_TYPE_CBP 0x00020000
  690. //Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
  691. /**
  692. * Pan Scan area.
  693. * This specifies the area which should be displayed.
  694. * Note there may be multiple such areas for one frame.
  695. */
  696. typedef struct AVPanScan{
  697. /**
  698. * id
  699. * - encoding: Set by user.
  700. * - decoding: Set by libavcodec.
  701. */
  702. int id;
  703. /**
  704. * width and height in 1/16 pel
  705. * - encoding: Set by user.
  706. * - decoding: Set by libavcodec.
  707. */
  708. int width;
  709. int height;
  710. /**
  711. * position of the top left corner in 1/16 pel for up to 3 fields/frames
  712. * - encoding: Set by user.
  713. * - decoding: Set by libavcodec.
  714. */
  715. int16_t position[3][2];
  716. }AVPanScan;
  717. #define FF_QSCALE_TYPE_MPEG1 0
  718. #define FF_QSCALE_TYPE_MPEG2 1
  719. #define FF_QSCALE_TYPE_H264 2
  720. #define FF_QSCALE_TYPE_VP56 3
  721. #define FF_BUFFER_TYPE_INTERNAL 1
  722. #define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user)
  723. #define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
  724. #define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
  725. #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore).
  726. #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
  727. #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
  728. #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
  729. enum AVPacketSideDataType {
  730. AV_PKT_DATA_PALETTE,
  731. AV_PKT_DATA_NEW_EXTRADATA,
  732. AV_PKT_DATA_PARAM_CHANGE,
  733. AV_PKT_DATA_H263_MB_INFO,
  734. };
  735. typedef struct AVPacket {
  736. /**
  737. * Presentation timestamp in AVStream->time_base units; the time at which
  738. * the decompressed packet will be presented to the user.
  739. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  740. * pts MUST be larger or equal to dts as presentation cannot happen before
  741. * decompression, unless one wants to view hex dumps. Some formats misuse
  742. * the terms dts and pts/cts to mean something different. Such timestamps
  743. * must be converted to true pts/dts before they are stored in AVPacket.
  744. */
  745. int64_t pts;
  746. /**
  747. * Decompression timestamp in AVStream->time_base units; the time at which
  748. * the packet is decompressed.
  749. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  750. */
  751. int64_t dts;
  752. uint8_t *data;
  753. int size;
  754. int stream_index;
  755. /**
  756. * A combination of AV_PKT_FLAG values
  757. */
  758. int flags;
  759. /**
  760. * Additional packet data that can be provided by the container.
  761. * Packet can contain several types of side information.
  762. */
  763. struct {
  764. uint8_t *data;
  765. int size;
  766. enum AVPacketSideDataType type;
  767. } *side_data;
  768. int side_data_elems;
  769. /**
  770. * Duration of this packet in AVStream->time_base units, 0 if unknown.
  771. * Equals next_pts - this_pts in presentation order.
  772. */
  773. int duration;
  774. void (*destruct)(struct AVPacket *);
  775. void *priv;
  776. int64_t pos; ///< byte position in stream, -1 if unknown
  777. /**
  778. * Time difference in AVStream->time_base units from the pts of this
  779. * packet to the point at which the output from the decoder has converged
  780. * independent from the availability of previous frames. That is, the
  781. * frames are virtually identical no matter if decoding started from
  782. * the very first frame or from this keyframe.
  783. * Is AV_NOPTS_VALUE if unknown.
  784. * This field is not the display duration of the current packet.
  785. * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
  786. * set.
  787. *
  788. * The purpose of this field is to allow seeking in streams that have no
  789. * keyframes in the conventional sense. It corresponds to the
  790. * recovery point SEI in H.264 and match_time_delta in NUT. It is also
  791. * essential for some types of subtitle streams to ensure that all
  792. * subtitles are correctly displayed after seeking.
  793. */
  794. int64_t convergence_duration;
  795. } AVPacket;
  796. #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
  797. #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
  798. /**
  799. * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
  800. * u32le param_flags
  801. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
  802. * s32le channel_count
  803. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
  804. * u64le channel_layout
  805. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
  806. * s32le sample_rate
  807. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
  808. * s32le width
  809. * s32le height
  810. */
  811. /**
  812. * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
  813. * structures with info about macroblocks relevant to splitting the
  814. * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
  815. * That is, it does not necessarily contain info about all macroblocks,
  816. * as long as the distance between macroblocks in the info is smaller
  817. * than the target payload size.
  818. * Each MB info structure is 12 bytes, and is laid out as follows:
  819. * u32le bit offset from the start of the packet
  820. * u8 current quantizer at the start of the macroblock
  821. * u8 GOB number
  822. * u16le macroblock address within the GOB
  823. * u8 horizontal MV predictor
  824. * u8 vertical MV predictor
  825. * u8 horizontal MV predictor for block number 3
  826. * u8 vertical MV predictor for block number 3
  827. */
  828. enum AVSideDataParamChangeFlags {
  829. AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001,
  830. AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
  831. AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004,
  832. AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
  833. };
  834. /**
  835. * Audio Video Frame.
  836. * New fields can be added to the end of AVFRAME with minor version
  837. * bumps. Similarly fields that are marked as to be only accessed by
  838. * av_opt_ptr() can be reordered. This allows 2 forks to add fields
  839. * without breaking compatibility with each other.
  840. * Removal, reordering and changes in the remaining cases require
  841. * a major version bump.
  842. * sizeof(AVFrame) must not be used outside libavcodec.
  843. */
  844. typedef struct AVFrame {
  845. #define AV_NUM_DATA_POINTERS 8
  846. /**
  847. * pointer to the picture/channel planes.
  848. * This might be different from the first allocated byte
  849. * - encoding: Set by user
  850. * - decoding: set by AVCodecContext.get_buffer()
  851. */
  852. uint8_t *data[AV_NUM_DATA_POINTERS];
  853. /**
  854. * Size, in bytes, of the data for each picture/channel plane.
  855. *
  856. * For audio, only linesize[0] may be set. For planar audio, each channel
  857. * plane must be the same size.
  858. *
  859. * - encoding: Set by user
  860. * - decoding: set by AVCodecContext.get_buffer()
  861. */
  862. int linesize[AV_NUM_DATA_POINTERS];
  863. /**
  864. * pointers to the data planes/channels.
  865. *
  866. * For video, this should simply point to data[].
  867. *
  868. * For planar audio, each channel has a separate data pointer, and
  869. * linesize[0] contains the size of each channel buffer.
  870. * For packed audio, there is just one data pointer, and linesize[0]
  871. * contains the total size of the buffer for all channels.
  872. *
  873. * Note: Both data and extended_data will always be set by get_buffer(),
  874. * but for planar audio with more channels that can fit in data,
  875. * extended_data must be used by the decoder in order to access all
  876. * channels.
  877. *
  878. * encoding: unused
  879. * decoding: set by AVCodecContext.get_buffer()
  880. */
  881. uint8_t **extended_data;
  882. /**
  883. * width and height of the video frame
  884. * - encoding: unused
  885. * - decoding: Read by user.
  886. */
  887. int width, height;
  888. /**
  889. * number of audio samples (per channel) described by this frame
  890. * - encoding: Set by user
  891. * - decoding: Set by libavcodec
  892. */
  893. int nb_samples;
  894. /**
  895. * format of the frame, -1 if unknown or unset
  896. * Values correspond to enum PixelFormat for video frames,
  897. * enum AVSampleFormat for audio)
  898. * - encoding: unused
  899. * - decoding: Read by user.
  900. */
  901. int format;
  902. /**
  903. * 1 -> keyframe, 0-> not
  904. * - encoding: Set by libavcodec.
  905. * - decoding: Set by libavcodec.
  906. */
  907. int key_frame;
  908. /**
  909. * Picture type of the frame, see ?_TYPE below.
  910. * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
  911. * - decoding: Set by libavcodec.
  912. */
  913. enum AVPictureType pict_type;
  914. /**
  915. * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.
  916. * This isn't used by libavcodec unless the default get/release_buffer() is used.
  917. * - encoding:
  918. * - decoding:
  919. */
  920. uint8_t *base[AV_NUM_DATA_POINTERS];
  921. /**
  922. * sample aspect ratio for the video frame, 0/1 if unknown\unspecified
  923. * - encoding: unused
  924. * - decoding: Read by user.
  925. */
  926. AVRational sample_aspect_ratio;
  927. /**
  928. * presentation timestamp in time_base units (time when frame should be shown to user)
  929. * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.
  930. * - encoding: MUST be set by user.
  931. * - decoding: Set by libavcodec.
  932. */
  933. int64_t pts;
  934. /**
  935. * reordered pts from the last AVPacket that has been input into the decoder
  936. * - encoding: unused
  937. * - decoding: Read by user.
  938. */
  939. int64_t pkt_pts;
  940. /**
  941. * dts from the last AVPacket that has been input into the decoder
  942. * - encoding: unused
  943. * - decoding: Read by user.
  944. */
  945. int64_t pkt_dts;
  946. /**
  947. * picture number in bitstream order
  948. * - encoding: set by
  949. * - decoding: Set by libavcodec.
  950. */
  951. int coded_picture_number;
  952. /**
  953. * picture number in display order
  954. * - encoding: set by
  955. * - decoding: Set by libavcodec.
  956. */
  957. int display_picture_number;
  958. /**
  959. * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
  960. * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
  961. * - decoding: Set by libavcodec.
  962. */
  963. int quality;
  964. /**
  965. * is this picture used as reference
  966. * The values for this are the same as the MpegEncContext.picture_structure
  967. * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
  968. * Set to 4 for delayed, non-reference frames.
  969. * - encoding: unused
  970. * - decoding: Set by libavcodec. (before get_buffer() call)).
  971. */
  972. int reference;
  973. /**
  974. * QP table
  975. * - encoding: unused
  976. * - decoding: Set by libavcodec.
  977. */
  978. int8_t *qscale_table;
  979. /**
  980. * QP store stride
  981. * - encoding: unused
  982. * - decoding: Set by libavcodec.
  983. */
  984. int qstride;
  985. /**
  986. *
  987. */
  988. int qscale_type;
  989. /**
  990. * mbskip_table[mb]>=1 if MB didn't change
  991. * stride= mb_width = (width+15)>>4
  992. * - encoding: unused
  993. * - decoding: Set by libavcodec.
  994. */
  995. uint8_t *mbskip_table;
  996. /**
  997. * motion vector table
  998. * @code
  999. * example:
  1000. * int mv_sample_log2= 4 - motion_subsample_log2;
  1001. * int mb_width= (width+15)>>4;
  1002. * int mv_stride= (mb_width << mv_sample_log2) + 1;
  1003. * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];
  1004. * @endcode
  1005. * - encoding: Set by user.
  1006. * - decoding: Set by libavcodec.
  1007. */
  1008. int16_t (*motion_val[2])[2];
  1009. /**
  1010. * macroblock type table
  1011. * mb_type_base + mb_width + 2
  1012. * - encoding: Set by user.
  1013. * - decoding: Set by libavcodec.
  1014. */
  1015. uint32_t *mb_type;
  1016. /**
  1017. * DCT coefficients
  1018. * - encoding: unused
  1019. * - decoding: Set by libavcodec.
  1020. */
  1021. short *dct_coeff;
  1022. /**
  1023. * motion reference frame index
  1024. * the order in which these are stored can depend on the codec.
  1025. * - encoding: Set by user.
  1026. * - decoding: Set by libavcodec.
  1027. */
  1028. int8_t *ref_index[2];
  1029. /**
  1030. * for some private data of the user
  1031. * - encoding: unused
  1032. * - decoding: Set by user.
  1033. */
  1034. void *opaque;
  1035. /**
  1036. * error
  1037. * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.
  1038. * - decoding: unused
  1039. */
  1040. uint64_t error[AV_NUM_DATA_POINTERS];
  1041. /**
  1042. * type of the buffer (to keep track of who has to deallocate data[*])
  1043. * - encoding: Set by the one who allocates it.
  1044. * - decoding: Set by the one who allocates it.
  1045. * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.
  1046. */
  1047. int type;
  1048. /**
  1049. * When decoding, this signals how much the picture must be delayed.
  1050. * extra_delay = repeat_pict / (2*fps)
  1051. * - encoding: unused
  1052. * - decoding: Set by libavcodec.
  1053. */
  1054. int repeat_pict;
  1055. /**
  1056. * The content of the picture is interlaced.
  1057. * - encoding: Set by user.
  1058. * - decoding: Set by libavcodec. (default 0)
  1059. */
  1060. int interlaced_frame;
  1061. /**
  1062. * If the content is interlaced, is top field displayed first.
  1063. * - encoding: Set by user.
  1064. * - decoding: Set by libavcodec.
  1065. */
  1066. int top_field_first;
  1067. /**
  1068. * Tell user application that palette has changed from previous frame.
  1069. * - encoding: ??? (no palette-enabled encoder yet)
  1070. * - decoding: Set by libavcodec. (default 0).
  1071. */
  1072. int palette_has_changed;
  1073. /**
  1074. * codec suggestion on buffer type if != 0
  1075. * - encoding: unused
  1076. * - decoding: Set by libavcodec. (before get_buffer() call)).
  1077. */
  1078. int buffer_hints;
  1079. /**
  1080. * Pan scan.
  1081. * - encoding: Set by user.
  1082. * - decoding: Set by libavcodec.
  1083. */
  1084. AVPanScan *pan_scan;
  1085. /**
  1086. * reordered opaque 64bit (generally an integer or a double precision float
  1087. * PTS but can be anything).
  1088. * The user sets AVCodecContext.reordered_opaque to represent the input at
  1089. * that time,
  1090. * the decoder reorders values as needed and sets AVFrame.reordered_opaque
  1091. * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
  1092. * @deprecated in favor of pkt_pts
  1093. * - encoding: unused
  1094. * - decoding: Read by user.
  1095. */
  1096. int64_t reordered_opaque;
  1097. /**
  1098. * hardware accelerator private data (FFmpeg-allocated)
  1099. * - encoding: unused
  1100. * - decoding: Set by libavcodec
  1101. */
  1102. void *hwaccel_picture_private;
  1103. /**
  1104. * the AVCodecContext which ff_thread_get_buffer() was last called on
  1105. * - encoding: Set by libavcodec.
  1106. * - decoding: Set by libavcodec.
  1107. */
  1108. struct AVCodecContext *owner;
  1109. /**
  1110. * used by multithreading to store frame-specific info
  1111. * - encoding: Set by libavcodec.
  1112. * - decoding: Set by libavcodec.
  1113. */
  1114. void *thread_opaque;
  1115. /**
  1116. * log2 of the size of the block which a single vector in motion_val represents:
  1117. * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
  1118. * - encoding: unused
  1119. * - decoding: Set by libavcodec.
  1120. */
  1121. uint8_t motion_subsample_log2;
  1122. /**
  1123. * frame timestamp estimated using various heuristics, in stream time base
  1124. * Code outside libavcodec should access this field using:
  1125. * av_opt_ptr(avcodec_get_frame_class(), frame, "best_effort_timestamp");
  1126. * - encoding: unused
  1127. * - decoding: set by libavcodec, read by user.
  1128. */
  1129. int64_t best_effort_timestamp;
  1130. /**
  1131. * reordered pos from the last AVPacket that has been input into the decoder
  1132. * Code outside libavcodec should access this field using:
  1133. * av_opt_ptr(avcodec_get_frame_class(), frame, "pkt_pos");
  1134. * - encoding: unused
  1135. * - decoding: Read by user.
  1136. */
  1137. int64_t pkt_pos;
  1138. } AVFrame;
  1139. struct AVCodecInternal;
  1140. enum AVFieldOrder {
  1141. AV_FIELD_UNKNOWN,
  1142. AV_FIELD_PROGRESSIVE,
  1143. AV_FIELD_TT, //< Top coded_first, top displayed first
  1144. AV_FIELD_BB, //< Bottom coded first, bottom displayed first
  1145. AV_FIELD_TB, //< Top coded first, bottom displayed first
  1146. AV_FIELD_BT, //< Bottom coded first, top displayed first
  1147. };
  1148. /**
  1149. * main external API structure.
  1150. * New fields can be added to the end with minor version bumps.
  1151. * Removal, reordering and changes to existing fields require a major
  1152. * version bump.
  1153. * Please use AVOptions (av_opt* / av_set/get*()) to access these fields from user
  1154. * applications.
  1155. * sizeof(AVCodecContext) must not be used outside libav*.
  1156. */
  1157. typedef struct AVCodecContext {
  1158. /**
  1159. * information on struct for av_log
  1160. * - set by avcodec_alloc_context3
  1161. */
  1162. const AVClass *av_class;
  1163. int log_level_offset;
  1164. enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
  1165. struct AVCodec *codec;
  1166. char codec_name[32];
  1167. enum CodecID codec_id; /* see CODEC_ID_xxx */
  1168. /**
  1169. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  1170. * This is used to work around some encoder bugs.
  1171. * A demuxer should set this to what is stored in the field used to identify the codec.
  1172. * If there are multiple such fields in a container then the demuxer should choose the one
  1173. * which maximizes the information about the used codec.
  1174. * If the codec tag field in a container is larger than 32 bits then the demuxer should
  1175. * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
  1176. * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
  1177. * first.
  1178. * - encoding: Set by user, if not then the default based on codec_id will be used.
  1179. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  1180. */
  1181. unsigned int codec_tag;
  1182. /**
  1183. * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  1184. * This is used to work around some encoder bugs.
  1185. * - encoding: unused
  1186. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  1187. */
  1188. unsigned int stream_codec_tag;
  1189. #if FF_API_SUB_ID
  1190. /**
  1191. * @deprecated this field is unused
  1192. */
  1193. attribute_deprecated int sub_id;
  1194. #endif
  1195. void *priv_data;
  1196. /**
  1197. * Private context used for internal data.
  1198. *
  1199. * Unlike priv_data, this is not codec-specific. It is used in general
  1200. * libavcodec functions.
  1201. */
  1202. struct AVCodecInternal *internal;
  1203. /**
  1204. * Private data of the user, can be used to carry app specific stuff.
  1205. * - encoding: Set by user.
  1206. * - decoding: Set by user.
  1207. */
  1208. void *opaque;
  1209. /**
  1210. * the average bitrate
  1211. * - encoding: Set by user; unused for constant quantizer encoding.
  1212. * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
  1213. */
  1214. int bit_rate;
  1215. /**
  1216. * number of bits the bitstream is allowed to diverge from the reference.
  1217. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  1218. * - encoding: Set by user; unused for constant quantizer encoding.
  1219. * - decoding: unused
  1220. */
  1221. int bit_rate_tolerance;
  1222. /**
  1223. * Global quality for codecs which cannot change it per frame.
  1224. * This should be proportional to MPEG-1/2/4 qscale.
  1225. * - encoding: Set by user.
  1226. * - decoding: unused
  1227. */
  1228. int global_quality;
  1229. /**
  1230. * - encoding: Set by user.
  1231. * - decoding: unused
  1232. */
  1233. int compression_level;
  1234. #define FF_COMPRESSION_DEFAULT -1
  1235. /**
  1236. * CODEC_FLAG_*.
  1237. * - encoding: Set by user.
  1238. * - decoding: Set by user.
  1239. */
  1240. int flags;
  1241. /**
  1242. * CODEC_FLAG2_*
  1243. * - encoding: Set by user.
  1244. * - decoding: Set by user.
  1245. */
  1246. int flags2;
  1247. /**
  1248. * some codecs need / can use extradata like Huffman tables.
  1249. * mjpeg: Huffman tables
  1250. * rv10: additional flags
  1251. * mpeg4: global headers (they can be in the bitstream or here)
  1252. * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
  1253. * than extradata_size to avoid prolems if it is read with the bitstream reader.
  1254. * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
  1255. * - encoding: Set/allocated/freed by libavcodec.
  1256. * - decoding: Set/allocated/freed by user.
  1257. */
  1258. uint8_t *extradata;
  1259. int extradata_size;
  1260. /**
  1261. * This is the fundamental unit of time (in seconds) in terms
  1262. * of which frame timestamps are represented. For fixed-fps content,
  1263. * timebase should be 1/framerate and timestamp increments should be
  1264. * identically 1.
  1265. * - encoding: MUST be set by user.
  1266. * - decoding: Set by libavcodec.
  1267. */
  1268. AVRational time_base;
  1269. /**
  1270. * For some codecs, the time base is closer to the field rate than the frame rate.
  1271. * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
  1272. * if no telecine is used ...
  1273. *
  1274. * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
  1275. */
  1276. int ticks_per_frame;
  1277. /**
  1278. * Encoding: Number of frames delay there will be from the encoder input to
  1279. * the decoder output. (we assume the decoder matches the spec)
  1280. * Decoding: Number of frames delay in addition to what a standard decoder
  1281. * as specified in the spec would produce.
  1282. *
  1283. * Video:
  1284. * Number of frames the decoded output will be delayed relative to the
  1285. * encoded input.
  1286. *
  1287. * Audio:
  1288. * Number of "priming" samples added to the beginning of the stream
  1289. * during encoding. The decoded output will be delayed by this many
  1290. * samples relative to the input to the encoder. Note that this field is
  1291. * purely informational and does not directly affect the pts output by
  1292. * the encoder, which should always be based on the actual presentation
  1293. * time, including any delay.
  1294. *
  1295. * - encoding: Set by libavcodec.
  1296. * - decoding: Set by libavcodec.
  1297. */
  1298. int delay;
  1299. /* video only */
  1300. /**
  1301. * picture width / height.
  1302. * - encoding: MUST be set by user.
  1303. * - decoding: Set by libavcodec.
  1304. * Note: For compatibility it is possible to set this instead of
  1305. * coded_width/height before decoding.
  1306. */
  1307. int width, height;
  1308. /**
  1309. * Bitstream width / height, may be different from width/height if lowres enabled.
  1310. * - encoding: unused
  1311. * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
  1312. */
  1313. int coded_width, coded_height;
  1314. #define FF_ASPECT_EXTENDED 15
  1315. /**
  1316. * the number of pictures in a group of pictures, or 0 for intra_only
  1317. * - encoding: Set by user.
  1318. * - decoding: unused
  1319. */
  1320. int gop_size;
  1321. /**
  1322. * Pixel format, see PIX_FMT_xxx.
  1323. * May be set by the demuxer if known from headers.
  1324. * May be overriden by the decoder if it knows better.
  1325. * - encoding: Set by user.
  1326. * - decoding: Set by user if known, overridden by libavcodec if known
  1327. */
  1328. enum PixelFormat pix_fmt;
  1329. /**
  1330. * Motion estimation algorithm used for video coding.
  1331. * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
  1332. * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
  1333. * - encoding: MUST be set by user.
  1334. * - decoding: unused
  1335. */
  1336. int me_method;
  1337. /**
  1338. * If non NULL, 'draw_horiz_band' is called by the libavcodec
  1339. * decoder to draw a horizontal band. It improves cache usage. Not
  1340. * all codecs can do that. You must check the codec capabilities
  1341. * beforehand.
  1342. * When multithreading is used, it may be called from multiple threads
  1343. * at the same time; threads might draw different parts of the same AVFrame,
  1344. * or multiple AVFrames, and there is no guarantee that slices will be drawn
  1345. * in order.
  1346. * The function is also used by hardware acceleration APIs.
  1347. * It is called at least once during frame decoding to pass
  1348. * the data needed for hardware render.
  1349. * In that mode instead of pixel data, AVFrame points to
  1350. * a structure specific to the acceleration API. The application
  1351. * reads the structure and can change some fields to indicate progress
  1352. * or mark state.
  1353. * - encoding: unused
  1354. * - decoding: Set by user.
  1355. * @param height the height of the slice
  1356. * @param y the y position of the slice
  1357. * @param type 1->top field, 2->bottom field, 3->frame
  1358. * @param offset offset into the AVFrame.data from which the slice should be read
  1359. */
  1360. void (*draw_horiz_band)(struct AVCodecContext *s,
  1361. const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
  1362. int y, int type, int height);
  1363. /**
  1364. * callback to negotiate the pixelFormat
  1365. * @param fmt is the list of formats which are supported by the codec,
  1366. * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
  1367. * The first is always the native one.
  1368. * @return the chosen format
  1369. * - encoding: unused
  1370. * - decoding: Set by user, if not set the native format will be chosen.
  1371. */
  1372. enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
  1373. /**
  1374. * maximum number of B-frames between non-B-frames
  1375. * Note: The output will be delayed by max_b_frames+1 relative to the input.
  1376. * - encoding: Set by user.
  1377. * - decoding: unused
  1378. */
  1379. int max_b_frames;
  1380. /**
  1381. * qscale factor between IP and B-frames
  1382. * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
  1383. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  1384. * - encoding: Set by user.
  1385. * - decoding: unused
  1386. */
  1387. float b_quant_factor;
  1388. /** obsolete FIXME remove */
  1389. int rc_strategy;
  1390. #define FF_RC_STRATEGY_XVID 1
  1391. int b_frame_strategy;
  1392. #if FF_API_MPV_GLOBAL_OPTS
  1393. /**
  1394. * luma single coefficient elimination threshold
  1395. * - encoding: Set by user.
  1396. * - decoding: unused
  1397. */
  1398. attribute_deprecated int luma_elim_threshold;
  1399. /**
  1400. * chroma single coeff elimination threshold
  1401. * - encoding: Set by user.
  1402. * - decoding: unused
  1403. */
  1404. attribute_deprecated int chroma_elim_threshold;
  1405. #endif
  1406. /**
  1407. * qscale offset between IP and B-frames
  1408. * - encoding: Set by user.
  1409. * - decoding: unused
  1410. */
  1411. float b_quant_offset;
  1412. /**
  1413. * Size of the frame reordering buffer in the decoder.
  1414. * For MPEG-2 it is 1 IPB or 0 low delay IP.
  1415. * - encoding: Set by libavcodec.
  1416. * - decoding: Set by libavcodec.
  1417. */
  1418. int has_b_frames;
  1419. /**
  1420. * 0-> h263 quant 1-> mpeg quant
  1421. * - encoding: Set by user.
  1422. * - decoding: unused
  1423. */
  1424. int mpeg_quant;
  1425. /**
  1426. * qscale factor between P and I-frames
  1427. * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
  1428. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  1429. * - encoding: Set by user.
  1430. * - decoding: unused
  1431. */
  1432. float i_quant_factor;
  1433. /**
  1434. * qscale offset between P and I-frames
  1435. * - encoding: Set by user.
  1436. * - decoding: unused
  1437. */
  1438. float i_quant_offset;
  1439. /**
  1440. * luminance masking (0-> disabled)
  1441. * - encoding: Set by user.
  1442. * - decoding: unused
  1443. */
  1444. float lumi_masking;
  1445. /**
  1446. * temporary complexity masking (0-> disabled)
  1447. * - encoding: Set by user.
  1448. * - decoding: unused
  1449. */
  1450. float temporal_cplx_masking;
  1451. /**
  1452. * spatial complexity masking (0-> disabled)
  1453. * - encoding: Set by user.
  1454. * - decoding: unused
  1455. */
  1456. float spatial_cplx_masking;
  1457. /**
  1458. * p block masking (0-> disabled)
  1459. * - encoding: Set by user.
  1460. * - decoding: unused
  1461. */
  1462. float p_masking;
  1463. /**
  1464. * darkness masking (0-> disabled)
  1465. * - encoding: Set by user.
  1466. * - decoding: unused
  1467. */
  1468. float dark_masking;
  1469. /**
  1470. * slice count
  1471. * - encoding: Set by libavcodec.
  1472. * - decoding: Set by user (or 0).
  1473. */
  1474. int slice_count;
  1475. /**
  1476. * prediction method (needed for huffyuv)
  1477. * - encoding: Set by user.
  1478. * - decoding: unused
  1479. */
  1480. int prediction_method;
  1481. #define FF_PRED_LEFT 0
  1482. #define FF_PRED_PLANE 1
  1483. #define FF_PRED_MEDIAN 2
  1484. /**
  1485. * slice offsets in the frame in bytes
  1486. * - encoding: Set/allocated by libavcodec.
  1487. * - decoding: Set/allocated by user (or NULL).
  1488. */
  1489. int *slice_offset;
  1490. /**
  1491. * sample aspect ratio (0 if unknown)
  1492. * That is the width of a pixel divided by the height of the pixel.
  1493. * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
  1494. * - encoding: Set by user.
  1495. * - decoding: Set by libavcodec.
  1496. */
  1497. AVRational sample_aspect_ratio;
  1498. /**
  1499. * motion estimation comparison function
  1500. * - encoding: Set by user.
  1501. * - decoding: unused
  1502. */
  1503. int me_cmp;
  1504. /**
  1505. * subpixel motion estimation comparison function
  1506. * - encoding: Set by user.
  1507. * - decoding: unused
  1508. */
  1509. int me_sub_cmp;
  1510. /**
  1511. * macroblock comparison function (not supported yet)
  1512. * - encoding: Set by user.
  1513. * - decoding: unused
  1514. */
  1515. int mb_cmp;
  1516. /**
  1517. * interlaced DCT comparison function
  1518. * - encoding: Set by user.
  1519. * - decoding: unused
  1520. */
  1521. int ildct_cmp;
  1522. #define FF_CMP_SAD 0
  1523. #define FF_CMP_SSE 1
  1524. #define FF_CMP_SATD 2
  1525. #define FF_CMP_DCT 3
  1526. #define FF_CMP_PSNR 4
  1527. #define FF_CMP_BIT 5
  1528. #define FF_CMP_RD 6
  1529. #define FF_CMP_ZERO 7
  1530. #define FF_CMP_VSAD 8
  1531. #define FF_CMP_VSSE 9
  1532. #define FF_CMP_NSSE 10
  1533. #define FF_CMP_W53 11
  1534. #define FF_CMP_W97 12
  1535. #define FF_CMP_DCTMAX 13
  1536. #define FF_CMP_DCT264 14
  1537. #define FF_CMP_CHROMA 256
  1538. /**
  1539. * ME diamond size & shape
  1540. * - encoding: Set by user.
  1541. * - decoding: unused
  1542. */
  1543. int dia_size;
  1544. /**
  1545. * amount of previous MV predictors (2a+1 x 2a+1 square)
  1546. * - encoding: Set by user.
  1547. * - decoding: unused
  1548. */
  1549. int last_predictor_count;
  1550. /**
  1551. * prepass for motion estimation
  1552. * - encoding: Set by user.
  1553. * - decoding: unused
  1554. */
  1555. int pre_me;
  1556. /**
  1557. * motion estimation prepass comparison function
  1558. * - encoding: Set by user.
  1559. * - decoding: unused
  1560. */
  1561. int me_pre_cmp;
  1562. /**
  1563. * ME prepass diamond size & shape
  1564. * - encoding: Set by user.
  1565. * - decoding: unused
  1566. */
  1567. int pre_dia_size;
  1568. /**
  1569. * subpel ME quality
  1570. * - encoding: Set by user.
  1571. * - decoding: unused
  1572. */
  1573. int me_subpel_quality;
  1574. /**
  1575. * DTG active format information (additional aspect ratio
  1576. * information only used in DVB MPEG-2 transport streams)
  1577. * 0 if not set.
  1578. *
  1579. * - encoding: unused
  1580. * - decoding: Set by decoder.
  1581. */
  1582. int dtg_active_format;
  1583. #define FF_DTG_AFD_SAME 8
  1584. #define FF_DTG_AFD_4_3 9
  1585. #define FF_DTG_AFD_16_9 10
  1586. #define FF_DTG_AFD_14_9 11
  1587. #define FF_DTG_AFD_4_3_SP_14_9 13
  1588. #define FF_DTG_AFD_16_9_SP_14_9 14
  1589. #define FF_DTG_AFD_SP_4_3 15
  1590. /**
  1591. * maximum motion estimation search range in subpel units
  1592. * If 0 then no limit.
  1593. *
  1594. * - encoding: Set by user.
  1595. * - decoding: unused
  1596. */
  1597. int me_range;
  1598. /**
  1599. * intra quantizer bias
  1600. * - encoding: Set by user.
  1601. * - decoding: unused
  1602. */
  1603. int intra_quant_bias;
  1604. #define FF_DEFAULT_QUANT_BIAS 999999
  1605. /**
  1606. * inter quantizer bias
  1607. * - encoding: Set by user.
  1608. * - decoding: unused
  1609. */
  1610. int inter_quant_bias;
  1611. #if FF_API_COLOR_TABLE_ID
  1612. /**
  1613. * color table ID
  1614. * - encoding: unused
  1615. * - decoding: Which clrtable should be used for 8bit RGB images.
  1616. * Tables have to be stored somewhere. FIXME
  1617. */
  1618. attribute_deprecated int color_table_id;
  1619. #endif
  1620. /**
  1621. * slice flags
  1622. * - encoding: unused
  1623. * - decoding: Set by user.
  1624. */
  1625. int slice_flags;
  1626. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  1627. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
  1628. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  1629. /**
  1630. * XVideo Motion Acceleration
  1631. * - encoding: forbidden
  1632. * - decoding: set by decoder
  1633. */
  1634. int xvmc_acceleration;
  1635. /**
  1636. * macroblock decision mode
  1637. * - encoding: Set by user.
  1638. * - decoding: unused
  1639. */
  1640. int mb_decision;
  1641. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  1642. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  1643. #define FF_MB_DECISION_RD 2 ///< rate distortion
  1644. /**
  1645. * custom intra quantization matrix
  1646. * - encoding: Set by user, can be NULL.
  1647. * - decoding: Set by libavcodec.
  1648. */
  1649. uint16_t *intra_matrix;
  1650. /**
  1651. * custom inter quantization matrix
  1652. * - encoding: Set by user, can be NULL.
  1653. * - decoding: Set by libavcodec.
  1654. */
  1655. uint16_t *inter_matrix;
  1656. /**
  1657. * scene change detection threshold
  1658. * 0 is default, larger means fewer detected scene changes.
  1659. * - encoding: Set by user.
  1660. * - decoding: unused
  1661. */
  1662. int scenechange_threshold;
  1663. /**
  1664. * noise reduction strength
  1665. * - encoding: Set by user.
  1666. * - decoding: unused
  1667. */
  1668. int noise_reduction;
  1669. #if FF_API_INTER_THRESHOLD
  1670. /**
  1671. * @deprecated this field is unused
  1672. */
  1673. attribute_deprecated int inter_threshold;
  1674. #endif
  1675. #if FF_API_MPV_GLOBAL_OPTS
  1676. /**
  1677. * @deprecated use mpegvideo private options instead
  1678. */
  1679. attribute_deprecated int quantizer_noise_shaping;
  1680. #endif
  1681. /**
  1682. * Motion estimation threshold below which no motion estimation is
  1683. * performed, but instead the user specified motion vectors are used.
  1684. *
  1685. * - encoding: Set by user.
  1686. * - decoding: unused
  1687. */
  1688. int me_threshold;
  1689. /**
  1690. * Macroblock threshold below which the user specified macroblock types will be used.
  1691. * - encoding: Set by user.
  1692. * - decoding: unused
  1693. */
  1694. int mb_threshold;
  1695. /**
  1696. * precision of the intra DC coefficient - 8
  1697. * - encoding: Set by user.
  1698. * - decoding: unused
  1699. */
  1700. int intra_dc_precision;
  1701. /**
  1702. * Number of macroblock rows at the top which are skipped.
  1703. * - encoding: unused
  1704. * - decoding: Set by user.
  1705. */
  1706. int skip_top;
  1707. /**
  1708. * Number of macroblock rows at the bottom which are skipped.
  1709. * - encoding: unused
  1710. * - decoding: Set by user.
  1711. */
  1712. int skip_bottom;
  1713. /**
  1714. * Border processing masking, raises the quantizer for mbs on the borders
  1715. * of the picture.
  1716. * - encoding: Set by user.
  1717. * - decoding: unused
  1718. */
  1719. float border_masking;
  1720. /**
  1721. * minimum MB lagrange multipler
  1722. * - encoding: Set by user.
  1723. * - decoding: unused
  1724. */
  1725. int mb_lmin;
  1726. /**
  1727. * maximum MB lagrange multipler
  1728. * - encoding: Set by user.
  1729. * - decoding: unused
  1730. */
  1731. int mb_lmax;
  1732. /**
  1733. *
  1734. * - encoding: Set by user.
  1735. * - decoding: unused
  1736. */
  1737. int me_penalty_compensation;
  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. * minimum GOP size
  1752. * - encoding: Set by user.
  1753. * - decoding: unused
  1754. */
  1755. int keyint_min;
  1756. /**
  1757. * number of reference frames
  1758. * - encoding: Set by user.
  1759. * - decoding: Set by lavc.
  1760. */
  1761. int refs;
  1762. /**
  1763. * chroma qp offset from luma
  1764. * - encoding: Set by user.
  1765. * - decoding: unused
  1766. */
  1767. int chromaoffset;
  1768. /**
  1769. * Multiplied by qscale for each frame and added to scene_change_score.
  1770. * - encoding: Set by user.
  1771. * - decoding: unused
  1772. */
  1773. int scenechange_factor;
  1774. /**
  1775. *
  1776. * Note: Value depends upon the compare function used for fullpel ME.
  1777. * - encoding: Set by user.
  1778. * - decoding: unused
  1779. */
  1780. int mv0_threshold;
  1781. /**
  1782. * Adjust sensitivity of b_frame_strategy 1.
  1783. * - encoding: Set by user.
  1784. * - decoding: unused
  1785. */
  1786. int b_sensitivity;
  1787. /**
  1788. * Chromaticity coordinates of the source primaries.
  1789. * - encoding: Set by user
  1790. * - decoding: Set by libavcodec
  1791. */
  1792. enum AVColorPrimaries color_primaries;
  1793. /**
  1794. * Color Transfer Characteristic.
  1795. * - encoding: Set by user
  1796. * - decoding: Set by libavcodec
  1797. */
  1798. enum AVColorTransferCharacteristic color_trc;
  1799. /**
  1800. * YUV colorspace type.
  1801. * - encoding: Set by user
  1802. * - decoding: Set by libavcodec
  1803. */
  1804. enum AVColorSpace colorspace;
  1805. /**
  1806. * MPEG vs JPEG YUV range.
  1807. * - encoding: Set by user
  1808. * - decoding: Set by libavcodec
  1809. */
  1810. enum AVColorRange color_range;
  1811. /**
  1812. * This defines the location of chroma samples.
  1813. * - encoding: Set by user
  1814. * - decoding: Set by libavcodec
  1815. */
  1816. enum AVChromaLocation chroma_sample_location;
  1817. /**
  1818. * Number of slices.
  1819. * Indicates number of picture subdivisions. Used for parallelized
  1820. * decoding.
  1821. * - encoding: Set by user
  1822. * - decoding: unused
  1823. */
  1824. int slices;
  1825. /** Field order
  1826. * - encoding: set by libavcodec
  1827. * - decoding: Set by libavcodec
  1828. */
  1829. enum AVFieldOrder field_order;
  1830. /* audio only */
  1831. int sample_rate; ///< samples per second
  1832. int channels; ///< number of audio channels
  1833. /**
  1834. * audio sample format
  1835. * - encoding: Set by user.
  1836. * - decoding: Set by libavcodec.
  1837. */
  1838. enum AVSampleFormat sample_fmt; ///< sample format
  1839. /* The following data should not be initialized. */
  1840. /**
  1841. * Samples per packet, initialized when calling 'init'.
  1842. */
  1843. int frame_size;
  1844. /**
  1845. * Frame counter, set by libavcodec.
  1846. *
  1847. * - decoding: total number of frames returned from the decoder so far.
  1848. * - encoding: total number of frames passed to the encoder so far.
  1849. *
  1850. * @note the counter is not incremented if encoding/decoding resulted in
  1851. * an error.
  1852. */
  1853. int frame_number;
  1854. /**
  1855. * number of bytes per packet if constant and known or 0
  1856. * Used by some WAV based audio codecs.
  1857. */
  1858. int block_align;
  1859. /**
  1860. * Audio cutoff bandwidth (0 means "automatic")
  1861. * - encoding: Set by user.
  1862. * - decoding: unused
  1863. */
  1864. int cutoff;
  1865. #if FF_API_REQUEST_CHANNELS
  1866. /**
  1867. * Decoder should decode to this many channels if it can (0 for default)
  1868. * - encoding: unused
  1869. * - decoding: Set by user.
  1870. * @deprecated Deprecated in favor of request_channel_layout.
  1871. */
  1872. int request_channels;
  1873. #endif
  1874. /**
  1875. * Audio channel layout.
  1876. * - encoding: set by user.
  1877. * - decoding: set by user, may be overwritten by libavcodec.
  1878. */
  1879. uint64_t channel_layout;
  1880. /**
  1881. * Request decoder to use this channel layout if it can (0 for default)
  1882. * - encoding: unused
  1883. * - decoding: Set by user.
  1884. */
  1885. uint64_t request_channel_layout;
  1886. /**
  1887. * Type of service that the audio stream conveys.
  1888. * - encoding: Set by user.
  1889. * - decoding: Set by libavcodec.
  1890. */
  1891. enum AVAudioServiceType audio_service_type;
  1892. /**
  1893. * desired sample format
  1894. * - encoding: Not used.
  1895. * - decoding: Set by user.
  1896. * Decoder will decode to this format if it can.
  1897. */
  1898. enum AVSampleFormat request_sample_fmt;
  1899. /**
  1900. * Called at the beginning of each frame to get a buffer for it.
  1901. *
  1902. * The function will set AVFrame.data[], AVFrame.linesize[].
  1903. * AVFrame.extended_data[] must also be set, but it should be the same as
  1904. * AVFrame.data[] except for planar audio with more channels than can fit
  1905. * in AVFrame.data[]. In that case, AVFrame.data[] shall still contain as
  1906. * many data pointers as it can hold.
  1907. *
  1908. * if CODEC_CAP_DR1 is not set then get_buffer() must call
  1909. * avcodec_default_get_buffer() instead of providing buffers allocated by
  1910. * some other means.
  1911. *
  1912. * AVFrame.data[] should be 32- or 16-byte-aligned unless the CPU doesn't
  1913. * need it. avcodec_default_get_buffer() aligns the output buffer properly,
  1914. * but if get_buffer() is overridden then alignment considerations should
  1915. * be taken into account.
  1916. *
  1917. * @see avcodec_default_get_buffer()
  1918. *
  1919. * Video:
  1920. *
  1921. * If pic.reference is set then the frame will be read later by libavcodec.
  1922. * avcodec_align_dimensions2() should be used to find the required width and
  1923. * height, as they normally need to be rounded up to the next multiple of 16.
  1924. *
  1925. * If frame multithreading is used and thread_safe_callbacks is set,
  1926. * it may be called from a different thread, but not from more than one at
  1927. * once. Does not need to be reentrant.
  1928. *
  1929. * @see release_buffer(), reget_buffer()
  1930. * @see avcodec_align_dimensions2()
  1931. *
  1932. * Audio:
  1933. *
  1934. * Decoders request a buffer of a particular size by setting
  1935. * AVFrame.nb_samples prior to calling get_buffer(). The decoder may,
  1936. * however, utilize only part of the buffer by setting AVFrame.nb_samples
  1937. * to a smaller value in the output frame.
  1938. *
  1939. * Decoders cannot use the buffer after returning from
  1940. * avcodec_decode_audio4(), so they will not call release_buffer(), as it
  1941. * is assumed to be released immediately upon return.
  1942. *
  1943. * As a convenience, av_samples_get_buffer_size() and
  1944. * av_samples_fill_arrays() in libavutil may be used by custom get_buffer()
  1945. * functions to find the required data size and to fill data pointers and
  1946. * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
  1947. * since all planes must be the same size.
  1948. *
  1949. * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
  1950. *
  1951. * - encoding: unused
  1952. * - decoding: Set by libavcodec, user can override.
  1953. */
  1954. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  1955. /**
  1956. * Called to release buffers which were allocated with get_buffer.
  1957. * A released buffer can be reused in get_buffer().
  1958. * pic.data[*] must be set to NULL.
  1959. * May be called from a different thread if frame multithreading is used,
  1960. * but not by more than one thread at once, so does not need to be reentrant.
  1961. * - encoding: unused
  1962. * - decoding: Set by libavcodec, user can override.
  1963. */
  1964. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  1965. /**
  1966. * Called at the beginning of a frame to get cr buffer for it.
  1967. * Buffer type (size, hints) must be the same. libavcodec won't check it.
  1968. * libavcodec will pass previous buffer in pic, function should return
  1969. * same buffer or new buffer with old frame "painted" into it.
  1970. * If pic.data[0] == NULL must behave like get_buffer().
  1971. * if CODEC_CAP_DR1 is not set then reget_buffer() must call
  1972. * avcodec_default_reget_buffer() instead of providing buffers allocated by
  1973. * some other means.
  1974. * - encoding: unused
  1975. * - decoding: Set by libavcodec, user can override.
  1976. */
  1977. int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
  1978. /* - encoding parameters */
  1979. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  1980. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  1981. /**
  1982. * minimum quantizer
  1983. * - encoding: Set by user.
  1984. * - decoding: unused
  1985. */
  1986. int qmin;
  1987. /**
  1988. * maximum quantizer
  1989. * - encoding: Set by user.
  1990. * - decoding: unused
  1991. */
  1992. int qmax;
  1993. /**
  1994. * maximum quantizer difference between frames
  1995. * - encoding: Set by user.
  1996. * - decoding: unused
  1997. */
  1998. int max_qdiff;
  1999. /**
  2000. * ratecontrol qmin qmax limiting method
  2001. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax.
  2002. * - encoding: Set by user.
  2003. * - decoding: unused
  2004. */
  2005. float rc_qsquish;
  2006. float rc_qmod_amp;
  2007. int rc_qmod_freq;
  2008. /**
  2009. * decoder bitstream buffer size
  2010. * - encoding: Set by user.
  2011. * - decoding: unused
  2012. */
  2013. int rc_buffer_size;
  2014. /**
  2015. * ratecontrol override, see RcOverride
  2016. * - encoding: Allocated/set/freed by user.
  2017. * - decoding: unused
  2018. */
  2019. int rc_override_count;
  2020. RcOverride *rc_override;
  2021. /**
  2022. * rate control equation
  2023. * - encoding: Set by user
  2024. * - decoding: unused
  2025. */
  2026. const char *rc_eq;
  2027. /**
  2028. * maximum bitrate
  2029. * - encoding: Set by user.
  2030. * - decoding: unused
  2031. */
  2032. int rc_max_rate;
  2033. /**
  2034. * minimum bitrate
  2035. * - encoding: Set by user.
  2036. * - decoding: unused
  2037. */
  2038. int rc_min_rate;
  2039. float rc_buffer_aggressivity;
  2040. /**
  2041. * initial complexity for pass1 ratecontrol
  2042. * - encoding: Set by user.
  2043. * - decoding: unused
  2044. */
  2045. float rc_initial_cplx;
  2046. /**
  2047. * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
  2048. * - encoding: Set by user.
  2049. * - decoding: unused.
  2050. */
  2051. float rc_max_available_vbv_use;
  2052. /**
  2053. * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
  2054. * - encoding: Set by user.
  2055. * - decoding: unused.
  2056. */
  2057. float rc_min_vbv_overflow_use;
  2058. /**
  2059. * Number of bits which should be loaded into the rc buffer before decoding starts.
  2060. * - encoding: Set by user.
  2061. * - decoding: unused
  2062. */
  2063. int rc_initial_buffer_occupancy;
  2064. #define FF_CODER_TYPE_VLC 0
  2065. #define FF_CODER_TYPE_AC 1
  2066. #define FF_CODER_TYPE_RAW 2
  2067. #define FF_CODER_TYPE_RLE 3
  2068. #define FF_CODER_TYPE_DEFLATE 4
  2069. /**
  2070. * coder type
  2071. * - encoding: Set by user.
  2072. * - decoding: unused
  2073. */
  2074. int coder_type;
  2075. /**
  2076. * context model
  2077. * - encoding: Set by user.
  2078. * - decoding: unused
  2079. */
  2080. int context_model;
  2081. /**
  2082. * minimum Lagrange multipler
  2083. * - encoding: Set by user.
  2084. * - decoding: unused
  2085. */
  2086. int lmin;
  2087. /**
  2088. * maximum Lagrange multipler
  2089. * - encoding: Set by user.
  2090. * - decoding: unused
  2091. */
  2092. int lmax;
  2093. /**
  2094. * frame skip threshold
  2095. * - encoding: Set by user.
  2096. * - decoding: unused
  2097. */
  2098. int frame_skip_threshold;
  2099. /**
  2100. * frame skip factor
  2101. * - encoding: Set by user.
  2102. * - decoding: unused
  2103. */
  2104. int frame_skip_factor;
  2105. /**
  2106. * frame skip exponent
  2107. * - encoding: Set by user.
  2108. * - decoding: unused
  2109. */
  2110. int frame_skip_exp;
  2111. /**
  2112. * frame skip comparison function
  2113. * - encoding: Set by user.
  2114. * - decoding: unused
  2115. */
  2116. int frame_skip_cmp;
  2117. /**
  2118. * trellis RD quantization
  2119. * - encoding: Set by user.
  2120. * - decoding: unused
  2121. */
  2122. int trellis;
  2123. /**
  2124. * - encoding: Set by user.
  2125. * - decoding: unused
  2126. */
  2127. int min_prediction_order;
  2128. /**
  2129. * - encoding: Set by user.
  2130. * - decoding: unused
  2131. */
  2132. int max_prediction_order;
  2133. /**
  2134. * GOP timecode frame start number
  2135. * - encoding: Set by user, in non drop frame format
  2136. * - decoding: Set by libavcodec (timecode in the 25 bits format, -1 if unset)
  2137. */
  2138. int64_t timecode_frame_start;
  2139. /* The RTP callback: This function is called */
  2140. /* every time the encoder has a packet to send. */
  2141. /* It depends on the encoder if the data starts */
  2142. /* with a Start Code (it should). H.263 does. */
  2143. /* mb_nb contains the number of macroblocks */
  2144. /* encoded in the RTP payload. */
  2145. void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
  2146. int rtp_payload_size; /* The size of the RTP payload: the coder will */
  2147. /* do its best to deliver a chunk with size */
  2148. /* below rtp_payload_size, the chunk will start */
  2149. /* with a start code on some codecs like H.263. */
  2150. /* This doesn't take account of any particular */
  2151. /* headers inside the transmitted RTP payload. */
  2152. /* statistics, used for 2-pass encoding */
  2153. int mv_bits;
  2154. int header_bits;
  2155. int i_tex_bits;
  2156. int p_tex_bits;
  2157. int i_count;
  2158. int p_count;
  2159. int skip_count;
  2160. int misc_bits;
  2161. /**
  2162. * number of bits used for the previously encoded frame
  2163. * - encoding: Set by libavcodec.
  2164. * - decoding: unused
  2165. */
  2166. int frame_bits;
  2167. /**
  2168. * pass1 encoding statistics output buffer
  2169. * - encoding: Set by libavcodec.
  2170. * - decoding: unused
  2171. */
  2172. char *stats_out;
  2173. /**
  2174. * pass2 encoding statistics input buffer
  2175. * Concatenated stuff from stats_out of pass1 should be placed here.
  2176. * - encoding: Allocated/set/freed by user.
  2177. * - decoding: unused
  2178. */
  2179. char *stats_in;
  2180. /**
  2181. * Work around bugs in encoders which sometimes cannot be detected automatically.
  2182. * - encoding: Set by user
  2183. * - decoding: Set by user
  2184. */
  2185. int workaround_bugs;
  2186. #define FF_BUG_AUTODETECT 1 ///< autodetection
  2187. #define FF_BUG_OLD_MSMPEG4 2
  2188. #define FF_BUG_XVID_ILACE 4
  2189. #define FF_BUG_UMP4 8
  2190. #define FF_BUG_NO_PADDING 16
  2191. #define FF_BUG_AMV 32
  2192. #define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
  2193. #define FF_BUG_QPEL_CHROMA 64
  2194. #define FF_BUG_STD_QPEL 128
  2195. #define FF_BUG_QPEL_CHROMA2 256
  2196. #define FF_BUG_DIRECT_BLOCKSIZE 512
  2197. #define FF_BUG_EDGE 1024
  2198. #define FF_BUG_HPEL_CHROMA 2048
  2199. #define FF_BUG_DC_CLIP 4096
  2200. #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
  2201. #define FF_BUG_TRUNCATED 16384
  2202. /**
  2203. * strictly follow the standard (MPEG4, ...).
  2204. * - encoding: Set by user.
  2205. * - decoding: Set by user.
  2206. * Setting this to STRICT or higher means the encoder and decoder will
  2207. * generally do stupid things, whereas setting it to unofficial or lower
  2208. * will mean the encoder might produce output that is not supported by all
  2209. * spec-compliant decoders. Decoders don't differentiate between normal,
  2210. * unofficial and experimental (that is, they always try to decode things
  2211. * when they can) unless they are explicitly asked to behave stupidly
  2212. * (=strictly conform to the specs)
  2213. */
  2214. int strict_std_compliance;
  2215. #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software.
  2216. #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
  2217. #define FF_COMPLIANCE_NORMAL 0
  2218. #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions
  2219. #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
  2220. /**
  2221. * error concealment flags
  2222. * - encoding: unused
  2223. * - decoding: Set by user.
  2224. */
  2225. int error_concealment;
  2226. #define FF_EC_GUESS_MVS 1
  2227. #define FF_EC_DEBLOCK 2
  2228. /**
  2229. * debug
  2230. * - encoding: Set by user.
  2231. * - decoding: Set by user.
  2232. */
  2233. int debug;
  2234. #define FF_DEBUG_PICT_INFO 1
  2235. #define FF_DEBUG_RC 2
  2236. #define FF_DEBUG_BITSTREAM 4
  2237. #define FF_DEBUG_MB_TYPE 8
  2238. #define FF_DEBUG_QP 16
  2239. #define FF_DEBUG_MV 32
  2240. #define FF_DEBUG_DCT_COEFF 0x00000040
  2241. #define FF_DEBUG_SKIP 0x00000080
  2242. #define FF_DEBUG_STARTCODE 0x00000100
  2243. #define FF_DEBUG_PTS 0x00000200
  2244. #define FF_DEBUG_ER 0x00000400
  2245. #define FF_DEBUG_MMCO 0x00000800
  2246. #define FF_DEBUG_BUGS 0x00001000
  2247. #define FF_DEBUG_VIS_QP 0x00002000
  2248. #define FF_DEBUG_VIS_MB_TYPE 0x00004000
  2249. #define FF_DEBUG_BUFFERS 0x00008000
  2250. #define FF_DEBUG_THREADS 0x00010000
  2251. /**
  2252. * debug
  2253. * - encoding: Set by user.
  2254. * - decoding: Set by user.
  2255. */
  2256. int debug_mv;
  2257. #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
  2258. #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
  2259. #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
  2260. /**
  2261. * Error recognition; may misdetect some more or less valid parts as errors.
  2262. * - encoding: unused
  2263. * - decoding: Set by user.
  2264. */
  2265. int err_recognition;
  2266. #define AV_EF_CRCCHECK (1<<0)
  2267. #define AV_EF_BITSTREAM (1<<1)
  2268. #define AV_EF_BUFFER (1<<2)
  2269. #define AV_EF_EXPLODE (1<<3)
  2270. #define AV_EF_CAREFUL (1<<16)
  2271. #define AV_EF_COMPLIANT (1<<17)
  2272. #define AV_EF_AGGRESSIVE (1<<18)
  2273. /**
  2274. * opaque 64bit number (generally a PTS) that will be reordered and
  2275. * output in AVFrame.reordered_opaque
  2276. * @deprecated in favor of pkt_pts
  2277. * - encoding: unused
  2278. * - decoding: Set by user.
  2279. */
  2280. int64_t reordered_opaque;
  2281. /**
  2282. * Hardware accelerator in use
  2283. * - encoding: unused.
  2284. * - decoding: Set by libavcodec
  2285. */
  2286. struct AVHWAccel *hwaccel;
  2287. /**
  2288. * Hardware accelerator context.
  2289. * For some hardware accelerators, a global context needs to be
  2290. * provided by the user. In that case, this holds display-dependent
  2291. * data FFmpeg cannot instantiate itself. Please refer to the
  2292. * FFmpeg HW accelerator documentation to know how to fill this
  2293. * is. e.g. for VA API, this is a struct vaapi_context.
  2294. * - encoding: unused
  2295. * - decoding: Set by user
  2296. */
  2297. void *hwaccel_context;
  2298. /**
  2299. * error
  2300. * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
  2301. * - decoding: unused
  2302. */
  2303. uint64_t error[AV_NUM_DATA_POINTERS];
  2304. /**
  2305. * DCT algorithm, see FF_DCT_* below
  2306. * - encoding: Set by user.
  2307. * - decoding: unused
  2308. */
  2309. int dct_algo;
  2310. #define FF_DCT_AUTO 0
  2311. #define FF_DCT_FASTINT 1
  2312. #define FF_DCT_INT 2
  2313. #define FF_DCT_MMX 3
  2314. #define FF_DCT_ALTIVEC 5
  2315. #define FF_DCT_FAAN 6
  2316. /**
  2317. * IDCT algorithm, see FF_IDCT_* below.
  2318. * - encoding: Set by user.
  2319. * - decoding: Set by user.
  2320. */
  2321. int idct_algo;
  2322. #define FF_IDCT_AUTO 0
  2323. #define FF_IDCT_INT 1
  2324. #define FF_IDCT_SIMPLE 2
  2325. #define FF_IDCT_SIMPLEMMX 3
  2326. #define FF_IDCT_LIBMPEG2MMX 4
  2327. #define FF_IDCT_MMI 5
  2328. #define FF_IDCT_ARM 7
  2329. #define FF_IDCT_ALTIVEC 8
  2330. #define FF_IDCT_SH4 9
  2331. #define FF_IDCT_SIMPLEARM 10
  2332. #define FF_IDCT_H264 11
  2333. #define FF_IDCT_VP3 12
  2334. #define FF_IDCT_IPP 13
  2335. #define FF_IDCT_XVIDMMX 14
  2336. #define FF_IDCT_CAVS 15
  2337. #define FF_IDCT_SIMPLEARMV5TE 16
  2338. #define FF_IDCT_SIMPLEARMV6 17
  2339. #define FF_IDCT_SIMPLEVIS 18
  2340. #define FF_IDCT_WMV2 19
  2341. #define FF_IDCT_FAAN 20
  2342. #define FF_IDCT_EA 21
  2343. #define FF_IDCT_SIMPLENEON 22
  2344. #define FF_IDCT_SIMPLEALPHA 23
  2345. #define FF_IDCT_BINK 24
  2346. /**
  2347. * dsp_mask could be add used to disable unwanted CPU features
  2348. * CPU features (i.e. MMX, SSE. ...)
  2349. *
  2350. * With the FORCE flag you may instead enable given CPU features.
  2351. * (Dangerous: Usable in case of misdetection, improper usage however will
  2352. * result into program crash.)
  2353. */
  2354. unsigned dsp_mask;
  2355. /**
  2356. * bits per sample/pixel from the demuxer (needed for huffyuv).
  2357. * - encoding: Set by libavcodec.
  2358. * - decoding: Set by user.
  2359. */
  2360. int bits_per_coded_sample;
  2361. /**
  2362. * Bits per sample/pixel of internal libavcodec pixel/sample format.
  2363. * - encoding: set by user.
  2364. * - decoding: set by libavcodec.
  2365. */
  2366. int bits_per_raw_sample;
  2367. /**
  2368. * low resolution decoding, 1-> 1/2 size, 2->1/4 size
  2369. * - encoding: unused
  2370. * - decoding: Set by user.
  2371. */
  2372. int lowres;
  2373. /**
  2374. * the picture in the bitstream
  2375. * - encoding: Set by libavcodec.
  2376. * - decoding: Set by libavcodec.
  2377. */
  2378. AVFrame *coded_frame;
  2379. /**
  2380. * thread count
  2381. * is used to decide how many independent tasks should be passed to execute()
  2382. * - encoding: Set by user.
  2383. * - decoding: Set by user.
  2384. */
  2385. int thread_count;
  2386. /**
  2387. * Which multithreading methods to use.
  2388. * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
  2389. * so clients which cannot provide future frames should not use it.
  2390. *
  2391. * - encoding: Set by user, otherwise the default is used.
  2392. * - decoding: Set by user, otherwise the default is used.
  2393. */
  2394. int thread_type;
  2395. #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
  2396. #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
  2397. /**
  2398. * Which multithreading methods are in use by the codec.
  2399. * - encoding: Set by libavcodec.
  2400. * - decoding: Set by libavcodec.
  2401. */
  2402. int active_thread_type;
  2403. /**
  2404. * Set by the client if its custom get_buffer() callback can be called
  2405. * from another thread, which allows faster multithreaded decoding.
  2406. * draw_horiz_band() will be called from other threads regardless of this setting.
  2407. * Ignored if the default get_buffer() is used.
  2408. * - encoding: Set by user.
  2409. * - decoding: Set by user.
  2410. */
  2411. int thread_safe_callbacks;
  2412. /**
  2413. * The codec may call this to execute several independent things.
  2414. * It will return only after finishing all tasks.
  2415. * The user may replace this with some multithreaded implementation,
  2416. * the default implementation will execute the parts serially.
  2417. * @param count the number of things to execute
  2418. * - encoding: Set by libavcodec, user can override.
  2419. * - decoding: Set by libavcodec, user can override.
  2420. */
  2421. int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
  2422. /**
  2423. * The codec may call this to execute several independent things.
  2424. * It will return only after finishing all tasks.
  2425. * The user may replace this with some multithreaded implementation,
  2426. * the default implementation will execute the parts serially.
  2427. * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
  2428. * @param c context passed also to func
  2429. * @param count the number of things to execute
  2430. * @param arg2 argument passed unchanged to func
  2431. * @param ret return values of executed functions, must have space for "count" values. May be NULL.
  2432. * @param func function that will be called count times, with jobnr from 0 to count-1.
  2433. * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
  2434. * two instances of func executing at the same time will have the same threadnr.
  2435. * @return always 0 currently, but code should handle a future improvement where when any call to func
  2436. * returns < 0 no further calls to func may be done and < 0 is returned.
  2437. * - encoding: Set by libavcodec, user can override.
  2438. * - decoding: Set by libavcodec, user can override.
  2439. */
  2440. int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
  2441. /**
  2442. * thread opaque
  2443. * Can be used by execute() to store some per AVCodecContext stuff.
  2444. * - encoding: set by execute()
  2445. * - decoding: set by execute()
  2446. */
  2447. void *thread_opaque;
  2448. /**
  2449. * noise vs. sse weight for the nsse comparsion function
  2450. * - encoding: Set by user.
  2451. * - decoding: unused
  2452. */
  2453. int nsse_weight;
  2454. /**
  2455. * profile
  2456. * - encoding: Set by user.
  2457. * - decoding: Set by libavcodec.
  2458. */
  2459. int profile;
  2460. #define FF_PROFILE_UNKNOWN -99
  2461. #define FF_PROFILE_RESERVED -100
  2462. #define FF_PROFILE_AAC_MAIN 0
  2463. #define FF_PROFILE_AAC_LOW 1
  2464. #define FF_PROFILE_AAC_SSR 2
  2465. #define FF_PROFILE_AAC_LTP 3
  2466. #define FF_PROFILE_DTS 20
  2467. #define FF_PROFILE_DTS_ES 30
  2468. #define FF_PROFILE_DTS_96_24 40
  2469. #define FF_PROFILE_DTS_HD_HRA 50
  2470. #define FF_PROFILE_DTS_HD_MA 60
  2471. #define FF_PROFILE_MPEG2_422 0
  2472. #define FF_PROFILE_MPEG2_HIGH 1
  2473. #define FF_PROFILE_MPEG2_SS 2
  2474. #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
  2475. #define FF_PROFILE_MPEG2_MAIN 4
  2476. #define FF_PROFILE_MPEG2_SIMPLE 5
  2477. #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
  2478. #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
  2479. #define FF_PROFILE_H264_BASELINE 66
  2480. #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
  2481. #define FF_PROFILE_H264_MAIN 77
  2482. #define FF_PROFILE_H264_EXTENDED 88
  2483. #define FF_PROFILE_H264_HIGH 100
  2484. #define FF_PROFILE_H264_HIGH_10 110
  2485. #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
  2486. #define FF_PROFILE_H264_HIGH_422 122
  2487. #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
  2488. #define FF_PROFILE_H264_HIGH_444 144
  2489. #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
  2490. #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
  2491. #define FF_PROFILE_H264_CAVLC_444 44
  2492. #define FF_PROFILE_VC1_SIMPLE 0
  2493. #define FF_PROFILE_VC1_MAIN 1
  2494. #define FF_PROFILE_VC1_COMPLEX 2
  2495. #define FF_PROFILE_VC1_ADVANCED 3
  2496. #define FF_PROFILE_MPEG4_SIMPLE 0
  2497. #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
  2498. #define FF_PROFILE_MPEG4_CORE 2
  2499. #define FF_PROFILE_MPEG4_MAIN 3
  2500. #define FF_PROFILE_MPEG4_N_BIT 4
  2501. #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
  2502. #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
  2503. #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
  2504. #define FF_PROFILE_MPEG4_HYBRID 8
  2505. #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
  2506. #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
  2507. #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
  2508. #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
  2509. #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
  2510. #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
  2511. #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
  2512. /**
  2513. * level
  2514. * - encoding: Set by user.
  2515. * - decoding: Set by libavcodec.
  2516. */
  2517. int level;
  2518. #define FF_LEVEL_UNKNOWN -99
  2519. /**
  2520. *
  2521. * - encoding: unused
  2522. * - decoding: Set by user.
  2523. */
  2524. enum AVDiscard skip_loop_filter;
  2525. /**
  2526. *
  2527. * - encoding: unused
  2528. * - decoding: Set by user.
  2529. */
  2530. enum AVDiscard skip_idct;
  2531. /**
  2532. *
  2533. * - encoding: unused
  2534. * - decoding: Set by user.
  2535. */
  2536. enum AVDiscard skip_frame;
  2537. /**
  2538. * Header containing style information for text subtitles.
  2539. * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
  2540. * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  2541. * the Format line following. It shouldn't include any Dialogue line.
  2542. * - encoding: Set/allocated/freed by user (before avcodec_open2())
  2543. * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
  2544. */
  2545. uint8_t *subtitle_header;
  2546. int subtitle_header_size;
  2547. /**
  2548. * Simulates errors in the bitstream to test error concealment.
  2549. * - encoding: Set by user.
  2550. * - decoding: unused
  2551. */
  2552. int error_rate;
  2553. /**
  2554. * Current packet as passed into the decoder, to avoid having
  2555. * to pass the packet into every function. Currently only valid
  2556. * inside lavc and get/release_buffer callbacks.
  2557. * - decoding: set by avcodec_decode_*, read by get_buffer() for setting pkt_pts
  2558. * - encoding: unused
  2559. */
  2560. AVPacket *pkt;
  2561. /**
  2562. * VBV delay coded in the last frame (in periods of a 27 MHz clock).
  2563. * Used for compliant TS muxing.
  2564. * - encoding: Set by libavcodec.
  2565. * - decoding: unused.
  2566. */
  2567. uint64_t vbv_delay;
  2568. /**
  2569. * Current statistics for PTS correction.
  2570. * - decoding: maintained and used by libavcodec, not intended to be used by user apps
  2571. * - encoding: unused
  2572. */
  2573. int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
  2574. int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
  2575. int64_t pts_correction_last_pts; /// PTS of the last frame
  2576. int64_t pts_correction_last_dts; /// DTS of the last frame
  2577. } AVCodecContext;
  2578. /**
  2579. * AVProfile.
  2580. */
  2581. typedef struct AVProfile {
  2582. int profile;
  2583. const char *name; ///< short name for the profile
  2584. } AVProfile;
  2585. typedef struct AVCodecDefault AVCodecDefault;
  2586. /**
  2587. * AVCodec.
  2588. */
  2589. typedef struct AVCodec {
  2590. /**
  2591. * Name of the codec implementation.
  2592. * The name is globally unique among encoders and among decoders (but an
  2593. * encoder and a decoder can share the same name).
  2594. * This is the primary way to find a codec from the user perspective.
  2595. */
  2596. const char *name;
  2597. /**
  2598. * Descriptive name for the codec, meant to be more human readable than name.
  2599. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
  2600. */
  2601. const char *long_name;
  2602. enum AVMediaType type;
  2603. enum CodecID id;
  2604. /**
  2605. * Codec capabilities.
  2606. * see CODEC_CAP_*
  2607. */
  2608. int capabilities;
  2609. const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
  2610. const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
  2611. const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
  2612. const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
  2613. const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
  2614. uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
  2615. const AVClass *priv_class; ///< AVClass for the private context
  2616. const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
  2617. /*****************************************************************
  2618. * No fields below this line are part of the public API. They
  2619. * may not be used outside of libavcodec and can be changed and
  2620. * removed at will.
  2621. * New public fields should be added right above.
  2622. *****************************************************************
  2623. */
  2624. int priv_data_size;
  2625. struct AVCodec *next;
  2626. /**
  2627. * @name Frame-level threading support functions
  2628. * @{
  2629. */
  2630. /**
  2631. * If defined, called on thread contexts when they are created.
  2632. * If the codec allocates writable tables in init(), re-allocate them here.
  2633. * priv_data will be set to a copy of the original.
  2634. */
  2635. int (*init_thread_copy)(AVCodecContext *);
  2636. /**
  2637. * Copy necessary context variables from a previous thread context to the current one.
  2638. * If not defined, the next thread will start automatically; otherwise, the codec
  2639. * must call ff_thread_finish_setup().
  2640. *
  2641. * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
  2642. */
  2643. int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
  2644. /** @} */
  2645. /**
  2646. * Private codec-specific defaults.
  2647. */
  2648. const AVCodecDefault *defaults;
  2649. /**
  2650. * Initialize codec static data, called from avcodec_register().
  2651. */
  2652. void (*init_static_data)(struct AVCodec *codec);
  2653. int (*init)(AVCodecContext *);
  2654. int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
  2655. /**
  2656. * Encode data to an AVPacket.
  2657. *
  2658. * @param avctx codec context
  2659. * @param avpkt output AVPacket (may contain a user-provided buffer)
  2660. * @param[in] frame AVFrame containing the raw data to be encoded
  2661. * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
  2662. * non-empty packet was returned in avpkt.
  2663. * @return 0 on success, negative error code on failure
  2664. */
  2665. int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
  2666. int *got_packet_ptr);
  2667. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
  2668. int (*close)(AVCodecContext *);
  2669. /**
  2670. * Flush buffers.
  2671. * Will be called when seeking
  2672. */
  2673. void (*flush)(AVCodecContext *);
  2674. } AVCodec;
  2675. /**
  2676. * AVHWAccel.
  2677. */
  2678. typedef struct AVHWAccel {
  2679. /**
  2680. * Name of the hardware accelerated codec.
  2681. * The name is globally unique among encoders and among decoders (but an
  2682. * encoder and a decoder can share the same name).
  2683. */
  2684. const char *name;
  2685. /**
  2686. * Type of codec implemented by the hardware accelerator.
  2687. *
  2688. * See AVMEDIA_TYPE_xxx
  2689. */
  2690. enum AVMediaType type;
  2691. /**
  2692. * Codec implemented by the hardware accelerator.
  2693. *
  2694. * See CODEC_ID_xxx
  2695. */
  2696. enum CodecID id;
  2697. /**
  2698. * Supported pixel format.
  2699. *
  2700. * Only hardware accelerated formats are supported here.
  2701. */
  2702. enum PixelFormat pix_fmt;
  2703. /**
  2704. * Hardware accelerated codec capabilities.
  2705. * see FF_HWACCEL_CODEC_CAP_*
  2706. */
  2707. int capabilities;
  2708. struct AVHWAccel *next;
  2709. /**
  2710. * Called at the beginning of each frame or field picture.
  2711. *
  2712. * Meaningful frame information (codec specific) is guaranteed to
  2713. * be parsed at this point. This function is mandatory.
  2714. *
  2715. * Note that buf can be NULL along with buf_size set to 0.
  2716. * Otherwise, this means the whole frame is available at this point.
  2717. *
  2718. * @param avctx the codec context
  2719. * @param buf the frame data buffer base
  2720. * @param buf_size the size of the frame in bytes
  2721. * @return zero if successful, a negative value otherwise
  2722. */
  2723. int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  2724. /**
  2725. * Callback for each slice.
  2726. *
  2727. * Meaningful slice information (codec specific) is guaranteed to
  2728. * be parsed at this point. This function is mandatory.
  2729. *
  2730. * @param avctx the codec context
  2731. * @param buf the slice data buffer base
  2732. * @param buf_size the size of the slice in bytes
  2733. * @return zero if successful, a negative value otherwise
  2734. */
  2735. int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  2736. /**
  2737. * Called at the end of each frame or field picture.
  2738. *
  2739. * The whole picture is parsed at this point and can now be sent
  2740. * to the hardware accelerator. This function is mandatory.
  2741. *
  2742. * @param avctx the codec context
  2743. * @return zero if successful, a negative value otherwise
  2744. */
  2745. int (*end_frame)(AVCodecContext *avctx);
  2746. /**
  2747. * Size of HW accelerator private data.
  2748. *
  2749. * Private data is allocated with av_mallocz() before
  2750. * AVCodecContext.get_buffer() and deallocated after
  2751. * AVCodecContext.release_buffer().
  2752. */
  2753. int priv_data_size;
  2754. } AVHWAccel;
  2755. /**
  2756. * four components are given, that's all.
  2757. * the last component is alpha
  2758. */
  2759. typedef struct AVPicture {
  2760. uint8_t *data[AV_NUM_DATA_POINTERS];
  2761. int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line
  2762. } AVPicture;
  2763. #define AVPALETTE_SIZE 1024
  2764. #define AVPALETTE_COUNT 256
  2765. enum AVSubtitleType {
  2766. SUBTITLE_NONE,
  2767. SUBTITLE_BITMAP, ///< A bitmap, pict will be set
  2768. /**
  2769. * Plain text, the text field must be set by the decoder and is
  2770. * authoritative. ass and pict fields may contain approximations.
  2771. */
  2772. SUBTITLE_TEXT,
  2773. /**
  2774. * Formatted text, the ass field must be set by the decoder and is
  2775. * authoritative. pict and text fields may contain approximations.
  2776. */
  2777. SUBTITLE_ASS,
  2778. };
  2779. typedef struct AVSubtitleRect {
  2780. int x; ///< top left corner of pict, undefined when pict is not set
  2781. int y; ///< top left corner of pict, undefined when pict is not set
  2782. int w; ///< width of pict, undefined when pict is not set
  2783. int h; ///< height of pict, undefined when pict is not set
  2784. int nb_colors; ///< number of colors in pict, undefined when pict is not set
  2785. /**
  2786. * data+linesize for the bitmap of this subtitle.
  2787. * can be set for text/ass as well once they where rendered
  2788. */
  2789. AVPicture pict;
  2790. enum AVSubtitleType type;
  2791. char *text; ///< 0 terminated plain UTF-8 text
  2792. /**
  2793. * 0 terminated ASS/SSA compatible event line.
  2794. * The pressentation of this is unaffected by the other values in this
  2795. * struct.
  2796. */
  2797. char *ass;
  2798. } AVSubtitleRect;
  2799. typedef struct AVSubtitle {
  2800. uint16_t format; /* 0 = graphics */
  2801. uint32_t start_display_time; /* relative to packet pts, in ms */
  2802. uint32_t end_display_time; /* relative to packet pts, in ms */
  2803. unsigned num_rects;
  2804. AVSubtitleRect **rects;
  2805. int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
  2806. } AVSubtitle;
  2807. /* packet functions */
  2808. /**
  2809. * @deprecated use NULL instead
  2810. */
  2811. attribute_deprecated void av_destruct_packet_nofree(AVPacket *pkt);
  2812. /**
  2813. * Default packet destructor.
  2814. */
  2815. void av_destruct_packet(AVPacket *pkt);
  2816. /**
  2817. * Initialize optional fields of a packet with default values.
  2818. *
  2819. * @param pkt packet
  2820. */
  2821. void av_init_packet(AVPacket *pkt);
  2822. /**
  2823. * Allocate the payload of a packet and initialize its fields with
  2824. * default values.
  2825. *
  2826. * @param pkt packet
  2827. * @param size wanted payload size
  2828. * @return 0 if OK, AVERROR_xxx otherwise
  2829. */
  2830. int av_new_packet(AVPacket *pkt, int size);
  2831. /**
  2832. * Reduce packet size, correctly zeroing padding
  2833. *
  2834. * @param pkt packet
  2835. * @param size new size
  2836. */
  2837. void av_shrink_packet(AVPacket *pkt, int size);
  2838. /**
  2839. * Increase packet size, correctly zeroing padding
  2840. *
  2841. * @param pkt packet
  2842. * @param grow_by number of bytes by which to increase the size of the packet
  2843. */
  2844. int av_grow_packet(AVPacket *pkt, int grow_by);
  2845. /**
  2846. * @warning This is a hack - the packet memory allocation stuff is broken. The
  2847. * packet is allocated if it was not really allocated.
  2848. */
  2849. int av_dup_packet(AVPacket *pkt);
  2850. /**
  2851. * Free a packet.
  2852. *
  2853. * @param pkt packet to free
  2854. */
  2855. void av_free_packet(AVPacket *pkt);
  2856. /**
  2857. * Allocate new information of a packet.
  2858. *
  2859. * @param pkt packet
  2860. * @param type side information type
  2861. * @param size side information size
  2862. * @return pointer to fresh allocated data or NULL otherwise
  2863. */
  2864. uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  2865. int size);
  2866. /**
  2867. * Shrink the already allocated side data buffer
  2868. *
  2869. * @param pkt packet
  2870. * @param type side information type
  2871. * @param size new side information size
  2872. * @return 0 on success, < 0 on failure
  2873. */
  2874. int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  2875. int size);
  2876. /**
  2877. * Get side information from packet.
  2878. *
  2879. * @param pkt packet
  2880. * @param type desired side information type
  2881. * @param size pointer for side information size to store (optional)
  2882. * @return pointer to data if present or NULL otherwise
  2883. */
  2884. uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  2885. int *size);
  2886. int av_packet_merge_side_data(AVPacket *pkt);
  2887. int av_packet_split_side_data(AVPacket *pkt);
  2888. /* resample.c */
  2889. struct ReSampleContext;
  2890. struct AVResampleContext;
  2891. typedef struct ReSampleContext ReSampleContext;
  2892. /**
  2893. * Initialize audio resampling context.
  2894. *
  2895. * @param output_channels number of output channels
  2896. * @param input_channels number of input channels
  2897. * @param output_rate output sample rate
  2898. * @param input_rate input sample rate
  2899. * @param sample_fmt_out requested output sample format
  2900. * @param sample_fmt_in input sample format
  2901. * @param filter_length length of each FIR filter in the filterbank relative to the cutoff frequency
  2902. * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
  2903. * @param linear if 1 then the used FIR filter will be linearly interpolated
  2904. between the 2 closest, if 0 the closest will be used
  2905. * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
  2906. * @return allocated ReSampleContext, NULL if error occurred
  2907. */
  2908. ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
  2909. int output_rate, int input_rate,
  2910. enum AVSampleFormat sample_fmt_out,
  2911. enum AVSampleFormat sample_fmt_in,
  2912. int filter_length, int log2_phase_count,
  2913. int linear, double cutoff);
  2914. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  2915. /**
  2916. * Free resample context.
  2917. *
  2918. * @param s a non-NULL pointer to a resample context previously
  2919. * created with av_audio_resample_init()
  2920. */
  2921. void audio_resample_close(ReSampleContext *s);
  2922. /**
  2923. * Initialize an audio resampler.
  2924. * Note, if either rate is not an integer then simply scale both rates up so they are.
  2925. * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
  2926. * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
  2927. * @param linear If 1 then the used FIR filter will be linearly interpolated
  2928. between the 2 closest, if 0 the closest will be used
  2929. * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
  2930. */
  2931. struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
  2932. /**
  2933. * Resample an array of samples using a previously configured context.
  2934. * @param src an array of unconsumed samples
  2935. * @param consumed the number of samples of src which have been consumed are returned here
  2936. * @param src_size the number of unconsumed samples available
  2937. * @param dst_size the amount of space in samples available in dst
  2938. * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
  2939. * @return the number of samples written in dst or -1 if an error occurred
  2940. */
  2941. int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
  2942. /**
  2943. * Compensate samplerate/timestamp drift. The compensation is done by changing
  2944. * the resampler parameters, so no audible clicks or similar distortions occur
  2945. * @param compensation_distance distance in output samples over which the compensation should be performed
  2946. * @param sample_delta number of output samples which should be output less
  2947. *
  2948. * example: av_resample_compensate(c, 10, 500)
  2949. * here instead of 510 samples only 500 samples would be output
  2950. *
  2951. * note, due to rounding the actual compensation might be slightly different,
  2952. * especially if the compensation_distance is large and the in_rate used during init is small
  2953. */
  2954. void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
  2955. void av_resample_close(struct AVResampleContext *c);
  2956. /**
  2957. * Allocate memory for a picture. Call avpicture_free() to free it.
  2958. *
  2959. * @see avpicture_fill()
  2960. *
  2961. * @param picture the picture to be filled in
  2962. * @param pix_fmt the format of the picture
  2963. * @param width the width of the picture
  2964. * @param height the height of the picture
  2965. * @return zero if successful, a negative value if not
  2966. */
  2967. int avpicture_alloc(AVPicture *picture, enum PixelFormat pix_fmt, int width, int height);
  2968. /**
  2969. * Free a picture previously allocated by avpicture_alloc().
  2970. * The data buffer used by the AVPicture is freed, but the AVPicture structure
  2971. * itself is not.
  2972. *
  2973. * @param picture the AVPicture to be freed
  2974. */
  2975. void avpicture_free(AVPicture *picture);
  2976. /**
  2977. * Fill in the AVPicture fields.
  2978. * The fields of the given AVPicture are filled in by using the 'ptr' address
  2979. * which points to the image data buffer. Depending on the specified picture
  2980. * format, one or multiple image data pointers and line sizes will be set.
  2981. * If a planar format is specified, several pointers will be set pointing to
  2982. * the different picture planes and the line sizes of the different planes
  2983. * will be stored in the lines_sizes array.
  2984. * Call with ptr == NULL to get the required size for the ptr buffer.
  2985. *
  2986. * To allocate the buffer and fill in the AVPicture fields in one call,
  2987. * use avpicture_alloc().
  2988. *
  2989. * @param picture AVPicture whose fields are to be filled in
  2990. * @param ptr Buffer which will contain or contains the actual image data
  2991. * @param pix_fmt The format in which the picture data is stored.
  2992. * @param width the width of the image in pixels
  2993. * @param height the height of the image in pixels
  2994. * @return size of the image data in bytes
  2995. */
  2996. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  2997. enum PixelFormat pix_fmt, int width, int height);
  2998. /**
  2999. * Copy pixel data from an AVPicture into a buffer.
  3000. * The data is stored compactly, without any gaps for alignment or padding
  3001. * which may be applied by avpicture_fill().
  3002. *
  3003. * @see avpicture_get_size()
  3004. *
  3005. * @param[in] src AVPicture containing image data
  3006. * @param[in] pix_fmt The format in which the picture data is stored.
  3007. * @param[in] width the width of the image in pixels.
  3008. * @param[in] height the height of the image in pixels.
  3009. * @param[out] dest A buffer into which picture data will be copied.
  3010. * @param[in] dest_size The size of 'dest'.
  3011. * @return The number of bytes written to dest, or a negative value (error code) on error.
  3012. */
  3013. int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height,
  3014. unsigned char *dest, int dest_size);
  3015. /**
  3016. * Calculate the size in bytes that a picture of the given width and height
  3017. * would occupy if stored in the given picture format.
  3018. * Note that this returns the size of a compact representation as generated
  3019. * by avpicture_layout(), which can be smaller than the size required for e.g.
  3020. * avpicture_fill().
  3021. *
  3022. * @param pix_fmt the given picture format
  3023. * @param width the width of the image
  3024. * @param height the height of the image
  3025. * @return Image data size in bytes or -1 on error (e.g. too large dimensions).
  3026. */
  3027. int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height);
  3028. void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift);
  3029. /**
  3030. * Get the name of a codec.
  3031. * @return a static string identifying the codec; never NULL
  3032. */
  3033. const char *avcodec_get_name(enum CodecID id);
  3034. void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
  3035. /**
  3036. * Return a value representing the fourCC code associated to the
  3037. * pixel format pix_fmt, or 0 if no associated fourCC code can be
  3038. * found.
  3039. */
  3040. unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat pix_fmt);
  3041. /**
  3042. * Put a string representing the codec tag codec_tag in buf.
  3043. *
  3044. * @param buf_size size in bytes of buf
  3045. * @return the length of the string that would have been generated if
  3046. * enough space had been available, excluding the trailing null
  3047. */
  3048. size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);
  3049. #define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
  3050. #define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
  3051. #define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
  3052. #define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
  3053. #define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
  3054. #define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
  3055. /**
  3056. * Compute what kind of losses will occur when converting from one specific
  3057. * pixel format to another.
  3058. * When converting from one pixel format to another, information loss may occur.
  3059. * For example, when converting from RGB24 to GRAY, the color information will
  3060. * be lost. Similarly, other losses occur when converting from some formats to
  3061. * other formats. These losses can involve loss of chroma, but also loss of
  3062. * resolution, loss of color depth, loss due to the color space conversion, loss
  3063. * of the alpha bits or loss due to color quantization.
  3064. * avcodec_get_fix_fmt_loss() informs you about the various types of losses
  3065. * which will occur when converting from one pixel format to another.
  3066. *
  3067. * @param[in] dst_pix_fmt destination pixel format
  3068. * @param[in] src_pix_fmt source pixel format
  3069. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  3070. * @return Combination of flags informing you what kind of losses will occur
  3071. * (maximum loss for an invalid dst_pix_fmt).
  3072. */
  3073. int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
  3074. int has_alpha);
  3075. /**
  3076. * Find the best pixel format to convert to given a certain source pixel
  3077. * format. When converting from one pixel format to another, information loss
  3078. * may occur. For example, when converting from RGB24 to GRAY, the color
  3079. * information will be lost. Similarly, other losses occur when converting from
  3080. * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
  3081. * the given pixel formats should be used to suffer the least amount of loss.
  3082. * The pixel formats from which it chooses one, are determined by the
  3083. * pix_fmt_mask parameter.
  3084. *
  3085. * Note, only the first 64 pixel formats will fit in pix_fmt_mask.
  3086. *
  3087. * @code
  3088. * src_pix_fmt = PIX_FMT_YUV420P;
  3089. * pix_fmt_mask = (1 << PIX_FMT_YUV422P) | (1 << PIX_FMT_RGB24);
  3090. * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
  3091. * @endcode
  3092. *
  3093. * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
  3094. * @param[in] src_pix_fmt source pixel format
  3095. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  3096. * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
  3097. * @return The best pixel format to convert to or -1 if none was found.
  3098. */
  3099. enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
  3100. int has_alpha, int *loss_ptr);
  3101. /**
  3102. * Find the best pixel format to convert to given a certain source pixel
  3103. * format and a selection of two destination pixel formats. When converting from
  3104. * one pixel format to another, information loss may occur. For example, when converting
  3105. * from RGB24 to GRAY, the color information will be lost. Similarly, other losses occur when
  3106. * converting from some formats to other formats. avcodec_find_best_pix_fmt2() selects which of
  3107. * the given pixel formats should be used to suffer the least amount of loss.
  3108. *
  3109. * If one of the destination formats is PIX_FMT_NONE the other pixel format (if valid) will be
  3110. * returned.
  3111. *
  3112. * @code
  3113. * src_pix_fmt = PIX_FMT_YUV420P;
  3114. * dst_pix_fmt1= PIX_FMT_RGB24;
  3115. * dst_pix_fmt2= PIX_FMT_GRAY8;
  3116. * dst_pix_fmt3= PIX_FMT_RGB8;
  3117. * loss= FF_LOSS_CHROMA; // don't care about chroma loss, so chroma loss will be ignored.
  3118. * dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, alpha, &loss);
  3119. * dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt, dst_pix_fmt3, src_pix_fmt, alpha, &loss);
  3120. * @endcode
  3121. *
  3122. * @param[in] dst_pix_fmt1 One of the two destination pixel formats to choose from
  3123. * @param[in] dst_pix_fmt2 The other of the two destination pixel formats to choose from
  3124. * @param[in] src_pix_fmt Source pixel format
  3125. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  3126. * @param[in, out] loss_ptr Combination of loss flags. In: selects which of the losses to ignore, i.e.
  3127. * NULL or value of zero means we care about all losses. Out: the loss
  3128. * that occurs when converting from src to selected dst pixel format.
  3129. * @return The best pixel format to convert to or -1 if none was found.
  3130. */
  3131. enum PixelFormat avcodec_find_best_pix_fmt2(enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2,
  3132. enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
  3133. /* deinterlace a picture */
  3134. /* deinterlace - if not supported return -1 */
  3135. int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
  3136. enum PixelFormat pix_fmt, int width, int height);
  3137. /* external high level API */
  3138. /**
  3139. * If c is NULL, returns the first registered codec,
  3140. * if c is non-NULL, returns the next registered codec after c,
  3141. * or NULL if c is the last one.
  3142. */
  3143. AVCodec *av_codec_next(AVCodec *c);
  3144. /**
  3145. * Return the LIBAVCODEC_VERSION_INT constant.
  3146. */
  3147. unsigned avcodec_version(void);
  3148. /**
  3149. * Return the libavcodec build-time configuration.
  3150. */
  3151. const char *avcodec_configuration(void);
  3152. /**
  3153. * Return the libavcodec license.
  3154. */
  3155. const char *avcodec_license(void);
  3156. /**
  3157. * Register the codec codec and initialize libavcodec.
  3158. *
  3159. * @warning either this function or avcodec_register_all() must be called
  3160. * before any other libavcodec functions.
  3161. *
  3162. * @see avcodec_register_all()
  3163. */
  3164. void avcodec_register(AVCodec *codec);
  3165. /**
  3166. * Find a registered encoder with a matching codec ID.
  3167. *
  3168. * @param id CodecID of the requested encoder
  3169. * @return An encoder if one was found, NULL otherwise.
  3170. */
  3171. AVCodec *avcodec_find_encoder(enum CodecID id);
  3172. /**
  3173. * Find a registered encoder with the specified name.
  3174. *
  3175. * @param name name of the requested encoder
  3176. * @return An encoder if one was found, NULL otherwise.
  3177. */
  3178. AVCodec *avcodec_find_encoder_by_name(const char *name);
  3179. /**
  3180. * Find a registered decoder with a matching codec ID.
  3181. *
  3182. * @param id CodecID of the requested decoder
  3183. * @return A decoder if one was found, NULL otherwise.
  3184. */
  3185. AVCodec *avcodec_find_decoder(enum CodecID id);
  3186. /**
  3187. * Find a registered decoder with the specified name.
  3188. *
  3189. * @param name name of the requested decoder
  3190. * @return A decoder if one was found, NULL otherwise.
  3191. */
  3192. AVCodec *avcodec_find_decoder_by_name(const char *name);
  3193. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  3194. /**
  3195. * Return a name for the specified profile, if available.
  3196. *
  3197. * @param codec the codec that is searched for the given profile
  3198. * @param profile the profile value for which a name is requested
  3199. * @return A name for the profile if found, NULL otherwise.
  3200. */
  3201. const char *av_get_profile_name(const AVCodec *codec, int profile);
  3202. #if FF_API_ALLOC_CONTEXT
  3203. /**
  3204. * Set the fields of the given AVCodecContext to default values.
  3205. *
  3206. * @param s The AVCodecContext of which the fields should be set to default values.
  3207. * @deprecated use avcodec_get_context_defaults3
  3208. */
  3209. attribute_deprecated
  3210. void avcodec_get_context_defaults(AVCodecContext *s);
  3211. /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
  3212. * we WILL change its arguments and name a few times! */
  3213. attribute_deprecated
  3214. void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
  3215. #endif
  3216. /**
  3217. * Set the fields of the given AVCodecContext to default values corresponding
  3218. * to the given codec (defaults may be codec-dependent).
  3219. *
  3220. * Do not call this function if a non-NULL codec has been passed
  3221. * to avcodec_alloc_context3() that allocated this AVCodecContext.
  3222. * If codec is non-NULL, it is illegal to call avcodec_open2() with a
  3223. * different codec on this AVCodecContext.
  3224. */
  3225. int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec);
  3226. #if FF_API_ALLOC_CONTEXT
  3227. /**
  3228. * Allocate an AVCodecContext and set its fields to default values. The
  3229. * resulting struct can be deallocated by simply calling av_free().
  3230. *
  3231. * @return An AVCodecContext filled with default values or NULL on failure.
  3232. * @see avcodec_get_context_defaults
  3233. *
  3234. * @deprecated use avcodec_alloc_context3()
  3235. */
  3236. attribute_deprecated
  3237. AVCodecContext *avcodec_alloc_context(void);
  3238. /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
  3239. * we WILL change its arguments and name a few times! */
  3240. attribute_deprecated
  3241. AVCodecContext *avcodec_alloc_context2(enum AVMediaType);
  3242. #endif
  3243. /**
  3244. * Allocate an AVCodecContext and set its fields to default values. The
  3245. * resulting struct can be deallocated by calling avcodec_close() on it followed
  3246. * by av_free().
  3247. *
  3248. * @param codec if non-NULL, allocate private data and initialize defaults
  3249. * for the given codec. It is illegal to then call avcodec_open2()
  3250. * with a different codec.
  3251. * If NULL, then the codec-specific defaults won't be initialized,
  3252. * which may result in suboptimal default settings (this is
  3253. * important mainly for encoders, e.g. libx264).
  3254. *
  3255. * @return An AVCodecContext filled with default values or NULL on failure.
  3256. * @see avcodec_get_context_defaults
  3257. */
  3258. AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
  3259. /**
  3260. * Copy the settings of the source AVCodecContext into the destination
  3261. * AVCodecContext. The resulting destination codec context will be
  3262. * unopened, i.e. you are required to call avcodec_open2() before you
  3263. * can use this AVCodecContext to decode/encode video/audio data.
  3264. *
  3265. * @param dest target codec context, should be initialized with
  3266. * avcodec_alloc_context3(), but otherwise uninitialized
  3267. * @param src source codec context
  3268. * @return AVERROR() on error (e.g. memory allocation error), 0 on success
  3269. */
  3270. int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
  3271. /**
  3272. * Set the fields of the given AVFrame to default values.
  3273. *
  3274. * @param pic The AVFrame of which the fields should be set to default values.
  3275. */
  3276. void avcodec_get_frame_defaults(AVFrame *pic);
  3277. /**
  3278. * Allocate an AVFrame and set its fields to default values. The resulting
  3279. * struct can be deallocated by simply calling av_free().
  3280. *
  3281. * @return An AVFrame filled with default values or NULL on failure.
  3282. * @see avcodec_get_frame_defaults
  3283. */
  3284. AVFrame *avcodec_alloc_frame(void);
  3285. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
  3286. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
  3287. int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
  3288. /**
  3289. * Return the amount of padding in pixels which the get_buffer callback must
  3290. * provide around the edge of the image for codecs which do not have the
  3291. * CODEC_FLAG_EMU_EDGE flag.
  3292. *
  3293. * @return Required padding in pixels.
  3294. */
  3295. unsigned avcodec_get_edge_width(void);
  3296. /**
  3297. * Modify width and height values so that they will result in a memory
  3298. * buffer that is acceptable for the codec if you do not use any horizontal
  3299. * padding.
  3300. *
  3301. * May only be used if a codec with CODEC_CAP_DR1 has been opened.
  3302. * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
  3303. * according to avcodec_get_edge_width() before.
  3304. */
  3305. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
  3306. /**
  3307. * Modify width and height values so that they will result in a memory
  3308. * buffer that is acceptable for the codec if you also ensure that all
  3309. * line sizes are a multiple of the respective linesize_align[i].
  3310. *
  3311. * May only be used if a codec with CODEC_CAP_DR1 has been opened.
  3312. * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
  3313. * according to avcodec_get_edge_width() before.
  3314. */
  3315. void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
  3316. int linesize_align[AV_NUM_DATA_POINTERS]);
  3317. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
  3318. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
  3319. int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
  3320. //FIXME func typedef
  3321. #if FF_API_AVCODEC_OPEN
  3322. /**
  3323. * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
  3324. * function the context has to be allocated.
  3325. *
  3326. * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
  3327. * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  3328. * retrieving a codec.
  3329. *
  3330. * @warning This function is not thread safe!
  3331. *
  3332. * @code
  3333. * avcodec_register_all();
  3334. * codec = avcodec_find_decoder(CODEC_ID_H264);
  3335. * if (!codec)
  3336. * exit(1);
  3337. *
  3338. * context = avcodec_alloc_context3(codec);
  3339. *
  3340. * if (avcodec_open(context, codec) < 0)
  3341. * exit(1);
  3342. * @endcode
  3343. *
  3344. * @param avctx The context which will be set up to use the given codec.
  3345. * @param codec The codec to use within the context.
  3346. * @return zero on success, a negative value on error
  3347. * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
  3348. *
  3349. * @deprecated use avcodec_open2
  3350. */
  3351. attribute_deprecated
  3352. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  3353. #endif
  3354. /**
  3355. * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
  3356. * function the context has to be allocated with avcodec_alloc_context3().
  3357. *
  3358. * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
  3359. * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  3360. * retrieving a codec.
  3361. *
  3362. * @warning This function is not thread safe!
  3363. *
  3364. * @code
  3365. * avcodec_register_all();
  3366. * av_dict_set(&opts, "b", "2.5M", 0);
  3367. * codec = avcodec_find_decoder(CODEC_ID_H264);
  3368. * if (!codec)
  3369. * exit(1);
  3370. *
  3371. * context = avcodec_alloc_context3(codec);
  3372. *
  3373. * if (avcodec_open2(context, codec, opts) < 0)
  3374. * exit(1);
  3375. * @endcode
  3376. *
  3377. * @param avctx The context to initialize.
  3378. * @param codec The codec to open this context for. If a non-NULL codec has been
  3379. * previously passed to avcodec_alloc_context3() or
  3380. * avcodec_get_context_defaults3() for this context, then this
  3381. * parameter MUST be either NULL or equal to the previously passed
  3382. * codec.
  3383. * @param options A dictionary filled with AVCodecContext and codec-private options.
  3384. * On return this object will be filled with options that were not found.
  3385. *
  3386. * @return zero on success, a negative value on error
  3387. * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
  3388. * av_dict_set(), av_opt_find().
  3389. */
  3390. int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
  3391. #if FF_API_OLD_DECODE_AUDIO
  3392. /**
  3393. * Wrapper function which calls avcodec_decode_audio4.
  3394. *
  3395. * @deprecated Use avcodec_decode_audio4 instead.
  3396. *
  3397. * Decode the audio frame of size avpkt->size from avpkt->data into samples.
  3398. * Some decoders may support multiple frames in a single AVPacket, such
  3399. * decoders would then just decode the first frame. In this case,
  3400. * avcodec_decode_audio3 has to be called again with an AVPacket that contains
  3401. * the remaining data in order to decode the second frame etc.
  3402. * If no frame
  3403. * could be outputted, frame_size_ptr is zero. Otherwise, it is the
  3404. * decompressed frame size in bytes.
  3405. *
  3406. * @warning You must set frame_size_ptr to the allocated size of the
  3407. * output buffer before calling avcodec_decode_audio3().
  3408. *
  3409. * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
  3410. * the actual read bytes because some optimized bitstream readers read 32 or 64
  3411. * bits at once and could read over the end.
  3412. *
  3413. * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that
  3414. * no overreading happens for damaged MPEG streams.
  3415. *
  3416. * @warning You must not provide a custom get_buffer() when using
  3417. * avcodec_decode_audio3(). Doing so will override it with
  3418. * avcodec_default_get_buffer. Use avcodec_decode_audio4() instead,
  3419. * which does allow the application to provide a custom get_buffer().
  3420. *
  3421. * @note You might have to align the input buffer avpkt->data and output buffer
  3422. * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
  3423. * necessary at all, on others it won't work at all if not aligned and on others
  3424. * it will work but it will have an impact on performance.
  3425. *
  3426. * In practice, avpkt->data should have 4 byte alignment at minimum and
  3427. * samples should be 16 byte aligned unless the CPU doesn't need it
  3428. * (AltiVec and SSE do).
  3429. *
  3430. * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
  3431. * between input and output, these need to be fed with avpkt->data=NULL,
  3432. * avpkt->size=0 at the end to return the remaining frames.
  3433. *
  3434. * @param avctx the codec context
  3435. * @param[out] samples the output buffer, sample type in avctx->sample_fmt
  3436. * If the sample format is planar, each channel plane will
  3437. * be the same size, with no padding between channels.
  3438. * @param[in,out] frame_size_ptr the output buffer size in bytes
  3439. * @param[in] avpkt The input AVPacket containing the input buffer.
  3440. * You can create such packet with av_init_packet() and by then setting
  3441. * data and size, some decoders might in addition need other fields.
  3442. * All decoders are designed to use the least fields possible though.
  3443. * @return On error a negative value is returned, otherwise the number of bytes
  3444. * used or zero if no frame data was decompressed (used) from the input AVPacket.
  3445. */
  3446. attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
  3447. int *frame_size_ptr,
  3448. AVPacket *avpkt);
  3449. #endif
  3450. /**
  3451. * Decode the audio frame of size avpkt->size from avpkt->data into frame.
  3452. *
  3453. * Some decoders may support multiple frames in a single AVPacket. Such
  3454. * decoders would then just decode the first frame. In this case,
  3455. * avcodec_decode_audio4 has to be called again with an AVPacket containing
  3456. * the remaining data in order to decode the second frame, etc...
  3457. * Even if no frames are returned, the packet needs to be fed to the decoder
  3458. * with remaining data until it is completely consumed or an error occurs.
  3459. *
  3460. * @warning The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE
  3461. * larger than the actual read bytes because some optimized bitstream
  3462. * readers read 32 or 64 bits at once and could read over the end.
  3463. *
  3464. * @note You might have to align the input buffer. The alignment requirements
  3465. * depend on the CPU and the decoder.
  3466. *
  3467. * @param avctx the codec context
  3468. * @param[out] frame The AVFrame in which to store decoded audio samples.
  3469. * Decoders request a buffer of a particular size by setting
  3470. * AVFrame.nb_samples prior to calling get_buffer(). The
  3471. * decoder may, however, only utilize part of the buffer by
  3472. * setting AVFrame.nb_samples to a smaller value in the
  3473. * output frame.
  3474. * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
  3475. * non-zero.
  3476. * @param[in] avpkt The input AVPacket containing the input buffer.
  3477. * At least avpkt->data and avpkt->size should be set. Some
  3478. * decoders might also require additional fields to be set.
  3479. * @return A negative error code is returned if an error occurred during
  3480. * decoding, otherwise the number of bytes consumed from the input
  3481. * AVPacket is returned.
  3482. */
  3483. int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
  3484. int *got_frame_ptr, AVPacket *avpkt);
  3485. /**
  3486. * Decode the video frame of size avpkt->size from avpkt->data into picture.
  3487. * Some decoders may support multiple frames in a single AVPacket, such
  3488. * decoders would then just decode the first frame.
  3489. *
  3490. * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
  3491. * the actual read bytes because some optimized bitstream readers read 32 or 64
  3492. * bits at once and could read over the end.
  3493. *
  3494. * @warning The end of the input buffer buf should be set to 0 to ensure that
  3495. * no overreading happens for damaged MPEG streams.
  3496. *
  3497. * @note You might have to align the input buffer avpkt->data.
  3498. * The alignment requirements depend on the CPU: on some CPUs it isn't
  3499. * necessary at all, on others it won't work at all if not aligned and on others
  3500. * it will work but it will have an impact on performance.
  3501. *
  3502. * In practice, avpkt->data should have 4 byte alignment at minimum.
  3503. *
  3504. * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
  3505. * between input and output, these need to be fed with avpkt->data=NULL,
  3506. * avpkt->size=0 at the end to return the remaining frames.
  3507. *
  3508. * @param avctx the codec context
  3509. * @param[out] picture The AVFrame in which the decoded video frame will be stored.
  3510. * Use avcodec_alloc_frame to get an AVFrame, the codec will
  3511. * allocate memory for the actual bitmap.
  3512. * with default get/release_buffer(), the decoder frees/reuses the bitmap as it sees fit.
  3513. * with overridden get/release_buffer() (needs CODEC_CAP_DR1) the user decides into what buffer the decoder
  3514. * decodes and the decoder tells the user once it does not need the data anymore,
  3515. * the user app can at this point free/reuse/keep the memory as it sees fit.
  3516. *
  3517. * @param[in] avpkt The input AVpacket containing the input buffer.
  3518. * You can create such packet with av_init_packet() and by then setting
  3519. * data and size, some decoders might in addition need other fields like
  3520. * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
  3521. * fields possible.
  3522. * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
  3523. * @return On error a negative value is returned, otherwise the number of bytes
  3524. * used or zero if no frame could be decompressed.
  3525. */
  3526. int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
  3527. int *got_picture_ptr,
  3528. const AVPacket *avpkt);
  3529. /**
  3530. * Decode a subtitle message.
  3531. * Return a negative value on error, otherwise return the number of bytes used.
  3532. * If no subtitle could be decompressed, got_sub_ptr is zero.
  3533. * Otherwise, the subtitle is stored in *sub.
  3534. * Note that CODEC_CAP_DR1 is not available for subtitle codecs. This is for
  3535. * simplicity, because the performance difference is expect to be negligible
  3536. * and reusing a get_buffer written for video codecs would probably perform badly
  3537. * due to a potentially very different allocation pattern.
  3538. *
  3539. * @param avctx the codec context
  3540. * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
  3541. freed with avsubtitle_free if *got_sub_ptr is set.
  3542. * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
  3543. * @param[in] avpkt The input AVPacket containing the input buffer.
  3544. */
  3545. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  3546. int *got_sub_ptr,
  3547. AVPacket *avpkt);
  3548. /**
  3549. * Free all allocated data in the given subtitle struct.
  3550. *
  3551. * @param sub AVSubtitle to free.
  3552. */
  3553. void avsubtitle_free(AVSubtitle *sub);
  3554. #if FF_API_OLD_ENCODE_AUDIO
  3555. /**
  3556. * Encode an audio frame from samples into buf.
  3557. *
  3558. * @deprecated Use avcodec_encode_audio2 instead.
  3559. *
  3560. * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large.
  3561. * However, for codecs with avctx->frame_size equal to 0 (e.g. PCM) the user
  3562. * will know how much space is needed because it depends on the value passed
  3563. * in buf_size as described below. In that case a lower value can be used.
  3564. *
  3565. * @param avctx the codec context
  3566. * @param[out] buf the output buffer
  3567. * @param[in] buf_size the output buffer size
  3568. * @param[in] samples the input buffer containing the samples
  3569. * The number of samples read from this buffer is frame_size*channels,
  3570. * both of which are defined in avctx.
  3571. * For codecs which have avctx->frame_size equal to 0 (e.g. PCM) the number of
  3572. * samples read from samples is equal to:
  3573. * buf_size * 8 / (avctx->channels * av_get_bits_per_sample(avctx->codec_id))
  3574. * This also implies that av_get_bits_per_sample() must not return 0 for these
  3575. * codecs.
  3576. * @return On error a negative value is returned, on success zero or the number
  3577. * of bytes used to encode the data read from the input buffer.
  3578. */
  3579. int attribute_deprecated avcodec_encode_audio(AVCodecContext *avctx,
  3580. uint8_t *buf, int buf_size,
  3581. const short *samples);
  3582. #endif
  3583. /**
  3584. * Encode a frame of audio.
  3585. *
  3586. * Takes input samples from frame and writes the next output packet, if
  3587. * available, to avpkt. The output packet does not necessarily contain data for
  3588. * the most recent frame, as encoders can delay, split, and combine input frames
  3589. * internally as needed.
  3590. *
  3591. * @param avctx codec context
  3592. * @param avpkt output AVPacket.
  3593. * The user can supply an output buffer by setting
  3594. * avpkt->data and avpkt->size prior to calling the
  3595. * function, but if the size of the user-provided data is not
  3596. * large enough, encoding will fail. All other AVPacket fields
  3597. * will be reset by the encoder using av_init_packet(). If
  3598. * avpkt->data is NULL, the encoder will allocate it.
  3599. * The encoder will set avpkt->size to the size of the
  3600. * output packet.
  3601. *
  3602. * If this function fails or produces no output, avpkt will be
  3603. * freed using av_free_packet() (i.e. avpkt->destruct will be
  3604. * called to free the user supplied buffer).
  3605. * @param[in] frame AVFrame containing the raw audio data to be encoded.
  3606. * May be NULL when flushing an encoder that has the
  3607. * CODEC_CAP_DELAY capability set.
  3608. * There are 2 codec capabilities that affect the allowed
  3609. * values of frame->nb_samples.
  3610. * If CODEC_CAP_SMALL_LAST_FRAME is set, then only the final
  3611. * frame may be smaller than avctx->frame_size, and all other
  3612. * frames must be equal to avctx->frame_size.
  3613. * If CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  3614. * can have any number of samples.
  3615. * If neither is set, frame->nb_samples must be equal to
  3616. * avctx->frame_size for all frames.
  3617. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  3618. * output packet is non-empty, and to 0 if it is
  3619. * empty. If the function returns an error, the
  3620. * packet can be assumed to be invalid, and the
  3621. * value of got_packet_ptr is undefined and should
  3622. * not be used.
  3623. * @return 0 on success, negative error code on failure
  3624. */
  3625. int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
  3626. const AVFrame *frame, int *got_packet_ptr);
  3627. /**
  3628. * Fill audio frame data and linesize.
  3629. * AVFrame extended_data channel pointers are allocated if necessary for
  3630. * planar audio.
  3631. *
  3632. * @param frame the AVFrame
  3633. * frame->nb_samples must be set prior to calling the
  3634. * function. This function fills in frame->data,
  3635. * frame->extended_data, frame->linesize[0].
  3636. * @param nb_channels channel count
  3637. * @param sample_fmt sample format
  3638. * @param buf buffer to use for frame data
  3639. * @param buf_size size of buffer
  3640. * @param align plane size sample alignment
  3641. * @return 0 on success, negative error code on failure
  3642. */
  3643. int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
  3644. enum AVSampleFormat sample_fmt, const uint8_t *buf,
  3645. int buf_size, int align);
  3646. #if FF_API_OLD_ENCODE_VIDEO
  3647. /**
  3648. * @deprecated use avcodec_encode_video2() instead.
  3649. *
  3650. * Encode a video frame from pict into buf.
  3651. * The input picture should be
  3652. * stored using a specific format, namely avctx.pix_fmt.
  3653. *
  3654. * @param avctx the codec context
  3655. * @param[out] buf the output buffer for the bitstream of encoded frame
  3656. * @param[in] buf_size the size of the output buffer in bytes
  3657. * @param[in] pict the input picture to encode
  3658. * @return On error a negative value is returned, on success zero or the number
  3659. * of bytes used from the output buffer.
  3660. */
  3661. attribute_deprecated
  3662. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  3663. const AVFrame *pict);
  3664. #endif
  3665. /**
  3666. * Encode a frame of video.
  3667. *
  3668. * Takes input raw video data from frame and writes the next output packet, if
  3669. * available, to avpkt. The output packet does not necessarily contain data for
  3670. * the most recent frame, as encoders can delay and reorder input frames
  3671. * internally as needed.
  3672. *
  3673. * @param avctx codec context
  3674. * @param avpkt output AVPacket.
  3675. * The user can supply an output buffer by setting
  3676. * avpkt->data and avpkt->size prior to calling the
  3677. * function, but if the size of the user-provided data is not
  3678. * large enough, encoding will fail. All other AVPacket fields
  3679. * will be reset by the encoder using av_init_packet(). If
  3680. * avpkt->data is NULL, the encoder will allocate it.
  3681. * The encoder will set avpkt->size to the size of the
  3682. * output packet. The returned data (if any) belongs to the
  3683. * caller, he is responsible for freeing it.
  3684. *
  3685. * If this function fails or produces no output, avpkt will be
  3686. * freed using av_free_packet() (i.e. avpkt->destruct will be
  3687. * called to free the user supplied buffer).
  3688. * @param[in] frame AVFrame containing the raw video data to be encoded.
  3689. * May be NULL when flushing an encoder that has the
  3690. * CODEC_CAP_DELAY capability set.
  3691. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  3692. * output packet is non-empty, and to 0 if it is
  3693. * empty. If the function returns an error, the
  3694. * packet can be assumed to be invalid, and the
  3695. * value of got_packet_ptr is undefined and should
  3696. * not be used.
  3697. * @return 0 on success, negative error code on failure
  3698. */
  3699. int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
  3700. const AVFrame *frame, int *got_packet_ptr);
  3701. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  3702. const AVSubtitle *sub);
  3703. /**
  3704. * Close a given AVCodecContext and free all the data associated with it
  3705. * (but not the AVCodecContext itself).
  3706. *
  3707. * Calling this function on an AVCodecContext that hasn't been opened will free
  3708. * the codec-specific data allocated in avcodec_alloc_context3() /
  3709. * avcodec_get_context_defaults3() with a non-NULL codec. Subsequent calls will
  3710. * do nothing.
  3711. */
  3712. int avcodec_close(AVCodecContext *avctx);
  3713. /**
  3714. * Register all the codecs, parsers and bitstream filters which were enabled at
  3715. * configuration time. If you do not call this function you can select exactly
  3716. * which formats you want to support, by using the individual registration
  3717. * functions.
  3718. *
  3719. * @see avcodec_register
  3720. * @see av_register_codec_parser
  3721. * @see av_register_bitstream_filter
  3722. */
  3723. void avcodec_register_all(void);
  3724. /**
  3725. * Flush buffers, should be called when seeking or when switching to a different stream.
  3726. */
  3727. void avcodec_flush_buffers(AVCodecContext *avctx);
  3728. void avcodec_default_free_buffers(AVCodecContext *s);
  3729. /* misc useful functions */
  3730. /**
  3731. * Return codec bits per sample.
  3732. *
  3733. * @param[in] codec_id the codec
  3734. * @return Number of bits per sample or zero if unknown for the given codec.
  3735. */
  3736. int av_get_bits_per_sample(enum CodecID codec_id);
  3737. /**
  3738. * Return the PCM codec associated with a sample format.
  3739. * @param be endianness, 0 for little, 1 for big,
  3740. * -1 (or anything else) for native
  3741. * @return CODEC_ID_PCM_* or CODEC_ID_NONE
  3742. */
  3743. enum CodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be);
  3744. /**
  3745. * Return codec bits per sample.
  3746. * Only return non-zero if the bits per sample is exactly correct, not an
  3747. * approximation.
  3748. *
  3749. * @param[in] codec_id the codec
  3750. * @return Number of bits per sample or zero if unknown for the given codec.
  3751. */
  3752. int av_get_exact_bits_per_sample(enum CodecID codec_id);
  3753. /**
  3754. * Return audio frame duration.
  3755. *
  3756. * @param avctx codec context
  3757. * @param frame_bytes size of the frame, or 0 if unknown
  3758. * @return frame duration, in samples, if known. 0 if not able to
  3759. * determine.
  3760. */
  3761. int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
  3762. /* frame parsing */
  3763. typedef struct AVCodecParserContext {
  3764. void *priv_data;
  3765. struct AVCodecParser *parser;
  3766. int64_t frame_offset; /* offset of the current frame */
  3767. int64_t cur_offset; /* current offset
  3768. (incremented by each av_parser_parse()) */
  3769. int64_t next_frame_offset; /* offset of the next frame */
  3770. /* video info */
  3771. int pict_type; /* XXX: Put it back in AVCodecContext. */
  3772. /**
  3773. * This field is used for proper frame duration computation in lavf.
  3774. * It signals, how much longer the frame duration of the current frame
  3775. * is compared to normal frame duration.
  3776. *
  3777. * frame_duration = (1 + repeat_pict) * time_base
  3778. *
  3779. * It is used by codecs like H.264 to display telecined material.
  3780. */
  3781. int repeat_pict; /* XXX: Put it back in AVCodecContext. */
  3782. int64_t pts; /* pts of the current frame */
  3783. int64_t dts; /* dts of the current frame */
  3784. /* private data */
  3785. int64_t last_pts;
  3786. int64_t last_dts;
  3787. int fetch_timestamp;
  3788. #define AV_PARSER_PTS_NB 4
  3789. int cur_frame_start_index;
  3790. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
  3791. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
  3792. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
  3793. int flags;
  3794. #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
  3795. #define PARSER_FLAG_ONCE 0x0002
  3796. /// Set if the parser has a valid file offset
  3797. #define PARSER_FLAG_FETCHED_OFFSET 0x0004
  3798. int64_t offset; ///< byte offset from starting packet start
  3799. int64_t cur_frame_end[AV_PARSER_PTS_NB];
  3800. /**
  3801. * Set by parser to 1 for key frames and 0 for non-key frames.
  3802. * It is initialized to -1, so if the parser doesn't set this flag,
  3803. * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
  3804. * will be used.
  3805. */
  3806. int key_frame;
  3807. /**
  3808. * Time difference in stream time base units from the pts of this
  3809. * packet to the point at which the output from the decoder has converged
  3810. * independent from the availability of previous frames. That is, the
  3811. * frames are virtually identical no matter if decoding started from
  3812. * the very first frame or from this keyframe.
  3813. * Is AV_NOPTS_VALUE if unknown.
  3814. * This field is not the display duration of the current frame.
  3815. * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
  3816. * set.
  3817. *
  3818. * The purpose of this field is to allow seeking in streams that have no
  3819. * keyframes in the conventional sense. It corresponds to the
  3820. * recovery point SEI in H.264 and match_time_delta in NUT. It is also
  3821. * essential for some types of subtitle streams to ensure that all
  3822. * subtitles are correctly displayed after seeking.
  3823. */
  3824. int64_t convergence_duration;
  3825. // Timestamp generation support:
  3826. /**
  3827. * Synchronization point for start of timestamp generation.
  3828. *
  3829. * Set to >0 for sync point, 0 for no sync point and <0 for undefined
  3830. * (default).
  3831. *
  3832. * For example, this corresponds to presence of H.264 buffering period
  3833. * SEI message.
  3834. */
  3835. int dts_sync_point;
  3836. /**
  3837. * Offset of the current timestamp against last timestamp sync point in
  3838. * units of AVCodecContext.time_base.
  3839. *
  3840. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  3841. * contain a valid timestamp offset.
  3842. *
  3843. * Note that the timestamp of sync point has usually a nonzero
  3844. * dts_ref_dts_delta, which refers to the previous sync point. Offset of
  3845. * the next frame after timestamp sync point will be usually 1.
  3846. *
  3847. * For example, this corresponds to H.264 cpb_removal_delay.
  3848. */
  3849. int dts_ref_dts_delta;
  3850. /**
  3851. * Presentation delay of current frame in units of AVCodecContext.time_base.
  3852. *
  3853. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  3854. * contain valid non-negative timestamp delta (presentation time of a frame
  3855. * must not lie in the past).
  3856. *
  3857. * This delay represents the difference between decoding and presentation
  3858. * time of the frame.
  3859. *
  3860. * For example, this corresponds to H.264 dpb_output_delay.
  3861. */
  3862. int pts_dts_delta;
  3863. /**
  3864. * Position of the packet in file.
  3865. *
  3866. * Analogous to cur_frame_pts/dts
  3867. */
  3868. int64_t cur_frame_pos[AV_PARSER_PTS_NB];
  3869. /**
  3870. * Byte position of currently parsed frame in stream.
  3871. */
  3872. int64_t pos;
  3873. /**
  3874. * Previous frame byte position.
  3875. */
  3876. int64_t last_pos;
  3877. /**
  3878. * Duration of the current frame.
  3879. * For audio, this is in units of 1 / AVCodecContext.sample_rate.
  3880. * For all other types, this is in units of AVCodecContext.time_base.
  3881. */
  3882. int duration;
  3883. } AVCodecParserContext;
  3884. typedef struct AVCodecParser {
  3885. int codec_ids[5]; /* several codec IDs are permitted */
  3886. int priv_data_size;
  3887. int (*parser_init)(AVCodecParserContext *s);
  3888. int (*parser_parse)(AVCodecParserContext *s,
  3889. AVCodecContext *avctx,
  3890. const uint8_t **poutbuf, int *poutbuf_size,
  3891. const uint8_t *buf, int buf_size);
  3892. void (*parser_close)(AVCodecParserContext *s);
  3893. int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  3894. struct AVCodecParser *next;
  3895. } AVCodecParser;
  3896. AVCodecParser *av_parser_next(AVCodecParser *c);
  3897. void av_register_codec_parser(AVCodecParser *parser);
  3898. AVCodecParserContext *av_parser_init(int codec_id);
  3899. /**
  3900. * Parse a packet.
  3901. *
  3902. * @param s parser context.
  3903. * @param avctx codec context.
  3904. * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
  3905. * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
  3906. * @param buf input buffer.
  3907. * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
  3908. * @param pts input presentation timestamp.
  3909. * @param dts input decoding timestamp.
  3910. * @param pos input byte position in stream.
  3911. * @return the number of bytes of the input bitstream used.
  3912. *
  3913. * Example:
  3914. * @code
  3915. * while(in_len){
  3916. * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
  3917. * in_data, in_len,
  3918. * pts, dts, pos);
  3919. * in_data += len;
  3920. * in_len -= len;
  3921. *
  3922. * if(size)
  3923. * decode_frame(data, size);
  3924. * }
  3925. * @endcode
  3926. */
  3927. int av_parser_parse2(AVCodecParserContext *s,
  3928. AVCodecContext *avctx,
  3929. uint8_t **poutbuf, int *poutbuf_size,
  3930. const uint8_t *buf, int buf_size,
  3931. int64_t pts, int64_t dts,
  3932. int64_t pos);
  3933. int av_parser_change(AVCodecParserContext *s,
  3934. AVCodecContext *avctx,
  3935. uint8_t **poutbuf, int *poutbuf_size,
  3936. const uint8_t *buf, int buf_size, int keyframe);
  3937. void av_parser_close(AVCodecParserContext *s);
  3938. typedef struct AVBitStreamFilterContext {
  3939. void *priv_data;
  3940. struct AVBitStreamFilter *filter;
  3941. AVCodecParserContext *parser;
  3942. struct AVBitStreamFilterContext *next;
  3943. } AVBitStreamFilterContext;
  3944. typedef struct AVBitStreamFilter {
  3945. const char *name;
  3946. int priv_data_size;
  3947. int (*filter)(AVBitStreamFilterContext *bsfc,
  3948. AVCodecContext *avctx, const char *args,
  3949. uint8_t **poutbuf, int *poutbuf_size,
  3950. const uint8_t *buf, int buf_size, int keyframe);
  3951. void (*close)(AVBitStreamFilterContext *bsfc);
  3952. struct AVBitStreamFilter *next;
  3953. } AVBitStreamFilter;
  3954. void av_register_bitstream_filter(AVBitStreamFilter *bsf);
  3955. AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
  3956. int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
  3957. AVCodecContext *avctx, const char *args,
  3958. uint8_t **poutbuf, int *poutbuf_size,
  3959. const uint8_t *buf, int buf_size, int keyframe);
  3960. void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
  3961. AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
  3962. /* memory */
  3963. /**
  3964. * Reallocate the given block if it is not large enough, otherwise do nothing.
  3965. *
  3966. * @see av_realloc
  3967. */
  3968. void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
  3969. /**
  3970. * Allocate a buffer, reusing the given one if large enough.
  3971. *
  3972. * Contrary to av_fast_realloc the current buffer contents might not be
  3973. * preserved and on error the old buffer is freed, thus no special
  3974. * handling to avoid memleaks is necessary.
  3975. *
  3976. * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
  3977. * @param size size of the buffer *ptr points to
  3978. * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
  3979. * *size 0 if an error occurred.
  3980. */
  3981. void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
  3982. /**
  3983. * Same behaviour av_fast_malloc but the buffer has additional
  3984. * FF_INPUT_PADDING_SIZE at the end which will will always be 0.
  3985. *
  3986. * In addition the whole buffer will initially and after resizes
  3987. * be 0-initialized so that no uninitialized data will ever appear.
  3988. */
  3989. void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
  3990. /**
  3991. * Copy image src to dst. Wraps av_picture_data_copy() above.
  3992. */
  3993. void av_picture_copy(AVPicture *dst, const AVPicture *src,
  3994. enum PixelFormat pix_fmt, int width, int height);
  3995. /**
  3996. * Crop image top and left side.
  3997. */
  3998. int av_picture_crop(AVPicture *dst, const AVPicture *src,
  3999. enum PixelFormat pix_fmt, int top_band, int left_band);
  4000. /**
  4001. * Pad image.
  4002. */
  4003. int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum PixelFormat pix_fmt,
  4004. int padtop, int padbottom, int padleft, int padright, int *color);
  4005. /**
  4006. * Encode extradata length to a buffer. Used by xiph codecs.
  4007. *
  4008. * @param s buffer to write to; must be at least (v/255+1) bytes long
  4009. * @param v size of extradata in bytes
  4010. * @return number of bytes written to the buffer.
  4011. */
  4012. unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
  4013. /**
  4014. * Log a generic warning message about a missing feature. This function is
  4015. * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
  4016. * only, and would normally not be used by applications.
  4017. * @param[in] avc a pointer to an arbitrary struct of which the first field is
  4018. * a pointer to an AVClass struct
  4019. * @param[in] feature string containing the name of the missing feature
  4020. * @param[in] want_sample indicates if samples are wanted which exhibit this feature.
  4021. * If want_sample is non-zero, additional verbage will be added to the log
  4022. * message which tells the user how to report samples to the development
  4023. * mailing list.
  4024. */
  4025. void av_log_missing_feature(void *avc, const char *feature, int want_sample);
  4026. /**
  4027. * Log a generic warning message asking for a sample. This function is
  4028. * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
  4029. * only, and would normally not be used by applications.
  4030. * @param[in] avc a pointer to an arbitrary struct of which the first field is
  4031. * a pointer to an AVClass struct
  4032. * @param[in] msg string containing an optional message, or NULL if no message
  4033. */
  4034. void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3);
  4035. /**
  4036. * Register the hardware accelerator hwaccel.
  4037. */
  4038. void av_register_hwaccel(AVHWAccel *hwaccel);
  4039. /**
  4040. * If hwaccel is NULL, returns the first registered hardware accelerator,
  4041. * if hwaccel is non-NULL, returns the next registered hardware accelerator
  4042. * after hwaccel, or NULL if hwaccel is the last one.
  4043. */
  4044. AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel);
  4045. /**
  4046. * Lock operation used by lockmgr
  4047. */
  4048. enum AVLockOp {
  4049. AV_LOCK_CREATE, ///< Create a mutex
  4050. AV_LOCK_OBTAIN, ///< Lock the mutex
  4051. AV_LOCK_RELEASE, ///< Unlock the mutex
  4052. AV_LOCK_DESTROY, ///< Free mutex resources
  4053. };
  4054. /**
  4055. * Register a user provided lock manager supporting the operations
  4056. * specified by AVLockOp. mutex points to a (void *) where the
  4057. * lockmgr should store/get a pointer to a user allocated mutex. It's
  4058. * NULL upon AV_LOCK_CREATE and != NULL for all other ops.
  4059. *
  4060. * @param cb User defined callback. Note: FFmpeg may invoke calls to this
  4061. * callback during the call to av_lockmgr_register().
  4062. * Thus, the application must be prepared to handle that.
  4063. * If cb is set to NULL the lockmgr will be unregistered.
  4064. * Also note that during unregistration the previously registered
  4065. * lockmgr callback may also be invoked.
  4066. */
  4067. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
  4068. /**
  4069. * Get the type of the given codec.
  4070. */
  4071. enum AVMediaType avcodec_get_type(enum CodecID codec_id);
  4072. /**
  4073. * Get the AVClass for AVCodecContext. It can be used in combination with
  4074. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  4075. *
  4076. * @see av_opt_find().
  4077. */
  4078. const AVClass *avcodec_get_class(void);
  4079. /**
  4080. * Get the AVClass for AVFrame. It can be used in combination with
  4081. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  4082. *
  4083. * @see av_opt_find().
  4084. */
  4085. const AVClass *avcodec_get_frame_class(void);
  4086. /**
  4087. * @return a positive value if s is open (i.e. avcodec_open2() was called on it
  4088. * with no corresponding avcodec_close()), 0 otherwise.
  4089. */
  4090. int avcodec_is_open(AVCodecContext *s);
  4091. /**
  4092. * @return a non-zero number if codec is an encoder, zero otherwise
  4093. */
  4094. int av_codec_is_encoder(AVCodec *codec);
  4095. /**
  4096. * @return a non-zero number if codec is a decoder, zero otherwise
  4097. */
  4098. int av_codec_is_decoder(AVCodec *codec);
  4099. #endif /* AVCODEC_AVCODEC_H */