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.

4768 lines
155KB

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