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.

4472 lines
148KB

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