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.

5366 lines
177KB

  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. * @ingroup libavc
  25. * Libavcodec external API header
  26. */
  27. #include <errno.h>
  28. #include "libavutil/samplefmt.h"
  29. #include "libavutil/attributes.h"
  30. #include "libavutil/avutil.h"
  31. #include "libavutil/buffer.h"
  32. #include "libavutil/cpu.h"
  33. #include "libavutil/dict.h"
  34. #include "libavutil/frame.h"
  35. #include "libavutil/log.h"
  36. #include "libavutil/pixfmt.h"
  37. #include "libavutil/rational.h"
  38. #include "version.h"
  39. #if FF_API_FAST_MALLOC
  40. // to provide fast_*alloc
  41. #include "libavutil/mem.h"
  42. #endif
  43. /**
  44. * @defgroup libavc Encoding/Decoding Library
  45. * @{
  46. *
  47. * @defgroup lavc_decoding Decoding
  48. * @{
  49. * @}
  50. *
  51. * @defgroup lavc_encoding Encoding
  52. * @{
  53. * @}
  54. *
  55. * @defgroup lavc_codec Codecs
  56. * @{
  57. * @defgroup lavc_codec_native Native Codecs
  58. * @{
  59. * @}
  60. * @defgroup lavc_codec_wrappers External library wrappers
  61. * @{
  62. * @}
  63. * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
  64. * @{
  65. * @}
  66. * @}
  67. * @defgroup lavc_internal Internal
  68. * @{
  69. * @}
  70. * @}
  71. */
  72. /**
  73. * @ingroup libavc
  74. * @defgroup lavc_encdec send/receive encoding and decoding API overview
  75. * @{
  76. *
  77. * The avcodec_send_packet()/avcodec_receive_frame()/avcodec_send_frame()/
  78. * avcodec_receive_packet() functions provide an encode/decode API, which
  79. * decouples input and output.
  80. *
  81. * The API is very similar for encoding/decoding and audio/video, and works as
  82. * follows:
  83. * - Set up and open the AVCodecContext as usual.
  84. * - Send valid input:
  85. * - For decoding, call avcodec_send_packet() to give the decoder raw
  86. * compressed data in an AVPacket.
  87. * - For encoding, call avcodec_send_frame() to give the decoder an AVFrame
  88. * containing uncompressed audio or video.
  89. * In both cases, it is recommended that AVPackets and AVFrames are
  90. * refcounted, or libavcodec might have to copy the input data. (libavformat
  91. * always returns refcounted AVPackets, and av_frame_get_buffer() allocates
  92. * refcounted AVFrames.)
  93. * - Receive output in a loop. Periodically call one of the avcodec_receive_*()
  94. * functions and process their output:
  95. * - For decoding, call avcodec_receive_frame(). On success, it will return
  96. * an AVFrame containing uncompressed audio or video data.
  97. * - For encoding, call avcodec_receive_packet(). On success, it will return
  98. * an AVPacket with a compressed frame.
  99. * Repeat this call until it returns AVERROR(EAGAIN) or an error. The
  100. * AVERROR(EAGAIN) return value means that new input data is required to
  101. * return new output. In this case, continue with sending input. For each
  102. * input frame/packet, the codec will typically return 1 output frame/packet,
  103. * but it can also be 0 or more than 1.
  104. *
  105. * At the beginning of decoding or encoding, the codec might accept multiple
  106. * input frames/packets without returning a frame, until its internal buffers
  107. * are filled. This situation is handled transparently if you follow the steps
  108. * outlined above.
  109. *
  110. * In theory, sending input can result in EAGAIN - this should happen only if
  111. * not all output was received. You can use this to structure alternative decode
  112. * or encode loops other than the one suggested above. For example, you could
  113. * try sending new input on each iteration, and try to receive output if that
  114. * returns EAGAIN.
  115. *
  116. * End of stream situations. These require "flushing" (aka draining) the codec,
  117. * as the codec might buffer multiple frames or packets internally for
  118. * performance or out of necessity (consider B-frames).
  119. * This is handled as follows:
  120. * - Instead of valid input, send NULL to the avcodec_send_packet() (decoding)
  121. * or avcodec_send_frame() (encoding) functions. This will enter draining
  122. * mode.
  123. * - Call avcodec_receive_frame() (decoding) or avcodec_receive_packet()
  124. * (encoding) in a loop until AVERROR_EOF is returned. The functions will
  125. * not return AVERROR(EAGAIN), unless you forgot to enter draining mode.
  126. * - Before decoding can be resumed again, the codec has to be reset with
  127. * avcodec_flush_buffers().
  128. *
  129. * Using the API as outlined above is highly recommended. But it is also
  130. * possible to call functions outside of this rigid schema. For example, you can
  131. * call avcodec_send_packet() repeatedly without calling
  132. * avcodec_receive_frame(). In this case, avcodec_send_packet() will succeed
  133. * until the codec's internal buffer has been filled up (which is typically of
  134. * size 1 per output frame, after initial input), and then reject input with
  135. * AVERROR(EAGAIN). Once it starts rejecting input, you have no choice but to
  136. * read at least some output.
  137. *
  138. * Not all codecs will follow a rigid and predictable dataflow; the only
  139. * guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on
  140. * one end implies that a receive/send call on the other end will succeed. In
  141. * general, no codec will permit unlimited buffering of input or output.
  142. *
  143. * This API replaces the following legacy functions:
  144. * - avcodec_decode_video2() and avcodec_decode_audio4():
  145. * Use avcodec_send_packet() to feed input to the decoder, then use
  146. * avcodec_receive_frame() to receive decoded frames after each packet.
  147. * Unlike with the old video decoding API, multiple frames might result from
  148. * a packet. For audio, splitting the input packet into frames by partially
  149. * decoding packets becomes transparent to the API user. You never need to
  150. * feed an AVPacket to the API twice (unless it is rejected with EAGAIN - then
  151. * no data was read from the packet).
  152. * Additionally, sending a flush/draining packet is required only once.
  153. * - avcodec_encode_video2()/avcodec_encode_audio2():
  154. * Use avcodec_send_frame() to feed input to the encoder, then use
  155. * avcodec_receive_packet() to receive encoded packets.
  156. * Providing user-allocated buffers for avcodec_receive_packet() is not
  157. * possible.
  158. * - The new API does not handle subtitles yet.
  159. *
  160. * Mixing new and old function calls on the same AVCodecContext is not allowed,
  161. * and will result in arbitrary behavior.
  162. *
  163. * Some codecs might require using the new API; using the old API will return
  164. * an error when calling it. All codecs support the new API.
  165. *
  166. * A codec is not allowed to return EAGAIN for both sending and receiving. This
  167. * would be an invalid state, which could put the codec user into an endless
  168. * loop. The API has no concept of time either: it cannot happen that trying to
  169. * do avcodec_send_packet() results in EAGAIN, but a repeated call 1 second
  170. * later accepts the packet (with no other receive/flush API calls involved).
  171. * The API is a strict state machine, and the passage of time is not supposed
  172. * to influence it. Some timing-dependent behavior might still be deemed
  173. * acceptable in certain cases. But it must never result in both send/receive
  174. * returning EAGAIN at the same time at any point. It must also absolutely be
  175. * avoided that the current state is "unstable" and can "flip-flop" between
  176. * the send/receive APIs allowing progress. For example, it's not allowed that
  177. * the codec randomly decides that it actually wants to consume a packet now
  178. * instead of returning a frame, after it just returned EAGAIN on an
  179. * avcodec_send_packet() call.
  180. * @}
  181. */
  182. /**
  183. * @defgroup lavc_core Core functions/structures.
  184. * @ingroup libavc
  185. *
  186. * Basic definitions, functions for querying libavcodec capabilities,
  187. * allocating core structures, etc.
  188. * @{
  189. */
  190. /**
  191. * Identify the syntax and semantics of the bitstream.
  192. * The principle is roughly:
  193. * Two decoders with the same ID can decode the same streams.
  194. * Two encoders with the same ID can encode compatible streams.
  195. * There may be slight deviations from the principle due to implementation
  196. * details.
  197. *
  198. * If you add a codec ID to this list, add it so that
  199. * 1. no value of a existing codec ID changes (that would break ABI),
  200. * 2. it is as close as possible to similar codecs.
  201. *
  202. * After adding new codec IDs, do not forget to add an entry to the codec
  203. * descriptor list and bump libavcodec minor version.
  204. */
  205. enum AVCodecID {
  206. AV_CODEC_ID_NONE,
  207. /* video codecs */
  208. AV_CODEC_ID_MPEG1VIDEO,
  209. AV_CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
  210. #if FF_API_XVMC
  211. AV_CODEC_ID_MPEG2VIDEO_XVMC,
  212. #endif /* FF_API_XVMC */
  213. AV_CODEC_ID_H261,
  214. AV_CODEC_ID_H263,
  215. AV_CODEC_ID_RV10,
  216. AV_CODEC_ID_RV20,
  217. AV_CODEC_ID_MJPEG,
  218. AV_CODEC_ID_MJPEGB,
  219. AV_CODEC_ID_LJPEG,
  220. AV_CODEC_ID_SP5X,
  221. AV_CODEC_ID_JPEGLS,
  222. AV_CODEC_ID_MPEG4,
  223. AV_CODEC_ID_RAWVIDEO,
  224. AV_CODEC_ID_MSMPEG4V1,
  225. AV_CODEC_ID_MSMPEG4V2,
  226. AV_CODEC_ID_MSMPEG4V3,
  227. AV_CODEC_ID_WMV1,
  228. AV_CODEC_ID_WMV2,
  229. AV_CODEC_ID_H263P,
  230. AV_CODEC_ID_H263I,
  231. AV_CODEC_ID_FLV1,
  232. AV_CODEC_ID_SVQ1,
  233. AV_CODEC_ID_SVQ3,
  234. AV_CODEC_ID_DVVIDEO,
  235. AV_CODEC_ID_HUFFYUV,
  236. AV_CODEC_ID_CYUV,
  237. AV_CODEC_ID_H264,
  238. AV_CODEC_ID_INDEO3,
  239. AV_CODEC_ID_VP3,
  240. AV_CODEC_ID_THEORA,
  241. AV_CODEC_ID_ASV1,
  242. AV_CODEC_ID_ASV2,
  243. AV_CODEC_ID_FFV1,
  244. AV_CODEC_ID_4XM,
  245. AV_CODEC_ID_VCR1,
  246. AV_CODEC_ID_CLJR,
  247. AV_CODEC_ID_MDEC,
  248. AV_CODEC_ID_ROQ,
  249. AV_CODEC_ID_INTERPLAY_VIDEO,
  250. AV_CODEC_ID_XAN_WC3,
  251. AV_CODEC_ID_XAN_WC4,
  252. AV_CODEC_ID_RPZA,
  253. AV_CODEC_ID_CINEPAK,
  254. AV_CODEC_ID_WS_VQA,
  255. AV_CODEC_ID_MSRLE,
  256. AV_CODEC_ID_MSVIDEO1,
  257. AV_CODEC_ID_IDCIN,
  258. AV_CODEC_ID_8BPS,
  259. AV_CODEC_ID_SMC,
  260. AV_CODEC_ID_FLIC,
  261. AV_CODEC_ID_TRUEMOTION1,
  262. AV_CODEC_ID_VMDVIDEO,
  263. AV_CODEC_ID_MSZH,
  264. AV_CODEC_ID_ZLIB,
  265. AV_CODEC_ID_QTRLE,
  266. AV_CODEC_ID_TSCC,
  267. AV_CODEC_ID_ULTI,
  268. AV_CODEC_ID_QDRAW,
  269. AV_CODEC_ID_VIXL,
  270. AV_CODEC_ID_QPEG,
  271. AV_CODEC_ID_PNG,
  272. AV_CODEC_ID_PPM,
  273. AV_CODEC_ID_PBM,
  274. AV_CODEC_ID_PGM,
  275. AV_CODEC_ID_PGMYUV,
  276. AV_CODEC_ID_PAM,
  277. AV_CODEC_ID_FFVHUFF,
  278. AV_CODEC_ID_RV30,
  279. AV_CODEC_ID_RV40,
  280. AV_CODEC_ID_VC1,
  281. AV_CODEC_ID_WMV3,
  282. AV_CODEC_ID_LOCO,
  283. AV_CODEC_ID_WNV1,
  284. AV_CODEC_ID_AASC,
  285. AV_CODEC_ID_INDEO2,
  286. AV_CODEC_ID_FRAPS,
  287. AV_CODEC_ID_TRUEMOTION2,
  288. AV_CODEC_ID_BMP,
  289. AV_CODEC_ID_CSCD,
  290. AV_CODEC_ID_MMVIDEO,
  291. AV_CODEC_ID_ZMBV,
  292. AV_CODEC_ID_AVS,
  293. AV_CODEC_ID_SMACKVIDEO,
  294. AV_CODEC_ID_NUV,
  295. AV_CODEC_ID_KMVC,
  296. AV_CODEC_ID_FLASHSV,
  297. AV_CODEC_ID_CAVS,
  298. AV_CODEC_ID_JPEG2000,
  299. AV_CODEC_ID_VMNC,
  300. AV_CODEC_ID_VP5,
  301. AV_CODEC_ID_VP6,
  302. AV_CODEC_ID_VP6F,
  303. AV_CODEC_ID_TARGA,
  304. AV_CODEC_ID_DSICINVIDEO,
  305. AV_CODEC_ID_TIERTEXSEQVIDEO,
  306. AV_CODEC_ID_TIFF,
  307. AV_CODEC_ID_GIF,
  308. AV_CODEC_ID_DXA,
  309. AV_CODEC_ID_DNXHD,
  310. AV_CODEC_ID_THP,
  311. AV_CODEC_ID_SGI,
  312. AV_CODEC_ID_C93,
  313. AV_CODEC_ID_BETHSOFTVID,
  314. AV_CODEC_ID_PTX,
  315. AV_CODEC_ID_TXD,
  316. AV_CODEC_ID_VP6A,
  317. AV_CODEC_ID_AMV,
  318. AV_CODEC_ID_VB,
  319. AV_CODEC_ID_PCX,
  320. AV_CODEC_ID_SUNRAST,
  321. AV_CODEC_ID_INDEO4,
  322. AV_CODEC_ID_INDEO5,
  323. AV_CODEC_ID_MIMIC,
  324. AV_CODEC_ID_RL2,
  325. AV_CODEC_ID_ESCAPE124,
  326. AV_CODEC_ID_DIRAC,
  327. AV_CODEC_ID_BFI,
  328. AV_CODEC_ID_CMV,
  329. AV_CODEC_ID_MOTIONPIXELS,
  330. AV_CODEC_ID_TGV,
  331. AV_CODEC_ID_TGQ,
  332. AV_CODEC_ID_TQI,
  333. AV_CODEC_ID_AURA,
  334. AV_CODEC_ID_AURA2,
  335. AV_CODEC_ID_V210X,
  336. AV_CODEC_ID_TMV,
  337. AV_CODEC_ID_V210,
  338. AV_CODEC_ID_DPX,
  339. AV_CODEC_ID_MAD,
  340. AV_CODEC_ID_FRWU,
  341. AV_CODEC_ID_FLASHSV2,
  342. AV_CODEC_ID_CDGRAPHICS,
  343. AV_CODEC_ID_R210,
  344. AV_CODEC_ID_ANM,
  345. AV_CODEC_ID_BINKVIDEO,
  346. AV_CODEC_ID_IFF_ILBM,
  347. AV_CODEC_ID_IFF_BYTERUN1,
  348. AV_CODEC_ID_KGV1,
  349. AV_CODEC_ID_YOP,
  350. AV_CODEC_ID_VP8,
  351. AV_CODEC_ID_PICTOR,
  352. AV_CODEC_ID_ANSI,
  353. AV_CODEC_ID_A64_MULTI,
  354. AV_CODEC_ID_A64_MULTI5,
  355. AV_CODEC_ID_R10K,
  356. AV_CODEC_ID_MXPEG,
  357. AV_CODEC_ID_LAGARITH,
  358. AV_CODEC_ID_PRORES,
  359. AV_CODEC_ID_JV,
  360. AV_CODEC_ID_DFA,
  361. AV_CODEC_ID_WMV3IMAGE,
  362. AV_CODEC_ID_VC1IMAGE,
  363. AV_CODEC_ID_UTVIDEO,
  364. AV_CODEC_ID_BMV_VIDEO,
  365. AV_CODEC_ID_VBLE,
  366. AV_CODEC_ID_DXTORY,
  367. AV_CODEC_ID_V410,
  368. AV_CODEC_ID_XWD,
  369. AV_CODEC_ID_CDXL,
  370. AV_CODEC_ID_XBM,
  371. AV_CODEC_ID_ZEROCODEC,
  372. AV_CODEC_ID_MSS1,
  373. AV_CODEC_ID_MSA1,
  374. AV_CODEC_ID_TSCC2,
  375. AV_CODEC_ID_MTS2,
  376. AV_CODEC_ID_CLLC,
  377. AV_CODEC_ID_MSS2,
  378. AV_CODEC_ID_VP9,
  379. AV_CODEC_ID_AIC,
  380. AV_CODEC_ID_ESCAPE130,
  381. AV_CODEC_ID_G2M,
  382. AV_CODEC_ID_WEBP,
  383. AV_CODEC_ID_HNM4_VIDEO,
  384. AV_CODEC_ID_HEVC,
  385. AV_CODEC_ID_FIC,
  386. AV_CODEC_ID_ALIAS_PIX,
  387. AV_CODEC_ID_BRENDER_PIX,
  388. AV_CODEC_ID_PAF_VIDEO,
  389. AV_CODEC_ID_EXR,
  390. AV_CODEC_ID_VP7,
  391. AV_CODEC_ID_SANM,
  392. AV_CODEC_ID_SGIRLE,
  393. AV_CODEC_ID_MVC1,
  394. AV_CODEC_ID_MVC2,
  395. AV_CODEC_ID_HQX,
  396. AV_CODEC_ID_TDSC,
  397. AV_CODEC_ID_HQ_HQA,
  398. AV_CODEC_ID_HAP,
  399. AV_CODEC_ID_DDS,
  400. AV_CODEC_ID_DXV,
  401. AV_CODEC_ID_SCREENPRESSO,
  402. AV_CODEC_ID_RSCC,
  403. AV_CODEC_ID_MAGICYUV,
  404. AV_CODEC_ID_TRUEMOTION2RT,
  405. AV_CODEC_ID_AV1,
  406. AV_CODEC_ID_PIXLET,
  407. AV_CODEC_ID_CFHD,
  408. /* various PCM "codecs" */
  409. AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
  410. AV_CODEC_ID_PCM_S16LE = 0x10000,
  411. AV_CODEC_ID_PCM_S16BE,
  412. AV_CODEC_ID_PCM_U16LE,
  413. AV_CODEC_ID_PCM_U16BE,
  414. AV_CODEC_ID_PCM_S8,
  415. AV_CODEC_ID_PCM_U8,
  416. AV_CODEC_ID_PCM_MULAW,
  417. AV_CODEC_ID_PCM_ALAW,
  418. AV_CODEC_ID_PCM_S32LE,
  419. AV_CODEC_ID_PCM_S32BE,
  420. AV_CODEC_ID_PCM_U32LE,
  421. AV_CODEC_ID_PCM_U32BE,
  422. AV_CODEC_ID_PCM_S24LE,
  423. AV_CODEC_ID_PCM_S24BE,
  424. AV_CODEC_ID_PCM_U24LE,
  425. AV_CODEC_ID_PCM_U24BE,
  426. AV_CODEC_ID_PCM_S24DAUD,
  427. AV_CODEC_ID_PCM_ZORK,
  428. AV_CODEC_ID_PCM_S16LE_PLANAR,
  429. AV_CODEC_ID_PCM_DVD,
  430. AV_CODEC_ID_PCM_F32BE,
  431. AV_CODEC_ID_PCM_F32LE,
  432. AV_CODEC_ID_PCM_F64BE,
  433. AV_CODEC_ID_PCM_F64LE,
  434. AV_CODEC_ID_PCM_BLURAY,
  435. AV_CODEC_ID_PCM_LXF,
  436. AV_CODEC_ID_S302M,
  437. AV_CODEC_ID_PCM_S8_PLANAR,
  438. AV_CODEC_ID_PCM_S24LE_PLANAR,
  439. AV_CODEC_ID_PCM_S32LE_PLANAR,
  440. AV_CODEC_ID_PCM_S16BE_PLANAR,
  441. /* various ADPCM codecs */
  442. AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,
  443. AV_CODEC_ID_ADPCM_IMA_WAV,
  444. AV_CODEC_ID_ADPCM_IMA_DK3,
  445. AV_CODEC_ID_ADPCM_IMA_DK4,
  446. AV_CODEC_ID_ADPCM_IMA_WS,
  447. AV_CODEC_ID_ADPCM_IMA_SMJPEG,
  448. AV_CODEC_ID_ADPCM_MS,
  449. AV_CODEC_ID_ADPCM_4XM,
  450. AV_CODEC_ID_ADPCM_XA,
  451. AV_CODEC_ID_ADPCM_ADX,
  452. AV_CODEC_ID_ADPCM_EA,
  453. AV_CODEC_ID_ADPCM_G726,
  454. AV_CODEC_ID_ADPCM_CT,
  455. AV_CODEC_ID_ADPCM_SWF,
  456. AV_CODEC_ID_ADPCM_YAMAHA,
  457. AV_CODEC_ID_ADPCM_SBPRO_4,
  458. AV_CODEC_ID_ADPCM_SBPRO_3,
  459. AV_CODEC_ID_ADPCM_SBPRO_2,
  460. AV_CODEC_ID_ADPCM_THP,
  461. AV_CODEC_ID_ADPCM_IMA_AMV,
  462. AV_CODEC_ID_ADPCM_EA_R1,
  463. AV_CODEC_ID_ADPCM_EA_R3,
  464. AV_CODEC_ID_ADPCM_EA_R2,
  465. AV_CODEC_ID_ADPCM_IMA_EA_SEAD,
  466. AV_CODEC_ID_ADPCM_IMA_EA_EACS,
  467. AV_CODEC_ID_ADPCM_EA_XAS,
  468. AV_CODEC_ID_ADPCM_EA_MAXIS_XA,
  469. AV_CODEC_ID_ADPCM_IMA_ISS,
  470. AV_CODEC_ID_ADPCM_G722,
  471. AV_CODEC_ID_ADPCM_IMA_APC,
  472. AV_CODEC_ID_ADPCM_VIMA,
  473. /* AMR */
  474. AV_CODEC_ID_AMR_NB = 0x12000,
  475. AV_CODEC_ID_AMR_WB,
  476. /* RealAudio codecs*/
  477. AV_CODEC_ID_RA_144 = 0x13000,
  478. AV_CODEC_ID_RA_288,
  479. /* various DPCM codecs */
  480. AV_CODEC_ID_ROQ_DPCM = 0x14000,
  481. AV_CODEC_ID_INTERPLAY_DPCM,
  482. AV_CODEC_ID_XAN_DPCM,
  483. AV_CODEC_ID_SOL_DPCM,
  484. /* audio codecs */
  485. AV_CODEC_ID_MP2 = 0x15000,
  486. AV_CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
  487. AV_CODEC_ID_AAC,
  488. AV_CODEC_ID_AC3,
  489. AV_CODEC_ID_DTS,
  490. AV_CODEC_ID_VORBIS,
  491. AV_CODEC_ID_DVAUDIO,
  492. AV_CODEC_ID_WMAV1,
  493. AV_CODEC_ID_WMAV2,
  494. AV_CODEC_ID_MACE3,
  495. AV_CODEC_ID_MACE6,
  496. AV_CODEC_ID_VMDAUDIO,
  497. AV_CODEC_ID_FLAC,
  498. AV_CODEC_ID_MP3ADU,
  499. AV_CODEC_ID_MP3ON4,
  500. AV_CODEC_ID_SHORTEN,
  501. AV_CODEC_ID_ALAC,
  502. AV_CODEC_ID_WESTWOOD_SND1,
  503. AV_CODEC_ID_GSM, ///< as in Berlin toast format
  504. AV_CODEC_ID_QDM2,
  505. AV_CODEC_ID_COOK,
  506. AV_CODEC_ID_TRUESPEECH,
  507. AV_CODEC_ID_TTA,
  508. AV_CODEC_ID_SMACKAUDIO,
  509. AV_CODEC_ID_QCELP,
  510. AV_CODEC_ID_WAVPACK,
  511. AV_CODEC_ID_DSICINAUDIO,
  512. AV_CODEC_ID_IMC,
  513. AV_CODEC_ID_MUSEPACK7,
  514. AV_CODEC_ID_MLP,
  515. AV_CODEC_ID_GSM_MS, /* as found in WAV */
  516. AV_CODEC_ID_ATRAC3,
  517. AV_CODEC_ID_APE,
  518. AV_CODEC_ID_NELLYMOSER,
  519. AV_CODEC_ID_MUSEPACK8,
  520. AV_CODEC_ID_SPEEX,
  521. AV_CODEC_ID_WMAVOICE,
  522. AV_CODEC_ID_WMAPRO,
  523. AV_CODEC_ID_WMALOSSLESS,
  524. AV_CODEC_ID_ATRAC3P,
  525. AV_CODEC_ID_EAC3,
  526. AV_CODEC_ID_SIPR,
  527. AV_CODEC_ID_MP1,
  528. AV_CODEC_ID_TWINVQ,
  529. AV_CODEC_ID_TRUEHD,
  530. AV_CODEC_ID_MP4ALS,
  531. AV_CODEC_ID_ATRAC1,
  532. AV_CODEC_ID_BINKAUDIO_RDFT,
  533. AV_CODEC_ID_BINKAUDIO_DCT,
  534. AV_CODEC_ID_AAC_LATM,
  535. AV_CODEC_ID_QDMC,
  536. AV_CODEC_ID_CELT,
  537. AV_CODEC_ID_G723_1,
  538. AV_CODEC_ID_G729,
  539. AV_CODEC_ID_8SVX_EXP,
  540. AV_CODEC_ID_8SVX_FIB,
  541. AV_CODEC_ID_BMV_AUDIO,
  542. AV_CODEC_ID_RALF,
  543. AV_CODEC_ID_IAC,
  544. AV_CODEC_ID_ILBC,
  545. AV_CODEC_ID_OPUS,
  546. AV_CODEC_ID_COMFORT_NOISE,
  547. AV_CODEC_ID_TAK,
  548. AV_CODEC_ID_METASOUND,
  549. AV_CODEC_ID_PAF_AUDIO,
  550. AV_CODEC_ID_ON2AVC,
  551. AV_CODEC_ID_DSS_SP,
  552. /* subtitle codecs */
  553. AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs.
  554. AV_CODEC_ID_DVD_SUBTITLE = 0x17000,
  555. AV_CODEC_ID_DVB_SUBTITLE,
  556. AV_CODEC_ID_TEXT, ///< raw UTF-8 text
  557. AV_CODEC_ID_XSUB,
  558. AV_CODEC_ID_SSA,
  559. AV_CODEC_ID_MOV_TEXT,
  560. AV_CODEC_ID_HDMV_PGS_SUBTITLE,
  561. AV_CODEC_ID_DVB_TELETEXT,
  562. AV_CODEC_ID_SRT,
  563. /* other specific kind of codecs (generally used for attachments) */
  564. AV_CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs.
  565. AV_CODEC_ID_TTF = 0x18000,
  566. AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it
  567. AV_CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
  568. * stream (only used by libavformat) */
  569. AV_CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
  570. * stream (only used by libavformat) */
  571. AV_CODEC_ID_FFMETADATA = 0x21000, ///< Dummy codec for streams containing only metadata information.
  572. AV_CODEC_ID_WRAPPED_AVFRAME = 0x21001, ///< Passthrough codec, AVFrames wrapped in AVPacket
  573. };
  574. /**
  575. * This struct describes the properties of a single codec described by an
  576. * AVCodecID.
  577. * @see avcodec_descriptor_get()
  578. */
  579. typedef struct AVCodecDescriptor {
  580. enum AVCodecID id;
  581. enum AVMediaType type;
  582. /**
  583. * Name of the codec described by this descriptor. It is non-empty and
  584. * unique for each codec descriptor. It should contain alphanumeric
  585. * characters and '_' only.
  586. */
  587. const char *name;
  588. /**
  589. * A more descriptive name for this codec. May be NULL.
  590. */
  591. const char *long_name;
  592. /**
  593. * Codec properties, a combination of AV_CODEC_PROP_* flags.
  594. */
  595. int props;
  596. /**
  597. * If non-NULL, an array of profiles recognized for this codec.
  598. * Terminated with FF_PROFILE_UNKNOWN.
  599. */
  600. const struct AVProfile *profiles;
  601. } AVCodecDescriptor;
  602. /**
  603. * Codec uses only intra compression.
  604. * Video codecs only.
  605. */
  606. #define AV_CODEC_PROP_INTRA_ONLY (1 << 0)
  607. /**
  608. * Codec supports lossy compression. Audio and video codecs only.
  609. * @note a codec may support both lossy and lossless
  610. * compression modes
  611. */
  612. #define AV_CODEC_PROP_LOSSY (1 << 1)
  613. /**
  614. * Codec supports lossless compression. Audio and video codecs only.
  615. */
  616. #define AV_CODEC_PROP_LOSSLESS (1 << 2)
  617. /**
  618. * Codec supports frame reordering. That is, the coded order (the order in which
  619. * the encoded packets are output by the encoders / stored / input to the
  620. * decoders) may be different from the presentation order of the corresponding
  621. * frames.
  622. *
  623. * For codecs that do not have this property set, PTS and DTS should always be
  624. * equal.
  625. */
  626. #define AV_CODEC_PROP_REORDER (1 << 3)
  627. /**
  628. * @ingroup lavc_decoding
  629. * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
  630. * This is mainly needed because some optimized bitstream readers read
  631. * 32 or 64 bit at once and could read over the end.<br>
  632. * Note: If the first 23 bits of the additional bytes are not 0, then damaged
  633. * MPEG bitstreams could cause overread and segfault.
  634. */
  635. #define AV_INPUT_BUFFER_PADDING_SIZE 8
  636. /**
  637. * @ingroup lavc_encoding
  638. * minimum encoding buffer size
  639. * Used to avoid some checks during header writing.
  640. */
  641. #define AV_INPUT_BUFFER_MIN_SIZE 16384
  642. #if FF_API_WITHOUT_PREFIX
  643. /**
  644. * @deprecated use AV_INPUT_BUFFER_PADDING_SIZE instead
  645. */
  646. #define FF_INPUT_BUFFER_PADDING_SIZE 8
  647. /**
  648. * @deprecated use AV_INPUT_BUFFER_MIN_SIZE instead
  649. */
  650. #define FF_MIN_BUFFER_SIZE 16384
  651. #endif /* FF_API_WITHOUT_PREFIX */
  652. /**
  653. * @ingroup lavc_encoding
  654. * motion estimation type.
  655. * @deprecated use codec private option instead
  656. */
  657. #if FF_API_MOTION_EST
  658. enum Motion_Est_ID {
  659. ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed
  660. ME_FULL,
  661. ME_LOG,
  662. ME_PHODS,
  663. ME_EPZS, ///< enhanced predictive zonal search
  664. ME_X1, ///< reserved for experiments
  665. ME_HEX, ///< hexagon based search
  666. ME_UMH, ///< uneven multi-hexagon search
  667. ME_TESA, ///< transformed exhaustive search algorithm
  668. };
  669. #endif
  670. /**
  671. * @ingroup lavc_decoding
  672. */
  673. enum AVDiscard{
  674. /* We leave some space between them for extensions (drop some
  675. * keyframes for intra-only or drop just some bidir frames). */
  676. AVDISCARD_NONE =-16, ///< discard nothing
  677. AVDISCARD_DEFAULT = 0, ///< discard useless packets like 0 size packets in avi
  678. AVDISCARD_NONREF = 8, ///< discard all non reference
  679. AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
  680. AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
  681. AVDISCARD_ALL = 48, ///< discard all
  682. };
  683. enum AVAudioServiceType {
  684. AV_AUDIO_SERVICE_TYPE_MAIN = 0,
  685. AV_AUDIO_SERVICE_TYPE_EFFECTS = 1,
  686. AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2,
  687. AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED = 3,
  688. AV_AUDIO_SERVICE_TYPE_DIALOGUE = 4,
  689. AV_AUDIO_SERVICE_TYPE_COMMENTARY = 5,
  690. AV_AUDIO_SERVICE_TYPE_EMERGENCY = 6,
  691. AV_AUDIO_SERVICE_TYPE_VOICE_OVER = 7,
  692. AV_AUDIO_SERVICE_TYPE_KARAOKE = 8,
  693. AV_AUDIO_SERVICE_TYPE_NB , ///< Not part of ABI
  694. };
  695. /**
  696. * @ingroup lavc_encoding
  697. */
  698. typedef struct RcOverride{
  699. int start_frame;
  700. int end_frame;
  701. int qscale; // If this is 0 then quality_factor will be used instead.
  702. float quality_factor;
  703. } RcOverride;
  704. #if FF_API_MAX_BFRAMES
  705. /**
  706. * @deprecated there is no libavcodec-wide limit on the number of B-frames
  707. */
  708. #define FF_MAX_B_FRAMES 16
  709. #endif
  710. /* encoding support
  711. These flags can be passed in AVCodecContext.flags before initialization.
  712. Note: Not everything is supported yet.
  713. */
  714. /**
  715. * Allow decoders to produce frames with data planes that are not aligned
  716. * to CPU requirements (e.g. due to cropping).
  717. */
  718. #define AV_CODEC_FLAG_UNALIGNED (1 << 0)
  719. /**
  720. * Use fixed qscale.
  721. */
  722. #define AV_CODEC_FLAG_QSCALE (1 << 1)
  723. /**
  724. * 4 MV per MB allowed / advanced prediction for H.263.
  725. */
  726. #define AV_CODEC_FLAG_4MV (1 << 2)
  727. /**
  728. * Output even those frames that might be corrupted.
  729. */
  730. #define AV_CODEC_FLAG_OUTPUT_CORRUPT (1 << 3)
  731. /**
  732. * Use qpel MC.
  733. */
  734. #define AV_CODEC_FLAG_QPEL (1 << 4)
  735. /**
  736. * Use internal 2pass ratecontrol in first pass mode.
  737. */
  738. #define AV_CODEC_FLAG_PASS1 (1 << 9)
  739. /**
  740. * Use internal 2pass ratecontrol in second pass mode.
  741. */
  742. #define AV_CODEC_FLAG_PASS2 (1 << 10)
  743. /**
  744. * loop filter.
  745. */
  746. #define AV_CODEC_FLAG_LOOP_FILTER (1 << 11)
  747. /**
  748. * Only decode/encode grayscale.
  749. */
  750. #define AV_CODEC_FLAG_GRAY (1 << 13)
  751. /**
  752. * error[?] variables will be set during encoding.
  753. */
  754. #define AV_CODEC_FLAG_PSNR (1 << 15)
  755. /**
  756. * Input bitstream might be truncated at a random location
  757. * instead of only at frame boundaries.
  758. */
  759. #define AV_CODEC_FLAG_TRUNCATED (1 << 16)
  760. /**
  761. * Use interlaced DCT.
  762. */
  763. #define AV_CODEC_FLAG_INTERLACED_DCT (1 << 18)
  764. /**
  765. * Force low delay.
  766. */
  767. #define AV_CODEC_FLAG_LOW_DELAY (1 << 19)
  768. /**
  769. * Place global headers in extradata instead of every keyframe.
  770. */
  771. #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
  772. /**
  773. * Use only bitexact stuff (except (I)DCT).
  774. */
  775. #define AV_CODEC_FLAG_BITEXACT (1 << 23)
  776. /* Fx : Flag for H.263+ extra options */
  777. /**
  778. * H.263 advanced intra coding / MPEG-4 AC prediction
  779. */
  780. #define AV_CODEC_FLAG_AC_PRED (1 << 24)
  781. /**
  782. * interlaced motion estimation
  783. */
  784. #define AV_CODEC_FLAG_INTERLACED_ME (1 << 29)
  785. #define AV_CODEC_FLAG_CLOSED_GOP (1 << 31)
  786. /**
  787. * Allow non spec compliant speedup tricks.
  788. */
  789. #define AV_CODEC_FLAG2_FAST (1 << 0)
  790. /**
  791. * Skip bitstream encoding.
  792. */
  793. #define AV_CODEC_FLAG2_NO_OUTPUT (1 << 2)
  794. /**
  795. * Place global headers at every keyframe instead of in extradata.
  796. */
  797. #define AV_CODEC_FLAG2_LOCAL_HEADER (1 << 3)
  798. /**
  799. * Input bitstream might be truncated at a packet boundaries
  800. * instead of only at frame boundaries.
  801. */
  802. #define AV_CODEC_FLAG2_CHUNKS (1 << 15)
  803. /**
  804. * Discard cropping information from SPS.
  805. */
  806. #define AV_CODEC_FLAG2_IGNORE_CROP (1 << 16)
  807. /* Unsupported options :
  808. * Syntax Arithmetic coding (SAC)
  809. * Reference Picture Selection
  810. * Independent Segment Decoding */
  811. /* /Fx */
  812. /* codec capabilities */
  813. /**
  814. * Decoder can use draw_horiz_band callback.
  815. */
  816. #define AV_CODEC_CAP_DRAW_HORIZ_BAND (1 << 0)
  817. /**
  818. * Codec uses get_buffer() for allocating buffers and supports custom allocators.
  819. * If not set, it might not use get_buffer() at all or use operations that
  820. * assume the buffer was allocated by avcodec_default_get_buffer.
  821. */
  822. #define AV_CODEC_CAP_DR1 (1 << 1)
  823. #define AV_CODEC_CAP_TRUNCATED (1 << 3)
  824. /**
  825. * Encoder or decoder requires flushing with NULL input at the end in order to
  826. * give the complete and correct output.
  827. *
  828. * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
  829. * with NULL data. The user can still send NULL data to the public encode
  830. * or decode function, but libavcodec will not pass it along to the codec
  831. * unless this flag is set.
  832. *
  833. * Decoders:
  834. * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
  835. * avpkt->size=0 at the end to get the delayed data until the decoder no longer
  836. * returns frames.
  837. *
  838. * Encoders:
  839. * The encoder needs to be fed with NULL data at the end of encoding until the
  840. * encoder no longer returns data.
  841. *
  842. * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
  843. * flag also means that the encoder must set the pts and duration for
  844. * each output packet. If this flag is not set, the pts and duration will
  845. * be determined by libavcodec from the input frame.
  846. */
  847. #define AV_CODEC_CAP_DELAY (1 << 5)
  848. /**
  849. * Codec can be fed a final frame with a smaller size.
  850. * This can be used to prevent truncation of the last audio samples.
  851. */
  852. #define AV_CODEC_CAP_SMALL_LAST_FRAME (1 << 6)
  853. /**
  854. * Codec can output multiple frames per AVPacket
  855. * Normally demuxers return one frame at a time, demuxers which do not do
  856. * are connected to a parser to split what they return into proper frames.
  857. * This flag is reserved to the very rare category of codecs which have a
  858. * bitstream that cannot be split into frames without timeconsuming
  859. * operations like full decoding. Demuxers carrying such bitstreams thus
  860. * may return multiple frames in a packet. This has many disadvantages like
  861. * prohibiting stream copy in many cases thus it should only be considered
  862. * as a last resort.
  863. */
  864. #define AV_CODEC_CAP_SUBFRAMES (1 << 8)
  865. /**
  866. * Codec is experimental and is thus avoided in favor of non experimental
  867. * encoders
  868. */
  869. #define AV_CODEC_CAP_EXPERIMENTAL (1 << 9)
  870. /**
  871. * Codec should fill in channel configuration and samplerate instead of container
  872. */
  873. #define AV_CODEC_CAP_CHANNEL_CONF (1 << 10)
  874. /**
  875. * Codec supports frame-level multithreading.
  876. */
  877. #define AV_CODEC_CAP_FRAME_THREADS (1 << 12)
  878. /**
  879. * Codec supports slice-based (or partition-based) multithreading.
  880. */
  881. #define AV_CODEC_CAP_SLICE_THREADS (1 << 13)
  882. /**
  883. * Codec supports changed parameters at any point.
  884. */
  885. #define AV_CODEC_CAP_PARAM_CHANGE (1 << 14)
  886. /**
  887. * Codec supports avctx->thread_count == 0 (auto).
  888. */
  889. #define AV_CODEC_CAP_AUTO_THREADS (1 << 15)
  890. /**
  891. * Audio encoder supports receiving a different number of samples in each call.
  892. */
  893. #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE (1 << 16)
  894. #if FF_API_WITHOUT_PREFIX
  895. /**
  896. * Allow decoders to produce frames with data planes that are not aligned
  897. * to CPU requirements (e.g. due to cropping).
  898. */
  899. #define CODEC_FLAG_UNALIGNED 0x0001
  900. #define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale.
  901. #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263.
  902. #define CODEC_FLAG_OUTPUT_CORRUPT 0x0008 ///< Output even those frames that might be corrupted
  903. #define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
  904. #if FF_API_GMC
  905. /**
  906. * @deprecated use the "gmc" private option of the libxvid encoder
  907. */
  908. #define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
  909. #endif
  910. #if FF_API_MV0
  911. /**
  912. * @deprecated use the flag "mv0" in the "mpv_flags" private option of the
  913. * mpegvideo encoders
  914. */
  915. #define CODEC_FLAG_MV0 0x0040
  916. #endif
  917. #if FF_API_INPUT_PRESERVED
  918. /**
  919. * @deprecated passing reference-counted frames to the encoders replaces this
  920. * flag
  921. */
  922. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  923. #endif
  924. #define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
  925. #define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
  926. #define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
  927. #if FF_API_EMU_EDGE
  928. /**
  929. * @deprecated edges are not used/required anymore. I.e. this flag is now always
  930. * set.
  931. */
  932. #define CODEC_FLAG_EMU_EDGE 0x4000
  933. #endif
  934. #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
  935. #define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random
  936. location instead of only at frame boundaries. */
  937. #if FF_API_NORMALIZE_AQP
  938. /**
  939. * @deprecated use the flag "naq" in the "mpv_flags" private option of the
  940. * mpegvideo encoders
  941. */
  942. #define CODEC_FLAG_NORMALIZE_AQP 0x00020000
  943. #endif
  944. #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
  945. #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
  946. #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
  947. #define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
  948. /* Fx : Flag for H.263+ extra options */
  949. #define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
  950. #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
  951. #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
  952. #define CODEC_FLAG_CLOSED_GOP 0x80000000
  953. #define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
  954. #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
  955. #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
  956. #define CODEC_FLAG2_IGNORE_CROP 0x00010000 ///< Discard cropping information from SPS.
  957. #define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
  958. /* Unsupported options :
  959. * Syntax Arithmetic coding (SAC)
  960. * Reference Picture Selection
  961. * Independent Segment Decoding */
  962. /* /Fx */
  963. /* codec capabilities */
  964. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
  965. /**
  966. * Codec uses get_buffer() for allocating buffers and supports custom allocators.
  967. * If not set, it might not use get_buffer() at all or use operations that
  968. * assume the buffer was allocated by avcodec_default_get_buffer.
  969. */
  970. #define CODEC_CAP_DR1 0x0002
  971. #define CODEC_CAP_TRUNCATED 0x0008
  972. #if FF_API_XVMC
  973. /* Codec can export data for HW decoding (XvMC). */
  974. #define CODEC_CAP_HWACCEL 0x0010
  975. #endif /* FF_API_XVMC */
  976. /**
  977. * Encoder or decoder requires flushing with NULL input at the end in order to
  978. * give the complete and correct output.
  979. *
  980. * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
  981. * with NULL data. The user can still send NULL data to the public encode
  982. * or decode function, but libavcodec will not pass it along to the codec
  983. * unless this flag is set.
  984. *
  985. * Decoders:
  986. * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
  987. * avpkt->size=0 at the end to get the delayed data until the decoder no longer
  988. * returns frames.
  989. *
  990. * Encoders:
  991. * The encoder needs to be fed with NULL data at the end of encoding until the
  992. * encoder no longer returns data.
  993. *
  994. * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
  995. * flag also means that the encoder must set the pts and duration for
  996. * each output packet. If this flag is not set, the pts and duration will
  997. * be determined by libavcodec from the input frame.
  998. */
  999. #define CODEC_CAP_DELAY 0x0020
  1000. /**
  1001. * Codec can be fed a final frame with a smaller size.
  1002. * This can be used to prevent truncation of the last audio samples.
  1003. */
  1004. #define CODEC_CAP_SMALL_LAST_FRAME 0x0040
  1005. /**
  1006. * Codec can output multiple frames per AVPacket
  1007. * Normally demuxers return one frame at a time, demuxers which do not do
  1008. * are connected to a parser to split what they return into proper frames.
  1009. * This flag is reserved to the very rare category of codecs which have a
  1010. * bitstream that cannot be split into frames without timeconsuming
  1011. * operations like full decoding. Demuxers carrying such bitstreams thus
  1012. * may return multiple frames in a packet. This has many disadvantages like
  1013. * prohibiting stream copy in many cases thus it should only be considered
  1014. * as a last resort.
  1015. */
  1016. #define CODEC_CAP_SUBFRAMES 0x0100
  1017. /**
  1018. * Codec is experimental and is thus avoided in favor of non experimental
  1019. * encoders
  1020. */
  1021. #define CODEC_CAP_EXPERIMENTAL 0x0200
  1022. /**
  1023. * Codec should fill in channel configuration and samplerate instead of container
  1024. */
  1025. #define CODEC_CAP_CHANNEL_CONF 0x0400
  1026. #if FF_API_NEG_LINESIZES
  1027. /**
  1028. * @deprecated no codecs use this capability
  1029. */
  1030. #define CODEC_CAP_NEG_LINESIZES 0x0800
  1031. #endif
  1032. /**
  1033. * Codec supports frame-level multithreading.
  1034. */
  1035. #define CODEC_CAP_FRAME_THREADS 0x1000
  1036. /**
  1037. * Codec supports slice-based (or partition-based) multithreading.
  1038. */
  1039. #define CODEC_CAP_SLICE_THREADS 0x2000
  1040. /**
  1041. * Codec supports changed parameters at any point.
  1042. */
  1043. #define CODEC_CAP_PARAM_CHANGE 0x4000
  1044. /**
  1045. * Codec supports avctx->thread_count == 0 (auto).
  1046. */
  1047. #define CODEC_CAP_AUTO_THREADS 0x8000
  1048. /**
  1049. * Audio encoder supports receiving a different number of samples in each call.
  1050. */
  1051. #define CODEC_CAP_VARIABLE_FRAME_SIZE 0x10000
  1052. #endif /* FF_API_WITHOUT_PREFIX */
  1053. #if FF_API_MB_TYPE
  1054. //The following defines may change, don't expect compatibility if you use them.
  1055. #define MB_TYPE_INTRA4x4 0x0001
  1056. #define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
  1057. #define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific
  1058. #define MB_TYPE_16x16 0x0008
  1059. #define MB_TYPE_16x8 0x0010
  1060. #define MB_TYPE_8x16 0x0020
  1061. #define MB_TYPE_8x8 0x0040
  1062. #define MB_TYPE_INTERLACED 0x0080
  1063. #define MB_TYPE_DIRECT2 0x0100 //FIXME
  1064. #define MB_TYPE_ACPRED 0x0200
  1065. #define MB_TYPE_GMC 0x0400
  1066. #define MB_TYPE_SKIP 0x0800
  1067. #define MB_TYPE_P0L0 0x1000
  1068. #define MB_TYPE_P1L0 0x2000
  1069. #define MB_TYPE_P0L1 0x4000
  1070. #define MB_TYPE_P1L1 0x8000
  1071. #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
  1072. #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
  1073. #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
  1074. #define MB_TYPE_QUANT 0x00010000
  1075. #define MB_TYPE_CBP 0x00020000
  1076. // Note bits 24-31 are reserved for codec specific use (H.264 ref0, MPEG-1 0mv, ...)
  1077. #endif
  1078. /**
  1079. * Pan Scan area.
  1080. * This specifies the area which should be displayed.
  1081. * Note there may be multiple such areas for one frame.
  1082. */
  1083. typedef struct AVPanScan{
  1084. /**
  1085. * id
  1086. * - encoding: Set by user.
  1087. * - decoding: Set by libavcodec.
  1088. */
  1089. int id;
  1090. /**
  1091. * width and height in 1/16 pel
  1092. * - encoding: Set by user.
  1093. * - decoding: Set by libavcodec.
  1094. */
  1095. int width;
  1096. int height;
  1097. /**
  1098. * position of the top left corner in 1/16 pel for up to 3 fields/frames
  1099. * - encoding: Set by user.
  1100. * - decoding: Set by libavcodec.
  1101. */
  1102. int16_t position[3][2];
  1103. }AVPanScan;
  1104. /**
  1105. * This structure describes the bitrate properties of an encoded bitstream. It
  1106. * roughly corresponds to a subset the VBV parameters for MPEG-2 or HRD
  1107. * parameters for H.264/HEVC.
  1108. */
  1109. typedef struct AVCPBProperties {
  1110. /**
  1111. * Maximum bitrate of the stream, in bits per second.
  1112. * Zero if unknown or unspecified.
  1113. */
  1114. int max_bitrate;
  1115. /**
  1116. * Minimum bitrate of the stream, in bits per second.
  1117. * Zero if unknown or unspecified.
  1118. */
  1119. int min_bitrate;
  1120. /**
  1121. * Average bitrate of the stream, in bits per second.
  1122. * Zero if unknown or unspecified.
  1123. */
  1124. int avg_bitrate;
  1125. /**
  1126. * The size of the buffer to which the ratecontrol is applied, in bits.
  1127. * Zero if unknown or unspecified.
  1128. */
  1129. int buffer_size;
  1130. /**
  1131. * The delay between the time the packet this structure is associated with
  1132. * is received and the time when it should be decoded, in periods of a 27MHz
  1133. * clock.
  1134. *
  1135. * UINT64_MAX when unknown or unspecified.
  1136. */
  1137. uint64_t vbv_delay;
  1138. } AVCPBProperties;
  1139. #if FF_API_QSCALE_TYPE
  1140. #define FF_QSCALE_TYPE_MPEG1 0
  1141. #define FF_QSCALE_TYPE_MPEG2 1
  1142. #define FF_QSCALE_TYPE_H264 2
  1143. #define FF_QSCALE_TYPE_VP56 3
  1144. #endif
  1145. /**
  1146. * The decoder will keep a reference to the frame and may reuse it later.
  1147. */
  1148. #define AV_GET_BUFFER_FLAG_REF (1 << 0)
  1149. /**
  1150. * @defgroup lavc_packet AVPacket
  1151. *
  1152. * Types and functions for working with AVPacket.
  1153. * @{
  1154. */
  1155. enum AVPacketSideDataType {
  1156. /**
  1157. * An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE
  1158. * bytes worth of palette. This side data signals that a new palette is
  1159. * present.
  1160. */
  1161. AV_PKT_DATA_PALETTE,
  1162. /**
  1163. * The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format
  1164. * that the extradata buffer was changed and the receiving side should
  1165. * act upon it appropriately. The new extradata is embedded in the side
  1166. * data buffer and should be immediately used for processing the current
  1167. * frame or packet.
  1168. */
  1169. AV_PKT_DATA_NEW_EXTRADATA,
  1170. /**
  1171. * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
  1172. * @code
  1173. * u32le param_flags
  1174. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
  1175. * s32le channel_count
  1176. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
  1177. * u64le channel_layout
  1178. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
  1179. * s32le sample_rate
  1180. * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
  1181. * s32le width
  1182. * s32le height
  1183. * @endcode
  1184. */
  1185. AV_PKT_DATA_PARAM_CHANGE,
  1186. /**
  1187. * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
  1188. * structures with info about macroblocks relevant to splitting the
  1189. * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
  1190. * That is, it does not necessarily contain info about all macroblocks,
  1191. * as long as the distance between macroblocks in the info is smaller
  1192. * than the target payload size.
  1193. * Each MB info structure is 12 bytes, and is laid out as follows:
  1194. * @code
  1195. * u32le bit offset from the start of the packet
  1196. * u8 current quantizer at the start of the macroblock
  1197. * u8 GOB number
  1198. * u16le macroblock address within the GOB
  1199. * u8 horizontal MV predictor
  1200. * u8 vertical MV predictor
  1201. * u8 horizontal MV predictor for block number 3
  1202. * u8 vertical MV predictor for block number 3
  1203. * @endcode
  1204. */
  1205. AV_PKT_DATA_H263_MB_INFO,
  1206. /**
  1207. * This side data should be associated with an audio stream and contains
  1208. * ReplayGain information in form of the AVReplayGain struct.
  1209. */
  1210. AV_PKT_DATA_REPLAYGAIN,
  1211. /**
  1212. * This side data contains a 3x3 transformation matrix describing an affine
  1213. * transformation that needs to be applied to the decoded video frames for
  1214. * correct presentation.
  1215. *
  1216. * See libavutil/display.h for a detailed description of the data.
  1217. */
  1218. AV_PKT_DATA_DISPLAYMATRIX,
  1219. /**
  1220. * This side data should be associated with a video stream and contains
  1221. * Stereoscopic 3D information in form of the AVStereo3D struct.
  1222. */
  1223. AV_PKT_DATA_STEREO3D,
  1224. /**
  1225. * This side data should be associated with an audio stream and corresponds
  1226. * to enum AVAudioServiceType.
  1227. */
  1228. AV_PKT_DATA_AUDIO_SERVICE_TYPE,
  1229. /**
  1230. * This side data contains an integer value representing the quality
  1231. * factor of the compressed frame. Allowed range is between 1 (good)
  1232. * and FF_LAMBDA_MAX (bad).
  1233. */
  1234. AV_PKT_DATA_QUALITY_FACTOR,
  1235. /**
  1236. * This side data contains an integer value representing the stream index
  1237. * of a "fallback" track. A fallback track indicates an alternate
  1238. * track to use when the current track can not be decoded for some reason.
  1239. * e.g. no decoder available for codec.
  1240. */
  1241. AV_PKT_DATA_FALLBACK_TRACK,
  1242. /**
  1243. * This side data corresponds to the AVCPBProperties struct.
  1244. */
  1245. AV_PKT_DATA_CPB_PROPERTIES,
  1246. /**
  1247. * This side data should be associated with a video stream and corresponds
  1248. * to the AVSphericalMapping structure.
  1249. */
  1250. AV_PKT_DATA_SPHERICAL,
  1251. };
  1252. typedef struct AVPacketSideData {
  1253. uint8_t *data;
  1254. int size;
  1255. enum AVPacketSideDataType type;
  1256. } AVPacketSideData;
  1257. /**
  1258. * This structure stores compressed data. It is typically exported by demuxers
  1259. * and then passed as input to decoders, or received as output from encoders and
  1260. * then passed to muxers.
  1261. *
  1262. * For video, it should typically contain one compressed frame. For audio it may
  1263. * contain several compressed frames. Encoders are allowed to output empty
  1264. * packets, with no compressed data, containing only side data
  1265. * (e.g. to update some stream parameters at the end of encoding).
  1266. *
  1267. * AVPacket is one of the few structs in Libav, whose size is a part of public
  1268. * ABI. Thus it may be allocated on stack and no new fields can be added to it
  1269. * without libavcodec and libavformat major bump.
  1270. *
  1271. * The semantics of data ownership depends on the buf field.
  1272. * If it is set, the packet data is dynamically allocated and is
  1273. * valid indefinitely until a call to av_packet_unref() reduces the
  1274. * reference count to 0.
  1275. *
  1276. * If the buf field is not set av_packet_ref() would make a copy instead
  1277. * of increasing the reference count.
  1278. *
  1279. * The side data is always allocated with av_malloc(), copied by
  1280. * av_packet_ref() and freed by av_packet_unref().
  1281. *
  1282. * @see av_packet_ref
  1283. * @see av_packet_unref
  1284. */
  1285. typedef struct AVPacket {
  1286. /**
  1287. * A reference to the reference-counted buffer where the packet data is
  1288. * stored.
  1289. * May be NULL, then the packet data is not reference-counted.
  1290. */
  1291. AVBufferRef *buf;
  1292. /**
  1293. * Presentation timestamp in AVStream->time_base units; the time at which
  1294. * the decompressed packet will be presented to the user.
  1295. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  1296. * pts MUST be larger or equal to dts as presentation cannot happen before
  1297. * decompression, unless one wants to view hex dumps. Some formats misuse
  1298. * the terms dts and pts/cts to mean something different. Such timestamps
  1299. * must be converted to true pts/dts before they are stored in AVPacket.
  1300. */
  1301. int64_t pts;
  1302. /**
  1303. * Decompression timestamp in AVStream->time_base units; the time at which
  1304. * the packet is decompressed.
  1305. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  1306. */
  1307. int64_t dts;
  1308. uint8_t *data;
  1309. int size;
  1310. int stream_index;
  1311. /**
  1312. * A combination of AV_PKT_FLAG values
  1313. */
  1314. int flags;
  1315. /**
  1316. * Additional packet data that can be provided by the container.
  1317. * Packet can contain several types of side information.
  1318. */
  1319. AVPacketSideData *side_data;
  1320. int side_data_elems;
  1321. /**
  1322. * Duration of this packet in AVStream->time_base units, 0 if unknown.
  1323. * Equals next_pts - this_pts in presentation order.
  1324. */
  1325. int64_t duration;
  1326. int64_t pos; ///< byte position in stream, -1 if unknown
  1327. #if FF_API_CONVERGENCE_DURATION
  1328. /**
  1329. * @deprecated Same as the duration field, but as int64_t. This was required
  1330. * for Matroska subtitles, whose duration values could overflow when the
  1331. * duration field was still an int.
  1332. */
  1333. attribute_deprecated
  1334. int64_t convergence_duration;
  1335. #endif
  1336. } AVPacket;
  1337. #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
  1338. #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
  1339. enum AVSideDataParamChangeFlags {
  1340. AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001,
  1341. AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
  1342. AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004,
  1343. AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
  1344. };
  1345. /**
  1346. * @}
  1347. */
  1348. struct AVCodecInternal;
  1349. enum AVFieldOrder {
  1350. AV_FIELD_UNKNOWN,
  1351. AV_FIELD_PROGRESSIVE,
  1352. AV_FIELD_TT, //< Top coded_first, top displayed first
  1353. AV_FIELD_BB, //< Bottom coded first, bottom displayed first
  1354. AV_FIELD_TB, //< Top coded first, bottom displayed first
  1355. AV_FIELD_BT, //< Bottom coded first, top displayed first
  1356. };
  1357. /**
  1358. * main external API structure.
  1359. * New fields can be added to the end with minor version bumps.
  1360. * Removal, reordering and changes to existing fields require a major
  1361. * version bump.
  1362. * sizeof(AVCodecContext) must not be used outside libav*.
  1363. */
  1364. typedef struct AVCodecContext {
  1365. /**
  1366. * information on struct for av_log
  1367. * - set by avcodec_alloc_context3
  1368. */
  1369. const AVClass *av_class;
  1370. int log_level_offset;
  1371. enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
  1372. const struct AVCodec *codec;
  1373. #if FF_API_CODEC_NAME
  1374. /**
  1375. * @deprecated this field is not used for anything in libavcodec
  1376. */
  1377. attribute_deprecated
  1378. char codec_name[32];
  1379. #endif
  1380. enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
  1381. /**
  1382. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  1383. * This is used to work around some encoder bugs.
  1384. * A demuxer should set this to what is stored in the field used to identify the codec.
  1385. * If there are multiple such fields in a container then the demuxer should choose the one
  1386. * which maximizes the information about the used codec.
  1387. * If the codec tag field in a container is larger than 32 bits then the demuxer should
  1388. * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
  1389. * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
  1390. * first.
  1391. * - encoding: Set by user, if not then the default based on codec_id will be used.
  1392. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  1393. */
  1394. unsigned int codec_tag;
  1395. #if FF_API_STREAM_CODEC_TAG
  1396. /**
  1397. * @deprecated this field is unused
  1398. */
  1399. attribute_deprecated
  1400. unsigned int stream_codec_tag;
  1401. #endif
  1402. void *priv_data;
  1403. /**
  1404. * Private context used for internal data.
  1405. *
  1406. * Unlike priv_data, this is not codec-specific. It is used in general
  1407. * libavcodec functions.
  1408. */
  1409. struct AVCodecInternal *internal;
  1410. /**
  1411. * Private data of the user, can be used to carry app specific stuff.
  1412. * - encoding: Set by user.
  1413. * - decoding: Set by user.
  1414. */
  1415. void *opaque;
  1416. /**
  1417. * the average bitrate
  1418. * - encoding: Set by user; unused for constant quantizer encoding.
  1419. * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
  1420. */
  1421. int bit_rate;
  1422. /**
  1423. * number of bits the bitstream is allowed to diverge from the reference.
  1424. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  1425. * - encoding: Set by user; unused for constant quantizer encoding.
  1426. * - decoding: unused
  1427. */
  1428. int bit_rate_tolerance;
  1429. /**
  1430. * Global quality for codecs which cannot change it per frame.
  1431. * This should be proportional to MPEG-1/2/4 qscale.
  1432. * - encoding: Set by user.
  1433. * - decoding: unused
  1434. */
  1435. int global_quality;
  1436. /**
  1437. * - encoding: Set by user.
  1438. * - decoding: unused
  1439. */
  1440. int compression_level;
  1441. #define FF_COMPRESSION_DEFAULT -1
  1442. /**
  1443. * AV_CODEC_FLAG_*.
  1444. * - encoding: Set by user.
  1445. * - decoding: Set by user.
  1446. */
  1447. int flags;
  1448. /**
  1449. * AV_CODEC_FLAG2_*
  1450. * - encoding: Set by user.
  1451. * - decoding: Set by user.
  1452. */
  1453. int flags2;
  1454. /**
  1455. * some codecs need / can use extradata like Huffman tables.
  1456. * MJPEG: Huffman tables
  1457. * rv10: additional flags
  1458. * MPEG-4: global headers (they can be in the bitstream or here)
  1459. * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
  1460. * than extradata_size to avoid problems if it is read with the bitstream reader.
  1461. * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
  1462. * - encoding: Set/allocated/freed by libavcodec.
  1463. * - decoding: Set/allocated/freed by user.
  1464. */
  1465. uint8_t *extradata;
  1466. int extradata_size;
  1467. /**
  1468. * This is the fundamental unit of time (in seconds) in terms
  1469. * of which frame timestamps are represented. For fixed-fps content,
  1470. * timebase should be 1/framerate and timestamp increments should be
  1471. * identically 1.
  1472. * - encoding: MUST be set by user.
  1473. * - decoding: the use of this field for decoding is deprecated.
  1474. * Use framerate instead.
  1475. */
  1476. AVRational time_base;
  1477. /**
  1478. * For some codecs, the time base is closer to the field rate than the frame rate.
  1479. * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
  1480. * if no telecine is used ...
  1481. *
  1482. * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
  1483. */
  1484. int ticks_per_frame;
  1485. /**
  1486. * Codec delay.
  1487. *
  1488. * Video:
  1489. * Number of frames the decoded output will be delayed relative to the
  1490. * encoded input.
  1491. *
  1492. * Audio:
  1493. * For encoding, this field is unused (see initial_padding).
  1494. *
  1495. * For decoding, this is the number of samples the decoder needs to
  1496. * output before the decoder's output is valid. When seeking, you should
  1497. * start decoding this many samples prior to your desired seek point.
  1498. *
  1499. * - encoding: Set by libavcodec.
  1500. * - decoding: Set by libavcodec.
  1501. */
  1502. int delay;
  1503. /* video only */
  1504. /**
  1505. * picture width / height.
  1506. *
  1507. * @note Those fields may not match the values of the last
  1508. * AVFrame output by avcodec_decode_video2 due frame
  1509. * reordering.
  1510. *
  1511. * - encoding: MUST be set by user.
  1512. * - decoding: May be set by the user before opening the decoder if known e.g.
  1513. * from the container. Some decoders will require the dimensions
  1514. * to be set by the caller. During decoding, the decoder may
  1515. * overwrite those values as required while parsing the data.
  1516. */
  1517. int width, height;
  1518. /**
  1519. * Bitstream width / height, may be different from width/height e.g. when
  1520. * the decoded frame is cropped before being output.
  1521. *
  1522. * @note Those field may not match the value of the last
  1523. * AVFrame output by avcodec_receive_frame() due frame
  1524. * reordering.
  1525. *
  1526. * - encoding: unused
  1527. * - decoding: May be set by the user before opening the decoder if known
  1528. * e.g. from the container. During decoding, the decoder may
  1529. * overwrite those values as required while parsing the data.
  1530. */
  1531. int coded_width, coded_height;
  1532. #if FF_API_ASPECT_EXTENDED
  1533. #define FF_ASPECT_EXTENDED 15
  1534. #endif
  1535. /**
  1536. * the number of pictures in a group of pictures, or 0 for intra_only
  1537. * - encoding: Set by user.
  1538. * - decoding: unused
  1539. */
  1540. int gop_size;
  1541. /**
  1542. * Pixel format, see AV_PIX_FMT_xxx.
  1543. * May be set by the demuxer if known from headers.
  1544. * May be overridden by the decoder if it knows better.
  1545. *
  1546. * @note This field may not match the value of the last
  1547. * AVFrame output by avcodec_receive_frame() due frame
  1548. * reordering.
  1549. *
  1550. * - encoding: Set by user.
  1551. * - decoding: Set by user if known, overridden by libavcodec while
  1552. * parsing the data.
  1553. */
  1554. enum AVPixelFormat pix_fmt;
  1555. #if FF_API_MOTION_EST
  1556. /**
  1557. * This option does nothing
  1558. * @deprecated use codec private options instead
  1559. */
  1560. attribute_deprecated int me_method;
  1561. #endif
  1562. /**
  1563. * If non NULL, 'draw_horiz_band' is called by the libavcodec
  1564. * decoder to draw a horizontal band. It improves cache usage. Not
  1565. * all codecs can do that. You must check the codec capabilities
  1566. * beforehand.
  1567. * When multithreading is used, it may be called from multiple threads
  1568. * at the same time; threads might draw different parts of the same AVFrame,
  1569. * or multiple AVFrames, and there is no guarantee that slices will be drawn
  1570. * in order.
  1571. * The function is also used by hardware acceleration APIs.
  1572. * It is called at least once during frame decoding to pass
  1573. * the data needed for hardware render.
  1574. * In that mode instead of pixel data, AVFrame points to
  1575. * a structure specific to the acceleration API. The application
  1576. * reads the structure and can change some fields to indicate progress
  1577. * or mark state.
  1578. * - encoding: unused
  1579. * - decoding: Set by user.
  1580. * @param height the height of the slice
  1581. * @param y the y position of the slice
  1582. * @param type 1->top field, 2->bottom field, 3->frame
  1583. * @param offset offset into the AVFrame.data from which the slice should be read
  1584. */
  1585. void (*draw_horiz_band)(struct AVCodecContext *s,
  1586. const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
  1587. int y, int type, int height);
  1588. /**
  1589. * callback to negotiate the pixelFormat
  1590. * @param fmt is the list of formats which are supported by the codec,
  1591. * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
  1592. * The first is always the native one.
  1593. * @note The callback may be called again immediately if initialization for
  1594. * the selected (hardware-accelerated) pixel format failed.
  1595. * @warning Behavior is undefined if the callback returns a value not
  1596. * in the fmt list of formats.
  1597. * @return the chosen format
  1598. * - encoding: unused
  1599. * - decoding: Set by user, if not set the native format will be chosen.
  1600. */
  1601. enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  1602. /**
  1603. * maximum number of B-frames between non-B-frames
  1604. * Note: The output will be delayed by max_b_frames+1 relative to the input.
  1605. * - encoding: Set by user.
  1606. * - decoding: unused
  1607. */
  1608. int max_b_frames;
  1609. /**
  1610. * qscale factor between IP and B-frames
  1611. * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
  1612. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  1613. * - encoding: Set by user.
  1614. * - decoding: unused
  1615. */
  1616. float b_quant_factor;
  1617. #if FF_API_RC_STRATEGY
  1618. /** @deprecated use codec private option instead */
  1619. attribute_deprecated int rc_strategy;
  1620. #define FF_RC_STRATEGY_XVID 1
  1621. #endif
  1622. #if FF_API_PRIVATE_OPT
  1623. /** @deprecated use encoder private options instead */
  1624. attribute_deprecated
  1625. int b_frame_strategy;
  1626. #endif
  1627. /**
  1628. * qscale offset between IP and B-frames
  1629. * - encoding: Set by user.
  1630. * - decoding: unused
  1631. */
  1632. float b_quant_offset;
  1633. /**
  1634. * Size of the frame reordering buffer in the decoder.
  1635. * For MPEG-2 it is 1 IPB or 0 low delay IP.
  1636. * - encoding: Set by libavcodec.
  1637. * - decoding: Set by libavcodec.
  1638. */
  1639. int has_b_frames;
  1640. #if FF_API_PRIVATE_OPT
  1641. /** @deprecated use encoder private options instead */
  1642. attribute_deprecated
  1643. int mpeg_quant;
  1644. #endif
  1645. /**
  1646. * qscale factor between P- and I-frames
  1647. * If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor + offset).
  1648. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  1649. * - encoding: Set by user.
  1650. * - decoding: unused
  1651. */
  1652. float i_quant_factor;
  1653. /**
  1654. * qscale offset between P and I-frames
  1655. * - encoding: Set by user.
  1656. * - decoding: unused
  1657. */
  1658. float i_quant_offset;
  1659. /**
  1660. * luminance masking (0-> disabled)
  1661. * - encoding: Set by user.
  1662. * - decoding: unused
  1663. */
  1664. float lumi_masking;
  1665. /**
  1666. * temporary complexity masking (0-> disabled)
  1667. * - encoding: Set by user.
  1668. * - decoding: unused
  1669. */
  1670. float temporal_cplx_masking;
  1671. /**
  1672. * spatial complexity masking (0-> disabled)
  1673. * - encoding: Set by user.
  1674. * - decoding: unused
  1675. */
  1676. float spatial_cplx_masking;
  1677. /**
  1678. * p block masking (0-> disabled)
  1679. * - encoding: Set by user.
  1680. * - decoding: unused
  1681. */
  1682. float p_masking;
  1683. /**
  1684. * darkness masking (0-> disabled)
  1685. * - encoding: Set by user.
  1686. * - decoding: unused
  1687. */
  1688. float dark_masking;
  1689. /**
  1690. * slice count
  1691. * - encoding: Set by libavcodec.
  1692. * - decoding: Set by user (or 0).
  1693. */
  1694. int slice_count;
  1695. #if FF_API_PRIVATE_OPT
  1696. /** @deprecated use encoder private options instead */
  1697. attribute_deprecated
  1698. int prediction_method;
  1699. #define FF_PRED_LEFT 0
  1700. #define FF_PRED_PLANE 1
  1701. #define FF_PRED_MEDIAN 2
  1702. #endif
  1703. /**
  1704. * slice offsets in the frame in bytes
  1705. * - encoding: Set/allocated by libavcodec.
  1706. * - decoding: Set/allocated by user (or NULL).
  1707. */
  1708. int *slice_offset;
  1709. /**
  1710. * sample aspect ratio (0 if unknown)
  1711. * That is the width of a pixel divided by the height of the pixel.
  1712. * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
  1713. * - encoding: Set by user.
  1714. * - decoding: Set by libavcodec.
  1715. */
  1716. AVRational sample_aspect_ratio;
  1717. /**
  1718. * motion estimation comparison function
  1719. * - encoding: Set by user.
  1720. * - decoding: unused
  1721. */
  1722. int me_cmp;
  1723. /**
  1724. * subpixel motion estimation comparison function
  1725. * - encoding: Set by user.
  1726. * - decoding: unused
  1727. */
  1728. int me_sub_cmp;
  1729. /**
  1730. * macroblock comparison function (not supported yet)
  1731. * - encoding: Set by user.
  1732. * - decoding: unused
  1733. */
  1734. int mb_cmp;
  1735. /**
  1736. * interlaced DCT comparison function
  1737. * - encoding: Set by user.
  1738. * - decoding: unused
  1739. */
  1740. int ildct_cmp;
  1741. #define FF_CMP_SAD 0
  1742. #define FF_CMP_SSE 1
  1743. #define FF_CMP_SATD 2
  1744. #define FF_CMP_DCT 3
  1745. #define FF_CMP_PSNR 4
  1746. #define FF_CMP_BIT 5
  1747. #define FF_CMP_RD 6
  1748. #define FF_CMP_ZERO 7
  1749. #define FF_CMP_VSAD 8
  1750. #define FF_CMP_VSSE 9
  1751. #define FF_CMP_NSSE 10
  1752. #define FF_CMP_DCTMAX 13
  1753. #define FF_CMP_DCT264 14
  1754. #define FF_CMP_CHROMA 256
  1755. /**
  1756. * ME diamond size & shape
  1757. * - encoding: Set by user.
  1758. * - decoding: unused
  1759. */
  1760. int dia_size;
  1761. /**
  1762. * amount of previous MV predictors (2a+1 x 2a+1 square)
  1763. * - encoding: Set by user.
  1764. * - decoding: unused
  1765. */
  1766. int last_predictor_count;
  1767. #if FF_API_PRIVATE_OPT
  1768. /** @deprecated use encoder private options instead */
  1769. attribute_deprecated
  1770. int pre_me;
  1771. #endif
  1772. /**
  1773. * motion estimation prepass comparison function
  1774. * - encoding: Set by user.
  1775. * - decoding: unused
  1776. */
  1777. int me_pre_cmp;
  1778. /**
  1779. * ME prepass diamond size & shape
  1780. * - encoding: Set by user.
  1781. * - decoding: unused
  1782. */
  1783. int pre_dia_size;
  1784. /**
  1785. * subpel ME quality
  1786. * - encoding: Set by user.
  1787. * - decoding: unused
  1788. */
  1789. int me_subpel_quality;
  1790. #if FF_API_AFD
  1791. /**
  1792. * DTG active format information (additional aspect ratio
  1793. * information only used in DVB MPEG-2 transport streams)
  1794. * 0 if not set.
  1795. *
  1796. * - encoding: unused
  1797. * - decoding: Set by decoder.
  1798. * @deprecated Deprecated in favor of AVSideData
  1799. */
  1800. attribute_deprecated int dtg_active_format;
  1801. #define FF_DTG_AFD_SAME 8
  1802. #define FF_DTG_AFD_4_3 9
  1803. #define FF_DTG_AFD_16_9 10
  1804. #define FF_DTG_AFD_14_9 11
  1805. #define FF_DTG_AFD_4_3_SP_14_9 13
  1806. #define FF_DTG_AFD_16_9_SP_14_9 14
  1807. #define FF_DTG_AFD_SP_4_3 15
  1808. #endif /* FF_API_AFD */
  1809. /**
  1810. * maximum motion estimation search range in subpel units
  1811. * If 0 then no limit.
  1812. *
  1813. * - encoding: Set by user.
  1814. * - decoding: unused
  1815. */
  1816. int me_range;
  1817. #if FF_API_QUANT_BIAS
  1818. /**
  1819. * @deprecated use encoder private option instead
  1820. */
  1821. attribute_deprecated int intra_quant_bias;
  1822. #define FF_DEFAULT_QUANT_BIAS 999999
  1823. /**
  1824. * @deprecated use encoder private option instead
  1825. */
  1826. attribute_deprecated int inter_quant_bias;
  1827. #endif
  1828. /**
  1829. * slice flags
  1830. * - encoding: unused
  1831. * - decoding: Set by user.
  1832. */
  1833. int slice_flags;
  1834. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  1835. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG-2 field pics)
  1836. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  1837. #if FF_API_XVMC
  1838. /**
  1839. * XVideo Motion Acceleration
  1840. * - encoding: forbidden
  1841. * - decoding: set by decoder
  1842. * @deprecated XvMC support is slated for removal.
  1843. */
  1844. attribute_deprecated int xvmc_acceleration;
  1845. #endif /* FF_API_XVMC */
  1846. /**
  1847. * macroblock decision mode
  1848. * - encoding: Set by user.
  1849. * - decoding: unused
  1850. */
  1851. int mb_decision;
  1852. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  1853. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  1854. #define FF_MB_DECISION_RD 2 ///< rate distortion
  1855. /**
  1856. * custom intra quantization matrix
  1857. * - encoding: Set by user, can be NULL.
  1858. * - decoding: Set by libavcodec.
  1859. */
  1860. uint16_t *intra_matrix;
  1861. /**
  1862. * custom inter quantization matrix
  1863. * - encoding: Set by user, can be NULL.
  1864. * - decoding: Set by libavcodec.
  1865. */
  1866. uint16_t *inter_matrix;
  1867. #if FF_API_PRIVATE_OPT
  1868. /** @deprecated use encoder private options instead */
  1869. attribute_deprecated
  1870. int scenechange_threshold;
  1871. /** @deprecated use encoder private options instead */
  1872. attribute_deprecated
  1873. int noise_reduction;
  1874. #endif
  1875. #if FF_API_MPV_OPT
  1876. /**
  1877. * @deprecated this field is unused
  1878. */
  1879. attribute_deprecated
  1880. int me_threshold;
  1881. /**
  1882. * @deprecated this field is unused
  1883. */
  1884. attribute_deprecated
  1885. int mb_threshold;
  1886. #endif
  1887. /**
  1888. * precision of the intra DC coefficient - 8
  1889. * - encoding: Set by user.
  1890. * - decoding: unused
  1891. */
  1892. int intra_dc_precision;
  1893. /**
  1894. * Number of macroblock rows at the top which are skipped.
  1895. * - encoding: unused
  1896. * - decoding: Set by user.
  1897. */
  1898. int skip_top;
  1899. /**
  1900. * Number of macroblock rows at the bottom which are skipped.
  1901. * - encoding: unused
  1902. * - decoding: Set by user.
  1903. */
  1904. int skip_bottom;
  1905. #if FF_API_MPV_OPT
  1906. /**
  1907. * @deprecated use encoder private options instead
  1908. */
  1909. attribute_deprecated
  1910. float border_masking;
  1911. #endif
  1912. /**
  1913. * minimum MB Lagrange multiplier
  1914. * - encoding: Set by user.
  1915. * - decoding: unused
  1916. */
  1917. int mb_lmin;
  1918. /**
  1919. * maximum MB Lagrange multiplier
  1920. * - encoding: Set by user.
  1921. * - decoding: unused
  1922. */
  1923. int mb_lmax;
  1924. #if FF_API_PRIVATE_OPT
  1925. /**
  1926. * @deprecated use encoder private options instead
  1927. */
  1928. attribute_deprecated
  1929. int me_penalty_compensation;
  1930. #endif
  1931. /**
  1932. * - encoding: Set by user.
  1933. * - decoding: unused
  1934. */
  1935. int bidir_refine;
  1936. #if FF_API_PRIVATE_OPT
  1937. /** @deprecated use encoder private options instead */
  1938. attribute_deprecated
  1939. int brd_scale;
  1940. #endif
  1941. /**
  1942. * minimum GOP size
  1943. * - encoding: Set by user.
  1944. * - decoding: unused
  1945. */
  1946. int keyint_min;
  1947. /**
  1948. * number of reference frames
  1949. * - encoding: Set by user.
  1950. * - decoding: Set by lavc.
  1951. */
  1952. int refs;
  1953. #if FF_API_PRIVATE_OPT
  1954. /** @deprecated use encoder private options instead */
  1955. attribute_deprecated
  1956. int chromaoffset;
  1957. #endif
  1958. #if FF_API_UNUSED_MEMBERS
  1959. /**
  1960. * Multiplied by qscale for each frame and added to scene_change_score.
  1961. * - encoding: Set by user.
  1962. * - decoding: unused
  1963. */
  1964. attribute_deprecated int scenechange_factor;
  1965. #endif
  1966. /**
  1967. * Note: Value depends upon the compare function used for fullpel ME.
  1968. * - encoding: Set by user.
  1969. * - decoding: unused
  1970. */
  1971. int mv0_threshold;
  1972. #if FF_API_PRIVATE_OPT
  1973. /** @deprecated use encoder private options instead */
  1974. attribute_deprecated
  1975. int b_sensitivity;
  1976. #endif
  1977. /**
  1978. * Chromaticity coordinates of the source primaries.
  1979. * - encoding: Set by user
  1980. * - decoding: Set by libavcodec
  1981. */
  1982. enum AVColorPrimaries color_primaries;
  1983. /**
  1984. * Color Transfer Characteristic.
  1985. * - encoding: Set by user
  1986. * - decoding: Set by libavcodec
  1987. */
  1988. enum AVColorTransferCharacteristic color_trc;
  1989. /**
  1990. * YUV colorspace type.
  1991. * - encoding: Set by user
  1992. * - decoding: Set by libavcodec
  1993. */
  1994. enum AVColorSpace colorspace;
  1995. /**
  1996. * MPEG vs JPEG YUV range.
  1997. * - encoding: Set by user
  1998. * - decoding: Set by libavcodec
  1999. */
  2000. enum AVColorRange color_range;
  2001. /**
  2002. * This defines the location of chroma samples.
  2003. * - encoding: Set by user
  2004. * - decoding: Set by libavcodec
  2005. */
  2006. enum AVChromaLocation chroma_sample_location;
  2007. /**
  2008. * Number of slices.
  2009. * Indicates number of picture subdivisions. Used for parallelized
  2010. * decoding.
  2011. * - encoding: Set by user
  2012. * - decoding: unused
  2013. */
  2014. int slices;
  2015. /** Field order
  2016. * - encoding: set by libavcodec
  2017. * - decoding: Set by libavcodec
  2018. */
  2019. enum AVFieldOrder field_order;
  2020. /* audio only */
  2021. int sample_rate; ///< samples per second
  2022. int channels; ///< number of audio channels
  2023. /**
  2024. * audio sample format
  2025. * - encoding: Set by user.
  2026. * - decoding: Set by libavcodec.
  2027. */
  2028. enum AVSampleFormat sample_fmt; ///< sample format
  2029. /* The following data should not be initialized. */
  2030. /**
  2031. * Number of samples per channel in an audio frame.
  2032. *
  2033. * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
  2034. * except the last must contain exactly frame_size samples per channel.
  2035. * May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
  2036. * frame size is not restricted.
  2037. * - decoding: may be set by some decoders to indicate constant frame size
  2038. */
  2039. int frame_size;
  2040. /**
  2041. * Frame counter, set by libavcodec.
  2042. *
  2043. * - decoding: total number of frames returned from the decoder so far.
  2044. * - encoding: total number of frames passed to the encoder so far.
  2045. *
  2046. * @note the counter is not incremented if encoding/decoding resulted in
  2047. * an error.
  2048. */
  2049. int frame_number;
  2050. /**
  2051. * number of bytes per packet if constant and known or 0
  2052. * Used by some WAV based audio codecs.
  2053. */
  2054. int block_align;
  2055. /**
  2056. * Audio cutoff bandwidth (0 means "automatic")
  2057. * - encoding: Set by user.
  2058. * - decoding: unused
  2059. */
  2060. int cutoff;
  2061. /**
  2062. * Audio channel layout.
  2063. * - encoding: set by user.
  2064. * - decoding: set by libavcodec.
  2065. */
  2066. uint64_t channel_layout;
  2067. /**
  2068. * Request decoder to use this channel layout if it can (0 for default)
  2069. * - encoding: unused
  2070. * - decoding: Set by user.
  2071. */
  2072. uint64_t request_channel_layout;
  2073. /**
  2074. * Type of service that the audio stream conveys.
  2075. * - encoding: Set by user.
  2076. * - decoding: Set by libavcodec.
  2077. */
  2078. enum AVAudioServiceType audio_service_type;
  2079. /**
  2080. * Used to request a sample format from the decoder.
  2081. * - encoding: unused.
  2082. * - decoding: Set by user.
  2083. */
  2084. enum AVSampleFormat request_sample_fmt;
  2085. /**
  2086. * This callback is called at the beginning of each frame to get data
  2087. * buffer(s) for it. There may be one contiguous buffer for all the data or
  2088. * there may be a buffer per each data plane or anything in between. What
  2089. * this means is, you may set however many entries in buf[] you feel necessary.
  2090. * Each buffer must be reference-counted using the AVBuffer API (see description
  2091. * of buf[] below).
  2092. *
  2093. * The following fields will be set in the frame before this callback is
  2094. * called:
  2095. * - format
  2096. * - width, height (video only)
  2097. * - sample_rate, channel_layout, nb_samples (audio only)
  2098. * Their values may differ from the corresponding values in
  2099. * AVCodecContext. This callback must use the frame values, not the codec
  2100. * context values, to calculate the required buffer size.
  2101. *
  2102. * This callback must fill the following fields in the frame:
  2103. * - data[]
  2104. * - linesize[]
  2105. * - extended_data:
  2106. * * if the data is planar audio with more than 8 channels, then this
  2107. * callback must allocate and fill extended_data to contain all pointers
  2108. * to all data planes. data[] must hold as many pointers as it can.
  2109. * extended_data must be allocated with av_malloc() and will be freed in
  2110. * av_frame_unref().
  2111. * * otherwise extended_data must point to data
  2112. * - buf[] must contain one or more pointers to AVBufferRef structures. Each of
  2113. * the frame's data and extended_data pointers must be contained in these. That
  2114. * is, one AVBufferRef for each allocated chunk of memory, not necessarily one
  2115. * AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(),
  2116. * and av_buffer_ref().
  2117. * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
  2118. * this callback and filled with the extra buffers if there are more
  2119. * buffers than buf[] can hold. extended_buf will be freed in
  2120. * av_frame_unref().
  2121. *
  2122. * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call
  2123. * avcodec_default_get_buffer2() instead of providing buffers allocated by
  2124. * some other means.
  2125. *
  2126. * Each data plane must be aligned to the maximum required by the target
  2127. * CPU.
  2128. *
  2129. * @see avcodec_default_get_buffer2()
  2130. *
  2131. * Video:
  2132. *
  2133. * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
  2134. * (read and/or written to if it is writable) later by libavcodec.
  2135. *
  2136. * avcodec_align_dimensions2() should be used to find the required width and
  2137. * height, as they normally need to be rounded up to the next multiple of 16.
  2138. *
  2139. * If frame multithreading is used and thread_safe_callbacks is set,
  2140. * this callback may be called from a different thread, but not from more
  2141. * than one at once. Does not need to be reentrant.
  2142. *
  2143. * @see avcodec_align_dimensions2()
  2144. *
  2145. * Audio:
  2146. *
  2147. * Decoders request a buffer of a particular size by setting
  2148. * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
  2149. * however, utilize only part of the buffer by setting AVFrame.nb_samples
  2150. * to a smaller value in the output frame.
  2151. *
  2152. * As a convenience, av_samples_get_buffer_size() and
  2153. * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
  2154. * functions to find the required data size and to fill data pointers and
  2155. * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
  2156. * since all planes must be the same size.
  2157. *
  2158. * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
  2159. *
  2160. * - encoding: unused
  2161. * - decoding: Set by libavcodec, user can override.
  2162. */
  2163. int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
  2164. /**
  2165. * If non-zero, the decoded audio and video frames returned from
  2166. * avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted
  2167. * and are valid indefinitely. The caller must free them with
  2168. * av_frame_unref() when they are not needed anymore.
  2169. * Otherwise, the decoded frames must not be freed by the caller and are
  2170. * only valid until the next decode call.
  2171. *
  2172. * This is always automatically enabled if avcodec_receive_frame() is used.
  2173. *
  2174. * - encoding: unused
  2175. * - decoding: set by the caller before avcodec_open2().
  2176. */
  2177. attribute_deprecated int refcounted_frames;
  2178. /* - encoding parameters */
  2179. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  2180. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  2181. /**
  2182. * minimum quantizer
  2183. * - encoding: Set by user.
  2184. * - decoding: unused
  2185. */
  2186. int qmin;
  2187. /**
  2188. * maximum quantizer
  2189. * - encoding: Set by user.
  2190. * - decoding: unused
  2191. */
  2192. int qmax;
  2193. /**
  2194. * maximum quantizer difference between frames
  2195. * - encoding: Set by user.
  2196. * - decoding: unused
  2197. */
  2198. int max_qdiff;
  2199. #if FF_API_MPV_OPT
  2200. /**
  2201. * @deprecated use encoder private options instead
  2202. */
  2203. attribute_deprecated
  2204. float rc_qsquish;
  2205. attribute_deprecated
  2206. float rc_qmod_amp;
  2207. attribute_deprecated
  2208. int rc_qmod_freq;
  2209. #endif
  2210. /**
  2211. * decoder bitstream buffer size
  2212. * - encoding: Set by user.
  2213. * - decoding: unused
  2214. */
  2215. int rc_buffer_size;
  2216. /**
  2217. * ratecontrol override, see RcOverride
  2218. * - encoding: Allocated/set/freed by user.
  2219. * - decoding: unused
  2220. */
  2221. int rc_override_count;
  2222. RcOverride *rc_override;
  2223. #if FF_API_MPV_OPT
  2224. /**
  2225. * @deprecated use encoder private options instead
  2226. */
  2227. attribute_deprecated
  2228. const char *rc_eq;
  2229. #endif
  2230. /**
  2231. * maximum bitrate
  2232. * - encoding: Set by user.
  2233. * - decoding: unused
  2234. */
  2235. int rc_max_rate;
  2236. /**
  2237. * minimum bitrate
  2238. * - encoding: Set by user.
  2239. * - decoding: unused
  2240. */
  2241. int rc_min_rate;
  2242. #if FF_API_MPV_OPT
  2243. /**
  2244. * @deprecated use encoder private options instead
  2245. */
  2246. attribute_deprecated
  2247. float rc_buffer_aggressivity;
  2248. attribute_deprecated
  2249. float rc_initial_cplx;
  2250. #endif
  2251. /**
  2252. * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
  2253. * - encoding: Set by user.
  2254. * - decoding: unused.
  2255. */
  2256. float rc_max_available_vbv_use;
  2257. /**
  2258. * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
  2259. * - encoding: Set by user.
  2260. * - decoding: unused.
  2261. */
  2262. float rc_min_vbv_overflow_use;
  2263. /**
  2264. * Number of bits which should be loaded into the rc buffer before decoding starts.
  2265. * - encoding: Set by user.
  2266. * - decoding: unused
  2267. */
  2268. int rc_initial_buffer_occupancy;
  2269. #if FF_API_CODER_TYPE
  2270. #define FF_CODER_TYPE_VLC 0
  2271. #define FF_CODER_TYPE_AC 1
  2272. #define FF_CODER_TYPE_RAW 2
  2273. #define FF_CODER_TYPE_RLE 3
  2274. #if FF_API_UNUSED_MEMBERS
  2275. #define FF_CODER_TYPE_DEFLATE 4
  2276. #endif /* FF_API_UNUSED_MEMBERS */
  2277. /**
  2278. * @deprecated use encoder private options instead
  2279. */
  2280. attribute_deprecated
  2281. int coder_type;
  2282. #endif /* FF_API_CODER_TYPE */
  2283. #if FF_API_PRIVATE_OPT
  2284. /** @deprecated use encoder private options instead */
  2285. attribute_deprecated
  2286. int context_model;
  2287. #endif
  2288. #if FF_API_MPV_OPT
  2289. /**
  2290. * @deprecated use encoder private options instead
  2291. */
  2292. attribute_deprecated
  2293. int lmin;
  2294. /**
  2295. * @deprecated use encoder private options instead
  2296. */
  2297. attribute_deprecated
  2298. int lmax;
  2299. #endif
  2300. #if FF_API_PRIVATE_OPT
  2301. /** @deprecated use encoder private options instead */
  2302. attribute_deprecated
  2303. int frame_skip_threshold;
  2304. /** @deprecated use encoder private options instead */
  2305. attribute_deprecated
  2306. int frame_skip_factor;
  2307. /** @deprecated use encoder private options instead */
  2308. attribute_deprecated
  2309. int frame_skip_exp;
  2310. /** @deprecated use encoder private options instead */
  2311. attribute_deprecated
  2312. int frame_skip_cmp;
  2313. #endif /* FF_API_PRIVATE_OPT */
  2314. /**
  2315. * trellis RD quantization
  2316. * - encoding: Set by user.
  2317. * - decoding: unused
  2318. */
  2319. int trellis;
  2320. #if FF_API_PRIVATE_OPT
  2321. /** @deprecated use encoder private options instead */
  2322. attribute_deprecated
  2323. int min_prediction_order;
  2324. /** @deprecated use encoder private options instead */
  2325. attribute_deprecated
  2326. int max_prediction_order;
  2327. /** @deprecated use encoder private options instead */
  2328. attribute_deprecated
  2329. int64_t timecode_frame_start;
  2330. #endif
  2331. #if FF_API_RTP_CALLBACK
  2332. /**
  2333. * @deprecated unused
  2334. */
  2335. /* The RTP callback: This function is called */
  2336. /* every time the encoder has a packet to send. */
  2337. /* It depends on the encoder if the data starts */
  2338. /* with a Start Code (it should). H.263 does. */
  2339. /* mb_nb contains the number of macroblocks */
  2340. /* encoded in the RTP payload. */
  2341. attribute_deprecated
  2342. void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
  2343. #endif
  2344. #if FF_API_PRIVATE_OPT
  2345. /** @deprecated use encoder private options instead */
  2346. attribute_deprecated
  2347. int rtp_payload_size; /* The size of the RTP payload: the coder will */
  2348. /* do its best to deliver a chunk with size */
  2349. /* below rtp_payload_size, the chunk will start */
  2350. /* with a start code on some codecs like H.263. */
  2351. /* This doesn't take account of any particular */
  2352. /* headers inside the transmitted RTP payload. */
  2353. #endif
  2354. #if FF_API_STAT_BITS
  2355. /* statistics, used for 2-pass encoding */
  2356. attribute_deprecated
  2357. int mv_bits;
  2358. attribute_deprecated
  2359. int header_bits;
  2360. attribute_deprecated
  2361. int i_tex_bits;
  2362. attribute_deprecated
  2363. int p_tex_bits;
  2364. attribute_deprecated
  2365. int i_count;
  2366. attribute_deprecated
  2367. int p_count;
  2368. attribute_deprecated
  2369. int skip_count;
  2370. attribute_deprecated
  2371. int misc_bits;
  2372. /** @deprecated this field is unused */
  2373. attribute_deprecated
  2374. int frame_bits;
  2375. #endif
  2376. /**
  2377. * pass1 encoding statistics output buffer
  2378. * - encoding: Set by libavcodec.
  2379. * - decoding: unused
  2380. */
  2381. char *stats_out;
  2382. /**
  2383. * pass2 encoding statistics input buffer
  2384. * Concatenated stuff from stats_out of pass1 should be placed here.
  2385. * - encoding: Allocated/set/freed by user.
  2386. * - decoding: unused
  2387. */
  2388. char *stats_in;
  2389. /**
  2390. * Work around bugs in encoders which sometimes cannot be detected automatically.
  2391. * - encoding: Set by user
  2392. * - decoding: Set by user
  2393. */
  2394. int workaround_bugs;
  2395. #define FF_BUG_AUTODETECT 1 ///< autodetection
  2396. #if FF_API_OLD_MSMPEG4
  2397. #define FF_BUG_OLD_MSMPEG4 2
  2398. #endif
  2399. #define FF_BUG_XVID_ILACE 4
  2400. #define FF_BUG_UMP4 8
  2401. #define FF_BUG_NO_PADDING 16
  2402. #define FF_BUG_AMV 32
  2403. #if FF_API_AC_VLC
  2404. #define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
  2405. #endif
  2406. #define FF_BUG_QPEL_CHROMA 64
  2407. #define FF_BUG_STD_QPEL 128
  2408. #define FF_BUG_QPEL_CHROMA2 256
  2409. #define FF_BUG_DIRECT_BLOCKSIZE 512
  2410. #define FF_BUG_EDGE 1024
  2411. #define FF_BUG_HPEL_CHROMA 2048
  2412. #define FF_BUG_DC_CLIP 4096
  2413. #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
  2414. #define FF_BUG_TRUNCATED 16384
  2415. /**
  2416. * strictly follow the standard (MPEG-4, ...).
  2417. * - encoding: Set by user.
  2418. * - decoding: Set by user.
  2419. * Setting this to STRICT or higher means the encoder and decoder will
  2420. * generally do stupid things, whereas setting it to unofficial or lower
  2421. * will mean the encoder might produce output that is not supported by all
  2422. * spec-compliant decoders. Decoders don't differentiate between normal,
  2423. * unofficial and experimental (that is, they always try to decode things
  2424. * when they can) unless they are explicitly asked to behave stupidly
  2425. * (=strictly conform to the specs)
  2426. */
  2427. int strict_std_compliance;
  2428. #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software.
  2429. #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
  2430. #define FF_COMPLIANCE_NORMAL 0
  2431. #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions
  2432. #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
  2433. /**
  2434. * error concealment flags
  2435. * - encoding: unused
  2436. * - decoding: Set by user.
  2437. */
  2438. int error_concealment;
  2439. #define FF_EC_GUESS_MVS 1
  2440. #define FF_EC_DEBLOCK 2
  2441. /**
  2442. * debug
  2443. * - encoding: Set by user.
  2444. * - decoding: Set by user.
  2445. */
  2446. int debug;
  2447. #define FF_DEBUG_PICT_INFO 1
  2448. #define FF_DEBUG_RC 2
  2449. #define FF_DEBUG_BITSTREAM 4
  2450. #define FF_DEBUG_MB_TYPE 8
  2451. #define FF_DEBUG_QP 16
  2452. #define FF_DEBUG_DCT_COEFF 0x00000040
  2453. #define FF_DEBUG_SKIP 0x00000080
  2454. #define FF_DEBUG_STARTCODE 0x00000100
  2455. #if FF_API_UNUSED_MEMBERS
  2456. #define FF_DEBUG_PTS 0x00000200
  2457. #endif /* FF_API_UNUSED_MEMBERS */
  2458. #define FF_DEBUG_ER 0x00000400
  2459. #define FF_DEBUG_MMCO 0x00000800
  2460. #define FF_DEBUG_BUGS 0x00001000
  2461. #define FF_DEBUG_BUFFERS 0x00008000
  2462. #define FF_DEBUG_THREADS 0x00010000
  2463. /**
  2464. * Error recognition; may misdetect some more or less valid parts as errors.
  2465. * - encoding: unused
  2466. * - decoding: Set by user.
  2467. */
  2468. int err_recognition;
  2469. /**
  2470. * Verify checksums embedded in the bitstream (could be of either encoded or
  2471. * decoded data, depending on the codec) and print an error message on mismatch.
  2472. * If AV_EF_EXPLODE is also set, a mismatching checksum will result in the
  2473. * decoder returning an error.
  2474. */
  2475. #define AV_EF_CRCCHECK (1<<0)
  2476. #define AV_EF_BITSTREAM (1<<1)
  2477. #define AV_EF_BUFFER (1<<2)
  2478. #define AV_EF_EXPLODE (1<<3)
  2479. /**
  2480. * opaque 64-bit number (generally a PTS) that will be reordered and
  2481. * output in AVFrame.reordered_opaque
  2482. * - encoding: unused
  2483. * - decoding: Set by user.
  2484. */
  2485. int64_t reordered_opaque;
  2486. /**
  2487. * Hardware accelerator in use
  2488. * - encoding: unused.
  2489. * - decoding: Set by libavcodec
  2490. */
  2491. struct AVHWAccel *hwaccel;
  2492. /**
  2493. * Hardware accelerator context.
  2494. * For some hardware accelerators, a global context needs to be
  2495. * provided by the user. In that case, this holds display-dependent
  2496. * data Libav cannot instantiate itself. Please refer to the
  2497. * Libav HW accelerator documentation to know how to fill this
  2498. * is. e.g. for VA API, this is a struct vaapi_context.
  2499. * - encoding: unused
  2500. * - decoding: Set by user
  2501. */
  2502. void *hwaccel_context;
  2503. /**
  2504. * error
  2505. * - encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR.
  2506. * - decoding: unused
  2507. */
  2508. uint64_t error[AV_NUM_DATA_POINTERS];
  2509. /**
  2510. * DCT algorithm, see FF_DCT_* below
  2511. * - encoding: Set by user.
  2512. * - decoding: unused
  2513. */
  2514. int dct_algo;
  2515. #define FF_DCT_AUTO 0
  2516. #define FF_DCT_FASTINT 1
  2517. #define FF_DCT_INT 2
  2518. #define FF_DCT_MMX 3
  2519. #define FF_DCT_ALTIVEC 5
  2520. #define FF_DCT_FAAN 6
  2521. /**
  2522. * IDCT algorithm, see FF_IDCT_* below.
  2523. * - encoding: Set by user.
  2524. * - decoding: Set by user.
  2525. */
  2526. int idct_algo;
  2527. #define FF_IDCT_AUTO 0
  2528. #define FF_IDCT_INT 1
  2529. #define FF_IDCT_SIMPLE 2
  2530. #define FF_IDCT_SIMPLEMMX 3
  2531. #define FF_IDCT_ARM 7
  2532. #define FF_IDCT_ALTIVEC 8
  2533. #if FF_API_ARCH_SH4
  2534. #define FF_IDCT_SH4 9
  2535. #endif
  2536. #define FF_IDCT_SIMPLEARM 10
  2537. #if FF_API_UNUSED_MEMBERS
  2538. #define FF_IDCT_IPP 13
  2539. #endif /* FF_API_UNUSED_MEMBERS */
  2540. #define FF_IDCT_XVID 14
  2541. #if FF_API_IDCT_XVIDMMX
  2542. #define FF_IDCT_XVIDMMX 14
  2543. #endif /* FF_API_IDCT_XVIDMMX */
  2544. #define FF_IDCT_SIMPLEARMV5TE 16
  2545. #define FF_IDCT_SIMPLEARMV6 17
  2546. #if FF_API_ARCH_SPARC
  2547. #define FF_IDCT_SIMPLEVIS 18
  2548. #endif
  2549. #define FF_IDCT_FAAN 20
  2550. #define FF_IDCT_SIMPLENEON 22
  2551. #if FF_API_ARCH_ALPHA
  2552. #define FF_IDCT_SIMPLEALPHA 23
  2553. #endif
  2554. /**
  2555. * bits per sample/pixel from the demuxer (needed for huffyuv).
  2556. * - encoding: Set by libavcodec.
  2557. * - decoding: Set by user.
  2558. */
  2559. int bits_per_coded_sample;
  2560. /**
  2561. * Bits per sample/pixel of internal libavcodec pixel/sample format.
  2562. * - encoding: set by user.
  2563. * - decoding: set by libavcodec.
  2564. */
  2565. int bits_per_raw_sample;
  2566. #if FF_API_CODED_FRAME
  2567. /**
  2568. * the picture in the bitstream
  2569. * - encoding: Set by libavcodec.
  2570. * - decoding: unused
  2571. *
  2572. * @deprecated use the quality factor packet side data instead
  2573. */
  2574. attribute_deprecated AVFrame *coded_frame;
  2575. #endif
  2576. /**
  2577. * thread count
  2578. * is used to decide how many independent tasks should be passed to execute()
  2579. * - encoding: Set by user.
  2580. * - decoding: Set by user.
  2581. */
  2582. int thread_count;
  2583. /**
  2584. * Which multithreading methods to use.
  2585. * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
  2586. * so clients which cannot provide future frames should not use it.
  2587. *
  2588. * - encoding: Set by user, otherwise the default is used.
  2589. * - decoding: Set by user, otherwise the default is used.
  2590. */
  2591. int thread_type;
  2592. #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
  2593. #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
  2594. /**
  2595. * Which multithreading methods are in use by the codec.
  2596. * - encoding: Set by libavcodec.
  2597. * - decoding: Set by libavcodec.
  2598. */
  2599. int active_thread_type;
  2600. /**
  2601. * Set by the client if its custom get_buffer() callback can be called
  2602. * synchronously from another thread, which allows faster multithreaded decoding.
  2603. * draw_horiz_band() will be called from other threads regardless of this setting.
  2604. * Ignored if the default get_buffer() is used.
  2605. * - encoding: Set by user.
  2606. * - decoding: Set by user.
  2607. */
  2608. int thread_safe_callbacks;
  2609. /**
  2610. * The codec may call this to execute several independent things.
  2611. * It will return only after finishing all tasks.
  2612. * The user may replace this with some multithreaded implementation,
  2613. * the default implementation will execute the parts serially.
  2614. * @param count the number of things to execute
  2615. * - encoding: Set by libavcodec, user can override.
  2616. * - decoding: Set by libavcodec, user can override.
  2617. */
  2618. int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
  2619. /**
  2620. * The codec may call this to execute several independent things.
  2621. * It will return only after finishing all tasks.
  2622. * The user may replace this with some multithreaded implementation,
  2623. * the default implementation will execute the parts serially.
  2624. * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
  2625. * @param c context passed also to func
  2626. * @param count the number of things to execute
  2627. * @param arg2 argument passed unchanged to func
  2628. * @param ret return values of executed functions, must have space for "count" values. May be NULL.
  2629. * @param func function that will be called count times, with jobnr from 0 to count-1.
  2630. * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
  2631. * two instances of func executing at the same time will have the same threadnr.
  2632. * @return always 0 currently, but code should handle a future improvement where when any call to func
  2633. * returns < 0 no further calls to func may be done and < 0 is returned.
  2634. * - encoding: Set by libavcodec, user can override.
  2635. * - decoding: Set by libavcodec, user can override.
  2636. */
  2637. int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
  2638. /**
  2639. * noise vs. sse weight for the nsse comparison function
  2640. * - encoding: Set by user.
  2641. * - decoding: unused
  2642. */
  2643. int nsse_weight;
  2644. /**
  2645. * profile
  2646. * - encoding: Set by user.
  2647. * - decoding: Set by libavcodec.
  2648. */
  2649. int profile;
  2650. #define FF_PROFILE_UNKNOWN -99
  2651. #define FF_PROFILE_RESERVED -100
  2652. #define FF_PROFILE_AAC_MAIN 0
  2653. #define FF_PROFILE_AAC_LOW 1
  2654. #define FF_PROFILE_AAC_SSR 2
  2655. #define FF_PROFILE_AAC_LTP 3
  2656. #define FF_PROFILE_AAC_HE 4
  2657. #define FF_PROFILE_AAC_HE_V2 28
  2658. #define FF_PROFILE_AAC_LD 22
  2659. #define FF_PROFILE_AAC_ELD 38
  2660. #define FF_PROFILE_MPEG2_AAC_LOW 128
  2661. #define FF_PROFILE_MPEG2_AAC_HE 131
  2662. #define FF_PROFILE_DTS 20
  2663. #define FF_PROFILE_DTS_ES 30
  2664. #define FF_PROFILE_DTS_96_24 40
  2665. #define FF_PROFILE_DTS_HD_HRA 50
  2666. #define FF_PROFILE_DTS_HD_MA 60
  2667. #define FF_PROFILE_DTS_EXPRESS 70
  2668. #define FF_PROFILE_MPEG2_422 0
  2669. #define FF_PROFILE_MPEG2_HIGH 1
  2670. #define FF_PROFILE_MPEG2_SS 2
  2671. #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
  2672. #define FF_PROFILE_MPEG2_MAIN 4
  2673. #define FF_PROFILE_MPEG2_SIMPLE 5
  2674. #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
  2675. #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
  2676. #define FF_PROFILE_H264_BASELINE 66
  2677. #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
  2678. #define FF_PROFILE_H264_MAIN 77
  2679. #define FF_PROFILE_H264_EXTENDED 88
  2680. #define FF_PROFILE_H264_HIGH 100
  2681. #define FF_PROFILE_H264_HIGH_10 110
  2682. #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
  2683. #define FF_PROFILE_H264_MULTIVIEW_HIGH 118
  2684. #define FF_PROFILE_H264_HIGH_422 122
  2685. #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
  2686. #define FF_PROFILE_H264_STEREO_HIGH 128
  2687. #define FF_PROFILE_H264_HIGH_444 144
  2688. #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
  2689. #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
  2690. #define FF_PROFILE_H264_CAVLC_444 44
  2691. #define FF_PROFILE_VC1_SIMPLE 0
  2692. #define FF_PROFILE_VC1_MAIN 1
  2693. #define FF_PROFILE_VC1_COMPLEX 2
  2694. #define FF_PROFILE_VC1_ADVANCED 3
  2695. #define FF_PROFILE_MPEG4_SIMPLE 0
  2696. #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
  2697. #define FF_PROFILE_MPEG4_CORE 2
  2698. #define FF_PROFILE_MPEG4_MAIN 3
  2699. #define FF_PROFILE_MPEG4_N_BIT 4
  2700. #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
  2701. #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
  2702. #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
  2703. #define FF_PROFILE_MPEG4_HYBRID 8
  2704. #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
  2705. #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
  2706. #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
  2707. #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
  2708. #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
  2709. #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
  2710. #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
  2711. #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 1
  2712. #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 2
  2713. #define FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION 32768
  2714. #define FF_PROFILE_JPEG2000_DCINEMA_2K 3
  2715. #define FF_PROFILE_JPEG2000_DCINEMA_4K 4
  2716. #define FF_PROFILE_VP9_0 0
  2717. #define FF_PROFILE_VP9_1 1
  2718. #define FF_PROFILE_VP9_2 2
  2719. #define FF_PROFILE_VP9_3 3
  2720. #define FF_PROFILE_HEVC_MAIN 1
  2721. #define FF_PROFILE_HEVC_MAIN_10 2
  2722. #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE 3
  2723. #define FF_PROFILE_HEVC_REXT 4
  2724. /**
  2725. * level
  2726. * - encoding: Set by user.
  2727. * - decoding: Set by libavcodec.
  2728. */
  2729. int level;
  2730. #define FF_LEVEL_UNKNOWN -99
  2731. /**
  2732. * - encoding: unused
  2733. * - decoding: Set by user.
  2734. */
  2735. enum AVDiscard skip_loop_filter;
  2736. /**
  2737. * - encoding: unused
  2738. * - decoding: Set by user.
  2739. */
  2740. enum AVDiscard skip_idct;
  2741. /**
  2742. * - encoding: unused
  2743. * - decoding: Set by user.
  2744. */
  2745. enum AVDiscard skip_frame;
  2746. /**
  2747. * Header containing style information for text subtitles.
  2748. * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
  2749. * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  2750. * the Format line following. It shouldn't include any Dialogue line.
  2751. * - encoding: Set/allocated/freed by user (before avcodec_open2())
  2752. * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
  2753. */
  2754. uint8_t *subtitle_header;
  2755. int subtitle_header_size;
  2756. #if FF_API_ERROR_RATE
  2757. /**
  2758. * @deprecated use the 'error_rate' private AVOption of the mpegvideo
  2759. * encoders
  2760. */
  2761. attribute_deprecated
  2762. int error_rate;
  2763. #endif
  2764. #if FF_API_VBV_DELAY
  2765. /**
  2766. * VBV delay coded in the last frame (in periods of a 27 MHz clock).
  2767. * Used for compliant TS muxing.
  2768. * - encoding: Set by libavcodec.
  2769. * - decoding: unused.
  2770. * @deprecated this value is now exported as a part of
  2771. * AV_PKT_DATA_CPB_PROPERTIES packet side data
  2772. */
  2773. attribute_deprecated
  2774. uint64_t vbv_delay;
  2775. #endif
  2776. #if FF_API_SIDEDATA_ONLY_PKT
  2777. /**
  2778. * Encoding only and set by default. Allow encoders to output packets
  2779. * that do not contain any encoded data, only side data.
  2780. *
  2781. * Some encoders need to output such packets, e.g. to update some stream
  2782. * parameters at the end of encoding.
  2783. *
  2784. * @deprecated this field disables the default behaviour and
  2785. * it is kept only for compatibility.
  2786. */
  2787. attribute_deprecated
  2788. int side_data_only_packets;
  2789. #endif
  2790. /**
  2791. * Audio only. The number of "priming" samples (padding) inserted by the
  2792. * encoder at the beginning of the audio. I.e. this number of leading
  2793. * decoded samples must be discarded by the caller to get the original audio
  2794. * without leading padding.
  2795. *
  2796. * - decoding: unused
  2797. * - encoding: Set by libavcodec. The timestamps on the output packets are
  2798. * adjusted by the encoder so that they always refer to the
  2799. * first sample of the data actually contained in the packet,
  2800. * including any added padding. E.g. if the timebase is
  2801. * 1/samplerate and the timestamp of the first input sample is
  2802. * 0, the timestamp of the first output packet will be
  2803. * -initial_padding.
  2804. */
  2805. int initial_padding;
  2806. /*
  2807. * - decoding: For codecs that store a framerate value in the compressed
  2808. * bitstream, the decoder may export it here. { 0, 1} when
  2809. * unknown.
  2810. * - encoding: May be used to signal the framerate of CFR content to an
  2811. * encoder.
  2812. */
  2813. AVRational framerate;
  2814. /**
  2815. * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
  2816. * - encoding: unused.
  2817. * - decoding: Set by libavcodec before calling get_format()
  2818. */
  2819. enum AVPixelFormat sw_pix_fmt;
  2820. /**
  2821. * Additional data associated with the entire coded stream.
  2822. *
  2823. * - decoding: unused
  2824. * - encoding: may be set by libavcodec after avcodec_open2().
  2825. */
  2826. AVPacketSideData *coded_side_data;
  2827. int nb_coded_side_data;
  2828. /**
  2829. * A reference to the AVHWFramesContext describing the input (for encoding)
  2830. * or output (decoding) frames. The reference is set by the caller and
  2831. * afterwards owned (and freed) by libavcodec - it should never be read by
  2832. * the caller after being set.
  2833. *
  2834. * - decoding: This field should be set by the caller from the get_format()
  2835. * callback. The previous reference (if any) will always be
  2836. * unreffed by libavcodec before the get_format() call.
  2837. *
  2838. * If the default get_buffer2() is used with a hwaccel pixel
  2839. * format, then this AVHWFramesContext will be used for
  2840. * allocating the frame buffers.
  2841. *
  2842. * - encoding: For hardware encoders configured to use a hwaccel pixel
  2843. * format, this field should be set by the caller to a reference
  2844. * to the AVHWFramesContext describing input frames.
  2845. * AVHWFramesContext.format must be equal to
  2846. * AVCodecContext.pix_fmt.
  2847. *
  2848. * This field should be set before avcodec_open2() is called.
  2849. */
  2850. AVBufferRef *hw_frames_ctx;
  2851. /**
  2852. * Video decoding only. Certain video codecs support cropping, meaning that
  2853. * only a sub-rectangle of the decoded frame is intended for display. This
  2854. * option controls how cropping is handled by libavcodec.
  2855. *
  2856. * When set to 1 (the default), libavcodec will apply cropping internally.
  2857. * I.e. it will modify the output frame width/height fields and offset the
  2858. * data pointers (only by as much as possible while preserving alignment, or
  2859. * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that
  2860. * the frames output by the decoder refer only to the cropped area. The
  2861. * crop_* fields of the output frames will be zero.
  2862. *
  2863. * When set to 0, the width/height fields of the output frames will be set
  2864. * to the coded dimensions and the crop_* fields will describe the cropping
  2865. * rectangle. Applying the cropping is left to the caller.
  2866. *
  2867. * @warning When hardware acceleration with opaque output frames is used,
  2868. * libavcodec is unable to apply cropping from the top/left border.
  2869. *
  2870. * @note when this option is set to zero, the width/height fields of the
  2871. * AVCodecContext and output AVFrames have different meanings. The codec
  2872. * context fields store display dimensions (with the coded dimensions in
  2873. * coded_width/height), while the frame fields store the coded dimensions
  2874. * (with the display dimensions being determined by the crop_* fields).
  2875. */
  2876. int apply_cropping;
  2877. /**
  2878. * A reference to the AVHWDeviceContext describing the device which will
  2879. * be used by a hardware encoder/decoder. The reference is set by the
  2880. * caller and afterwards owned (and freed) by libavcodec.
  2881. *
  2882. * This should be used if either the codec device does not require
  2883. * hardware frames or any that are used are to be allocated internally by
  2884. * libavcodec. If the user wishes to supply any of the frames used as
  2885. * encoder input or decoder output then hw_frames_ctx should be used
  2886. * instead. When hw_frames_ctx is set in get_format() for a decoder, this
  2887. * field will be ignored while decoding the associated stream segment, but
  2888. * may again be used on a following one after another get_format() call.
  2889. *
  2890. * For both encoders and decoders this field should be set before
  2891. * avcodec_open2() is called and must not be written to thereafter.
  2892. *
  2893. * Note that some decoders may require this field to be set initially in
  2894. * order to support hw_frames_ctx at all - in that case, all frames
  2895. * contexts used must be created on the same device.
  2896. */
  2897. AVBufferRef *hw_device_ctx;
  2898. /**
  2899. * Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated
  2900. * decoding (if active).
  2901. * - encoding: unused
  2902. * - decoding: Set by user (either before avcodec_open2(), or in the
  2903. * AVCodecContext.get_format callback)
  2904. */
  2905. int hwaccel_flags;
  2906. } AVCodecContext;
  2907. /**
  2908. * AVProfile.
  2909. */
  2910. typedef struct AVProfile {
  2911. int profile;
  2912. const char *name; ///< short name for the profile
  2913. } AVProfile;
  2914. typedef struct AVCodecDefault AVCodecDefault;
  2915. struct AVSubtitle;
  2916. /**
  2917. * AVCodec.
  2918. */
  2919. typedef struct AVCodec {
  2920. /**
  2921. * Name of the codec implementation.
  2922. * The name is globally unique among encoders and among decoders (but an
  2923. * encoder and a decoder can share the same name).
  2924. * This is the primary way to find a codec from the user perspective.
  2925. */
  2926. const char *name;
  2927. /**
  2928. * Descriptive name for the codec, meant to be more human readable than name.
  2929. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
  2930. */
  2931. const char *long_name;
  2932. enum AVMediaType type;
  2933. enum AVCodecID id;
  2934. /**
  2935. * Codec capabilities.
  2936. * see AV_CODEC_CAP_*
  2937. */
  2938. int capabilities;
  2939. const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
  2940. const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
  2941. const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
  2942. const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
  2943. const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
  2944. const AVClass *priv_class; ///< AVClass for the private context
  2945. const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
  2946. /*****************************************************************
  2947. * No fields below this line are part of the public API. They
  2948. * may not be used outside of libavcodec and can be changed and
  2949. * removed at will.
  2950. * New public fields should be added right above.
  2951. *****************************************************************
  2952. */
  2953. int priv_data_size;
  2954. struct AVCodec *next;
  2955. /**
  2956. * @name Frame-level threading support functions
  2957. * @{
  2958. */
  2959. /**
  2960. * If defined, called on thread contexts when they are created.
  2961. * If the codec allocates writable tables in init(), re-allocate them here.
  2962. * priv_data will be set to a copy of the original.
  2963. */
  2964. int (*init_thread_copy)(AVCodecContext *);
  2965. /**
  2966. * Copy necessary context variables from a previous thread context to the current one.
  2967. * If not defined, the next thread will start automatically; otherwise, the codec
  2968. * must call ff_thread_finish_setup().
  2969. *
  2970. * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
  2971. */
  2972. int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
  2973. /** @} */
  2974. /**
  2975. * Private codec-specific defaults.
  2976. */
  2977. const AVCodecDefault *defaults;
  2978. /**
  2979. * Initialize codec static data, called from avcodec_register().
  2980. */
  2981. void (*init_static_data)(struct AVCodec *codec);
  2982. int (*init)(AVCodecContext *);
  2983. int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
  2984. const struct AVSubtitle *sub);
  2985. /**
  2986. * Encode data to an AVPacket.
  2987. *
  2988. * @param avctx codec context
  2989. * @param avpkt output AVPacket (may contain a user-provided buffer)
  2990. * @param[in] frame AVFrame containing the raw data to be encoded
  2991. * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
  2992. * non-empty packet was returned in avpkt.
  2993. * @return 0 on success, negative error code on failure
  2994. */
  2995. int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
  2996. int *got_packet_ptr);
  2997. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
  2998. int (*close)(AVCodecContext *);
  2999. /**
  3000. * Encode API with decoupled packet/frame dataflow. The API is the
  3001. * same as the avcodec_ prefixed APIs (avcodec_send_frame() etc.), except
  3002. * that:
  3003. * - never called if the codec is closed or the wrong type,
  3004. * - if AV_CODEC_CAP_DELAY is not set, drain frames are never sent,
  3005. * - only one drain frame is ever passed down,
  3006. */
  3007. int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);
  3008. int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);
  3009. /**
  3010. * Decode API with decoupled packet/frame dataflow. This function is called
  3011. * to get one output frame. It should call ff_decode_get_packet() to obtain
  3012. * input data.
  3013. */
  3014. int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);
  3015. /**
  3016. * Flush buffers.
  3017. * Will be called when seeking
  3018. */
  3019. void (*flush)(AVCodecContext *);
  3020. /**
  3021. * Internal codec capabilities.
  3022. * See FF_CODEC_CAP_* in internal.h
  3023. */
  3024. int caps_internal;
  3025. /**
  3026. * Decoding only, a comma-separated list of bitstream filters to apply to
  3027. * packets before decoding.
  3028. */
  3029. const char *bsfs;
  3030. } AVCodec;
  3031. /**
  3032. * @defgroup lavc_hwaccel AVHWAccel
  3033. * @{
  3034. */
  3035. typedef struct AVHWAccel {
  3036. /**
  3037. * Name of the hardware accelerated codec.
  3038. * The name is globally unique among encoders and among decoders (but an
  3039. * encoder and a decoder can share the same name).
  3040. */
  3041. const char *name;
  3042. /**
  3043. * Type of codec implemented by the hardware accelerator.
  3044. *
  3045. * See AVMEDIA_TYPE_xxx
  3046. */
  3047. enum AVMediaType type;
  3048. /**
  3049. * Codec implemented by the hardware accelerator.
  3050. *
  3051. * See AV_CODEC_ID_xxx
  3052. */
  3053. enum AVCodecID id;
  3054. /**
  3055. * Supported pixel format.
  3056. *
  3057. * Only hardware accelerated formats are supported here.
  3058. */
  3059. enum AVPixelFormat pix_fmt;
  3060. /**
  3061. * Hardware accelerated codec capabilities.
  3062. * see FF_HWACCEL_CODEC_CAP_*
  3063. */
  3064. int capabilities;
  3065. /*****************************************************************
  3066. * No fields below this line are part of the public API. They
  3067. * may not be used outside of libavcodec and can be changed and
  3068. * removed at will.
  3069. * New public fields should be added right above.
  3070. *****************************************************************
  3071. */
  3072. struct AVHWAccel *next;
  3073. /**
  3074. * Allocate a custom buffer
  3075. */
  3076. int (*alloc_frame)(AVCodecContext *avctx, AVFrame *frame);
  3077. /**
  3078. * Called at the beginning of each frame or field picture.
  3079. *
  3080. * Meaningful frame information (codec specific) is guaranteed to
  3081. * be parsed at this point. This function is mandatory.
  3082. *
  3083. * Note that buf can be NULL along with buf_size set to 0.
  3084. * Otherwise, this means the whole frame is available at this point.
  3085. *
  3086. * @param avctx the codec context
  3087. * @param buf the frame data buffer base
  3088. * @param buf_size the size of the frame in bytes
  3089. * @return zero if successful, a negative value otherwise
  3090. */
  3091. int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  3092. /**
  3093. * Callback for each slice.
  3094. *
  3095. * Meaningful slice information (codec specific) is guaranteed to
  3096. * be parsed at this point. This function is mandatory.
  3097. *
  3098. * @param avctx the codec context
  3099. * @param buf the slice data buffer base
  3100. * @param buf_size the size of the slice in bytes
  3101. * @return zero if successful, a negative value otherwise
  3102. */
  3103. int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  3104. /**
  3105. * Called at the end of each frame or field picture.
  3106. *
  3107. * The whole picture is parsed at this point and can now be sent
  3108. * to the hardware accelerator. This function is mandatory.
  3109. *
  3110. * @param avctx the codec context
  3111. * @return zero if successful, a negative value otherwise
  3112. */
  3113. int (*end_frame)(AVCodecContext *avctx);
  3114. /**
  3115. * Size of per-frame hardware accelerator private data.
  3116. *
  3117. * Private data is allocated with av_mallocz() before
  3118. * AVCodecContext.get_buffer() and deallocated after
  3119. * AVCodecContext.release_buffer().
  3120. */
  3121. int frame_priv_data_size;
  3122. /**
  3123. * Initialize the hwaccel private data.
  3124. *
  3125. * This will be called from ff_get_format(), after hwaccel and
  3126. * hwaccel_context are set and the hwaccel private data in AVCodecInternal
  3127. * is allocated.
  3128. */
  3129. int (*init)(AVCodecContext *avctx);
  3130. /**
  3131. * Uninitialize the hwaccel private data.
  3132. *
  3133. * This will be called from get_format() or avcodec_close(), after hwaccel
  3134. * and hwaccel_context are already uninitialized.
  3135. */
  3136. int (*uninit)(AVCodecContext *avctx);
  3137. /**
  3138. * Size of the private data to allocate in
  3139. * AVCodecInternal.hwaccel_priv_data.
  3140. */
  3141. int priv_data_size;
  3142. /**
  3143. * Internal hwaccel capabilities.
  3144. */
  3145. int caps_internal;
  3146. } AVHWAccel;
  3147. /**
  3148. * Hardware acceleration should be used for decoding even if the codec level
  3149. * used is unknown or higher than the maximum supported level reported by the
  3150. * hardware driver.
  3151. */
  3152. #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
  3153. /**
  3154. * Hardware acceleration can output YUV pixel formats with a different chroma
  3155. * sampling than 4:2:0 and/or other than 8 bits per component.
  3156. */
  3157. #define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1)
  3158. /**
  3159. * @}
  3160. */
  3161. #if FF_API_AVPICTURE
  3162. /**
  3163. * @defgroup lavc_picture AVPicture
  3164. *
  3165. * Functions for working with AVPicture
  3166. * @{
  3167. */
  3168. /**
  3169. * four components are given, that's all.
  3170. * the last component is alpha
  3171. * @deprecated Use the imgutils functions
  3172. */
  3173. typedef struct AVPicture {
  3174. attribute_deprecated
  3175. uint8_t *data[AV_NUM_DATA_POINTERS];
  3176. attribute_deprecated
  3177. int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line
  3178. } AVPicture;
  3179. /**
  3180. * @}
  3181. */
  3182. #endif
  3183. #define AVPALETTE_SIZE 1024
  3184. #define AVPALETTE_COUNT 256
  3185. enum AVSubtitleType {
  3186. SUBTITLE_NONE,
  3187. SUBTITLE_BITMAP, ///< A bitmap, pict will be set
  3188. /**
  3189. * Plain text, the text field must be set by the decoder and is
  3190. * authoritative. ass and pict fields may contain approximations.
  3191. */
  3192. SUBTITLE_TEXT,
  3193. /**
  3194. * Formatted text, the ass field must be set by the decoder and is
  3195. * authoritative. pict and text fields may contain approximations.
  3196. */
  3197. SUBTITLE_ASS,
  3198. };
  3199. #define AV_SUBTITLE_FLAG_FORCED 0x00000001
  3200. typedef struct AVSubtitleRect {
  3201. int x; ///< top left corner of pict, undefined when pict is not set
  3202. int y; ///< top left corner of pict, undefined when pict is not set
  3203. int w; ///< width of pict, undefined when pict is not set
  3204. int h; ///< height of pict, undefined when pict is not set
  3205. int nb_colors; ///< number of colors in pict, undefined when pict is not set
  3206. #if FF_API_AVPICTURE
  3207. /**
  3208. * @deprecated unused
  3209. */
  3210. attribute_deprecated
  3211. AVPicture pict;
  3212. #endif
  3213. /**
  3214. * data+linesize for the bitmap of this subtitle.
  3215. * Can be set for text/ass as well once they are rendered.
  3216. */
  3217. uint8_t *data[4];
  3218. int linesize[4];
  3219. enum AVSubtitleType type;
  3220. char *text; ///< 0 terminated plain UTF-8 text
  3221. /**
  3222. * 0 terminated ASS/SSA compatible event line.
  3223. * The presentation of this is unaffected by the other values in this
  3224. * struct.
  3225. */
  3226. char *ass;
  3227. int flags;
  3228. } AVSubtitleRect;
  3229. typedef struct AVSubtitle {
  3230. uint16_t format; /* 0 = graphics */
  3231. uint32_t start_display_time; /* relative to packet pts, in ms */
  3232. uint32_t end_display_time; /* relative to packet pts, in ms */
  3233. unsigned num_rects;
  3234. AVSubtitleRect **rects;
  3235. int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
  3236. } AVSubtitle;
  3237. /**
  3238. * This struct describes the properties of an encoded stream.
  3239. *
  3240. * sizeof(AVCodecParameters) is not a part of the public ABI, this struct must
  3241. * be allocated with avcodec_parameters_alloc() and freed with
  3242. * avcodec_parameters_free().
  3243. */
  3244. typedef struct AVCodecParameters {
  3245. /**
  3246. * General type of the encoded data.
  3247. */
  3248. enum AVMediaType codec_type;
  3249. /**
  3250. * Specific type of the encoded data (the codec used).
  3251. */
  3252. enum AVCodecID codec_id;
  3253. /**
  3254. * Additional information about the codec (corresponds to the AVI FOURCC).
  3255. */
  3256. uint32_t codec_tag;
  3257. /**
  3258. * Extra binary data needed for initializing the decoder, codec-dependent.
  3259. *
  3260. * Must be allocated with av_malloc() and will be freed by
  3261. * avcodec_parameters_free(). The allocated size of extradata must be at
  3262. * least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
  3263. * bytes zeroed.
  3264. */
  3265. uint8_t *extradata;
  3266. /**
  3267. * Size of the extradata content in bytes.
  3268. */
  3269. int extradata_size;
  3270. /**
  3271. * - video: the pixel format, the value corresponds to enum AVPixelFormat.
  3272. * - audio: the sample format, the value corresponds to enum AVSampleFormat.
  3273. */
  3274. int format;
  3275. /**
  3276. * The average bitrate of the encoded data (in bits per second).
  3277. */
  3278. int bit_rate;
  3279. int bits_per_coded_sample;
  3280. /**
  3281. * Codec-specific bitstream restrictions that the stream conforms to.
  3282. */
  3283. int profile;
  3284. int level;
  3285. /**
  3286. * Video only. The dimensions of the video frame in pixels.
  3287. */
  3288. int width;
  3289. int height;
  3290. /**
  3291. * Video only. The aspect ratio (width / height) which a single pixel
  3292. * should have when displayed.
  3293. *
  3294. * When the aspect ratio is unknown / undefined, the numerator should be
  3295. * set to 0 (the denominator may have any value).
  3296. */
  3297. AVRational sample_aspect_ratio;
  3298. /**
  3299. * Video only. The order of the fields in interlaced video.
  3300. */
  3301. enum AVFieldOrder field_order;
  3302. /**
  3303. * Video only. Additional colorspace characteristics.
  3304. */
  3305. enum AVColorRange color_range;
  3306. enum AVColorPrimaries color_primaries;
  3307. enum AVColorTransferCharacteristic color_trc;
  3308. enum AVColorSpace color_space;
  3309. enum AVChromaLocation chroma_location;
  3310. /**
  3311. * Audio only. The channel layout bitmask. May be 0 if the channel layout is
  3312. * unknown or unspecified, otherwise the number of bits set must be equal to
  3313. * the channels field.
  3314. */
  3315. uint64_t channel_layout;
  3316. /**
  3317. * Audio only. The number of audio channels.
  3318. */
  3319. int channels;
  3320. /**
  3321. * Audio only. The number of audio samples per second.
  3322. */
  3323. int sample_rate;
  3324. /**
  3325. * Audio only. The number of bytes per coded audio frame, required by some
  3326. * formats.
  3327. *
  3328. * Corresponds to nBlockAlign in WAVEFORMATEX.
  3329. */
  3330. int block_align;
  3331. /**
  3332. * Audio only. The amount of padding (in samples) inserted by the encoder at
  3333. * the beginning of the audio. I.e. this number of leading decoded samples
  3334. * must be discarded by the caller to get the original audio without leading
  3335. * padding.
  3336. */
  3337. int initial_padding;
  3338. /**
  3339. * Audio only. The amount of padding (in samples) appended by the encoder to
  3340. * the end of the audio. I.e. this number of decoded samples must be
  3341. * discarded by the caller from the end of the stream to get the original
  3342. * audio without any trailing padding.
  3343. */
  3344. int trailing_padding;
  3345. } AVCodecParameters;
  3346. /**
  3347. * If c is NULL, returns the first registered codec,
  3348. * if c is non-NULL, returns the next registered codec after c,
  3349. * or NULL if c is the last one.
  3350. */
  3351. AVCodec *av_codec_next(const AVCodec *c);
  3352. /**
  3353. * Return the LIBAVCODEC_VERSION_INT constant.
  3354. */
  3355. unsigned avcodec_version(void);
  3356. /**
  3357. * Return the libavcodec build-time configuration.
  3358. */
  3359. const char *avcodec_configuration(void);
  3360. /**
  3361. * Return the libavcodec license.
  3362. */
  3363. const char *avcodec_license(void);
  3364. /**
  3365. * Register the codec codec and initialize libavcodec.
  3366. *
  3367. * @warning either this function or avcodec_register_all() must be called
  3368. * before any other libavcodec functions.
  3369. *
  3370. * @see avcodec_register_all()
  3371. */
  3372. void avcodec_register(AVCodec *codec);
  3373. /**
  3374. * Register all the codecs, parsers and bitstream filters which were enabled at
  3375. * configuration time. If you do not call this function you can select exactly
  3376. * which formats you want to support, by using the individual registration
  3377. * functions.
  3378. *
  3379. * @see avcodec_register
  3380. * @see av_register_codec_parser
  3381. * @see av_register_bitstream_filter
  3382. */
  3383. void avcodec_register_all(void);
  3384. /**
  3385. * Allocate an AVCodecContext and set its fields to default values. The
  3386. * resulting struct should be freed with avcodec_free_context().
  3387. *
  3388. * @param codec if non-NULL, allocate private data and initialize defaults
  3389. * for the given codec. It is illegal to then call avcodec_open2()
  3390. * with a different codec.
  3391. * If NULL, then the codec-specific defaults won't be initialized,
  3392. * which may result in suboptimal default settings (this is
  3393. * important mainly for encoders, e.g. libx264).
  3394. *
  3395. * @return An AVCodecContext filled with default values or NULL on failure.
  3396. */
  3397. AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
  3398. /**
  3399. * Free the codec context and everything associated with it and write NULL to
  3400. * the provided pointer.
  3401. */
  3402. void avcodec_free_context(AVCodecContext **avctx);
  3403. #if FF_API_GET_CONTEXT_DEFAULTS
  3404. /**
  3405. * @deprecated This function should not be used, as closing and opening a codec
  3406. * context multiple time is not supported. A new codec context should be
  3407. * allocated for each new use.
  3408. */
  3409. int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec);
  3410. #endif
  3411. /**
  3412. * Get the AVClass for AVCodecContext. It can be used in combination with
  3413. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  3414. *
  3415. * @see av_opt_find().
  3416. */
  3417. const AVClass *avcodec_get_class(void);
  3418. #if FF_API_COPY_CONTEXT
  3419. /**
  3420. * Copy the settings of the source AVCodecContext into the destination
  3421. * AVCodecContext. The resulting destination codec context will be
  3422. * unopened, i.e. you are required to call avcodec_open2() before you
  3423. * can use this AVCodecContext to decode/encode video/audio data.
  3424. *
  3425. * @param dest target codec context, should be initialized with
  3426. * avcodec_alloc_context3(), but otherwise uninitialized
  3427. * @param src source codec context
  3428. * @return AVERROR() on error (e.g. memory allocation error), 0 on success
  3429. *
  3430. * @deprecated The semantics of this function are ill-defined and it should not
  3431. * be used. If you need to transfer the stream parameters from one codec context
  3432. * to another, use an intermediate AVCodecParameters instance and the
  3433. * avcodec_parameters_from_context() / avcodec_parameters_to_context()
  3434. * functions.
  3435. */
  3436. attribute_deprecated
  3437. int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
  3438. #endif
  3439. /**
  3440. * Allocate a new AVCodecParameters and set its fields to default values
  3441. * (unknown/invalid/0). The returned struct must be freed with
  3442. * avcodec_parameters_free().
  3443. */
  3444. AVCodecParameters *avcodec_parameters_alloc(void);
  3445. /**
  3446. * Free an AVCodecParameters instance and everything associated with it and
  3447. * write NULL to the supplied pointer.
  3448. */
  3449. void avcodec_parameters_free(AVCodecParameters **par);
  3450. /**
  3451. * Copy the contents of src to dst. Any allocated fields in dst are freed and
  3452. * replaced with newly allocated duplicates of the corresponding fields in src.
  3453. *
  3454. * @return >= 0 on success, a negative AVERROR code on failure.
  3455. */
  3456. int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src);
  3457. /**
  3458. * Fill the parameters struct based on the values from the supplied codec
  3459. * context. Any allocated fields in par are freed and replaced with duplicates
  3460. * of the corresponding fields in codec.
  3461. *
  3462. * @return >= 0 on success, a negative AVERROR code on failure
  3463. */
  3464. int avcodec_parameters_from_context(AVCodecParameters *par,
  3465. const AVCodecContext *codec);
  3466. /**
  3467. * Fill the codec context based on the values from the supplied codec
  3468. * parameters. Any allocated fields in codec that have a corresponding field in
  3469. * par are freed and replaced with duplicates of the corresponding field in par.
  3470. * Fields in codec that do not have a counterpart in par are not touched.
  3471. *
  3472. * @return >= 0 on success, a negative AVERROR code on failure.
  3473. */
  3474. int avcodec_parameters_to_context(AVCodecContext *codec,
  3475. const AVCodecParameters *par);
  3476. /**
  3477. * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
  3478. * function the context has to be allocated with avcodec_alloc_context3().
  3479. *
  3480. * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
  3481. * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  3482. * retrieving a codec.
  3483. *
  3484. * @warning This function is not thread safe!
  3485. *
  3486. * @note Always call this function before using decoding routines (such as
  3487. * @ref avcodec_receive_frame()).
  3488. *
  3489. * @code
  3490. * avcodec_register_all();
  3491. * av_dict_set(&opts, "b", "2.5M", 0);
  3492. * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
  3493. * if (!codec)
  3494. * exit(1);
  3495. *
  3496. * context = avcodec_alloc_context3(codec);
  3497. *
  3498. * if (avcodec_open2(context, codec, opts) < 0)
  3499. * exit(1);
  3500. * @endcode
  3501. *
  3502. * @param avctx The context to initialize.
  3503. * @param codec The codec to open this context for. If a non-NULL codec has been
  3504. * previously passed to avcodec_alloc_context3() or
  3505. * for this context, then this parameter MUST be either NULL or
  3506. * equal to the previously passed codec.
  3507. * @param options A dictionary filled with AVCodecContext and codec-private options.
  3508. * On return this object will be filled with options that were not found.
  3509. *
  3510. * @return zero on success, a negative value on error
  3511. * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
  3512. * av_dict_set(), av_opt_find().
  3513. */
  3514. int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
  3515. /**
  3516. * Close a given AVCodecContext and free all the data associated with it
  3517. * (but not the AVCodecContext itself).
  3518. *
  3519. * Calling this function on an AVCodecContext that hasn't been opened will free
  3520. * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
  3521. * codec. Subsequent calls will do nothing.
  3522. *
  3523. * @note Do not use this function. Use avcodec_free_context() to destroy a
  3524. * codec context (either open or closed). Opening and closing a codec context
  3525. * multiple times is not supported anymore -- use multiple codec contexts
  3526. * instead.
  3527. */
  3528. int avcodec_close(AVCodecContext *avctx);
  3529. /**
  3530. * Free all allocated data in the given subtitle struct.
  3531. *
  3532. * @param sub AVSubtitle to free.
  3533. */
  3534. void avsubtitle_free(AVSubtitle *sub);
  3535. /**
  3536. * @}
  3537. */
  3538. /**
  3539. * @addtogroup lavc_packet
  3540. * @{
  3541. */
  3542. /**
  3543. * Allocate an AVPacket and set its fields to default values. The resulting
  3544. * struct must be freed using av_packet_free().
  3545. *
  3546. * @return An AVPacket filled with default values or NULL on failure.
  3547. *
  3548. * @note this only allocates the AVPacket itself, not the data buffers. Those
  3549. * must be allocated through other means such as av_new_packet.
  3550. *
  3551. * @see av_new_packet
  3552. */
  3553. AVPacket *av_packet_alloc(void);
  3554. /**
  3555. * Create a new packet that references the same data as src.
  3556. *
  3557. * This is a shortcut for av_packet_alloc()+av_packet_ref().
  3558. *
  3559. * @return newly created AVPacket on success, NULL on error.
  3560. *
  3561. * @see av_packet_alloc
  3562. * @see av_packet_ref
  3563. */
  3564. AVPacket *av_packet_clone(const AVPacket *src);
  3565. /**
  3566. * Free the packet, if the packet is reference counted, it will be
  3567. * unreferenced first.
  3568. *
  3569. * @param pkt packet to be freed. The pointer will be set to NULL.
  3570. * @note passing NULL is a no-op.
  3571. */
  3572. void av_packet_free(AVPacket **pkt);
  3573. /**
  3574. * Initialize optional fields of a packet with default values.
  3575. *
  3576. * Note, this does not touch the data and size members, which have to be
  3577. * initialized separately.
  3578. *
  3579. * @param pkt packet
  3580. */
  3581. void av_init_packet(AVPacket *pkt);
  3582. /**
  3583. * Allocate the payload of a packet and initialize its fields with
  3584. * default values.
  3585. *
  3586. * @param pkt packet
  3587. * @param size wanted payload size
  3588. * @return 0 if OK, AVERROR_xxx otherwise
  3589. */
  3590. int av_new_packet(AVPacket *pkt, int size);
  3591. /**
  3592. * Reduce packet size, correctly zeroing padding
  3593. *
  3594. * @param pkt packet
  3595. * @param size new size
  3596. */
  3597. void av_shrink_packet(AVPacket *pkt, int size);
  3598. /**
  3599. * Increase packet size, correctly zeroing padding
  3600. *
  3601. * @param pkt packet
  3602. * @param grow_by number of bytes by which to increase the size of the packet
  3603. */
  3604. int av_grow_packet(AVPacket *pkt, int grow_by);
  3605. /**
  3606. * Initialize a reference-counted packet from av_malloc()ed data.
  3607. *
  3608. * @param pkt packet to be initialized. This function will set the data, size,
  3609. * buf and destruct fields, all others are left untouched.
  3610. * @param data Data allocated by av_malloc() to be used as packet data. If this
  3611. * function returns successfully, the data is owned by the underlying AVBuffer.
  3612. * The caller may not access the data through other means.
  3613. * @param size size of data in bytes, without the padding. I.e. the full buffer
  3614. * size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
  3615. *
  3616. * @return 0 on success, a negative AVERROR on error
  3617. */
  3618. int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
  3619. #if FF_API_AVPACKET_OLD_API
  3620. /**
  3621. * @warning This is a hack - the packet memory allocation stuff is broken. The
  3622. * packet is allocated if it was not really allocated.
  3623. *
  3624. * @deprecated Use av_packet_ref
  3625. */
  3626. attribute_deprecated
  3627. int av_dup_packet(AVPacket *pkt);
  3628. /**
  3629. * Free a packet.
  3630. *
  3631. * @deprecated Use av_packet_unref
  3632. *
  3633. * @param pkt packet to free
  3634. */
  3635. attribute_deprecated
  3636. void av_free_packet(AVPacket *pkt);
  3637. #endif
  3638. /**
  3639. * Allocate new information of a packet.
  3640. *
  3641. * @param pkt packet
  3642. * @param type side information type
  3643. * @param size side information size
  3644. * @return pointer to fresh allocated data or NULL otherwise
  3645. */
  3646. uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3647. int size);
  3648. /**
  3649. * Wrap an existing array as a packet side data.
  3650. *
  3651. * @param pkt packet
  3652. * @param type side information type
  3653. * @param data the side data array. It must be allocated with the av_malloc()
  3654. * family of functions. The ownership of the data is transferred to
  3655. * pkt.
  3656. * @param size side information size
  3657. * @return a non-negative number on success, a negative AVERROR code on
  3658. * failure. On failure, the packet is unchanged and the data remains
  3659. * owned by the caller.
  3660. */
  3661. int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3662. uint8_t *data, size_t size);
  3663. /**
  3664. * Shrink the already allocated side data buffer
  3665. *
  3666. * @param pkt packet
  3667. * @param type side information type
  3668. * @param size new side information size
  3669. * @return 0 on success, < 0 on failure
  3670. */
  3671. int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3672. int size);
  3673. /**
  3674. * Get side information from packet.
  3675. *
  3676. * @param pkt packet
  3677. * @param type desired side information type
  3678. * @param size pointer for side information size to store (optional)
  3679. * @return pointer to data if present or NULL otherwise
  3680. */
  3681. uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
  3682. int *size);
  3683. /**
  3684. * Convenience function to free all the side data stored.
  3685. * All the other fields stay untouched.
  3686. *
  3687. * @param pkt packet
  3688. */
  3689. void av_packet_free_side_data(AVPacket *pkt);
  3690. /**
  3691. * Setup a new reference to the data described by a given packet
  3692. *
  3693. * If src is reference-counted, setup dst as a new reference to the
  3694. * buffer in src. Otherwise allocate a new buffer in dst and copy the
  3695. * data from src into it.
  3696. *
  3697. * All the other fields are copied from src.
  3698. *
  3699. * @see av_packet_unref
  3700. *
  3701. * @param dst Destination packet
  3702. * @param src Source packet
  3703. *
  3704. * @return 0 on success, a negative AVERROR on error.
  3705. */
  3706. int av_packet_ref(AVPacket *dst, const AVPacket *src);
  3707. /**
  3708. * Wipe the packet.
  3709. *
  3710. * Unreference the buffer referenced by the packet and reset the
  3711. * remaining packet fields to their default values.
  3712. *
  3713. * @param pkt The packet to be unreferenced.
  3714. */
  3715. void av_packet_unref(AVPacket *pkt);
  3716. /**
  3717. * Move every field in src to dst and reset src.
  3718. *
  3719. * @see av_packet_unref
  3720. *
  3721. * @param src Source packet, will be reset
  3722. * @param dst Destination packet
  3723. */
  3724. void av_packet_move_ref(AVPacket *dst, AVPacket *src);
  3725. /**
  3726. * Copy only "properties" fields from src to dst.
  3727. *
  3728. * Properties for the purpose of this function are all the fields
  3729. * beside those related to the packet data (buf, data, size)
  3730. *
  3731. * @param dst Destination packet
  3732. * @param src Source packet
  3733. *
  3734. * @return 0 on success AVERROR on failure.
  3735. */
  3736. int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
  3737. /**
  3738. * Convert valid timing fields (timestamps / durations) in a packet from one
  3739. * timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
  3740. * ignored.
  3741. *
  3742. * @param pkt packet on which the conversion will be performed
  3743. * @param tb_src source timebase, in which the timing fields in pkt are
  3744. * expressed
  3745. * @param tb_dst destination timebase, to which the timing fields will be
  3746. * converted
  3747. */
  3748. void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
  3749. /**
  3750. * @}
  3751. */
  3752. /**
  3753. * @addtogroup lavc_decoding
  3754. * @{
  3755. */
  3756. /**
  3757. * Find a registered decoder with a matching codec ID.
  3758. *
  3759. * @param id AVCodecID of the requested decoder
  3760. * @return A decoder if one was found, NULL otherwise.
  3761. */
  3762. AVCodec *avcodec_find_decoder(enum AVCodecID id);
  3763. /**
  3764. * Find a registered decoder with the specified name.
  3765. *
  3766. * @param name name of the requested decoder
  3767. * @return A decoder if one was found, NULL otherwise.
  3768. */
  3769. AVCodec *avcodec_find_decoder_by_name(const char *name);
  3770. /**
  3771. * The default callback for AVCodecContext.get_buffer2(). It is made public so
  3772. * it can be called by custom get_buffer2() implementations for decoders without
  3773. * AV_CODEC_CAP_DR1 set.
  3774. */
  3775. int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags);
  3776. #if FF_API_EMU_EDGE
  3777. /**
  3778. * Return the amount of padding in pixels which the get_buffer callback must
  3779. * provide around the edge of the image for codecs which do not have the
  3780. * CODEC_FLAG_EMU_EDGE flag.
  3781. *
  3782. * @return Required padding in pixels.
  3783. *
  3784. * @deprecated CODEC_FLAG_EMU_EDGE is deprecated, so this function is no longer
  3785. * needed
  3786. */
  3787. attribute_deprecated
  3788. unsigned avcodec_get_edge_width(void);
  3789. #endif
  3790. /**
  3791. * Modify width and height values so that they will result in a memory
  3792. * buffer that is acceptable for the codec if you do not use any horizontal
  3793. * padding.
  3794. *
  3795. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  3796. */
  3797. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
  3798. /**
  3799. * Modify width and height values so that they will result in a memory
  3800. * buffer that is acceptable for the codec if you also ensure that all
  3801. * line sizes are a multiple of the respective linesize_align[i].
  3802. *
  3803. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  3804. */
  3805. void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
  3806. int linesize_align[AV_NUM_DATA_POINTERS]);
  3807. /**
  3808. * Decode the audio frame of size avpkt->size from avpkt->data into frame.
  3809. *
  3810. * Some decoders may support multiple frames in a single AVPacket. Such
  3811. * decoders would then just decode the first frame and the return value would be
  3812. * less than the packet size. In this case, avcodec_decode_audio4 has to be
  3813. * called again with an AVPacket containing the remaining data in order to
  3814. * decode the second frame, etc... Even if no frames are returned, the packet
  3815. * needs to be fed to the decoder with remaining data until it is completely
  3816. * consumed or an error occurs.
  3817. *
  3818. * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input
  3819. * and output. This means that for some packets they will not immediately
  3820. * produce decoded output and need to be flushed at the end of decoding to get
  3821. * all the decoded data. Flushing is done by calling this function with packets
  3822. * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
  3823. * returning samples. It is safe to flush even those decoders that are not
  3824. * marked with AV_CODEC_CAP_DELAY, then no samples will be returned.
  3825. *
  3826. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  3827. * larger than the actual read bytes because some optimized bitstream
  3828. * readers read 32 or 64 bits at once and could read over the end.
  3829. *
  3830. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3831. * before packets may be fed to the decoder.
  3832. *
  3833. * @param avctx the codec context
  3834. * @param[out] frame The AVFrame in which to store decoded audio samples.
  3835. * The decoder will allocate a buffer for the decoded frame by
  3836. * calling the AVCodecContext.get_buffer2() callback.
  3837. * When AVCodecContext.refcounted_frames is set to 1, the frame is
  3838. * reference counted and the returned reference belongs to the
  3839. * caller. The caller must release the frame using av_frame_unref()
  3840. * when the frame is no longer needed. The caller may safely write
  3841. * to the frame if av_frame_is_writable() returns 1.
  3842. * When AVCodecContext.refcounted_frames is set to 0, the returned
  3843. * reference belongs to the decoder and is valid only until the
  3844. * next call to this function or until closing or flushing the
  3845. * decoder. The caller may not write to it.
  3846. * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
  3847. * non-zero. Note that this field being set to zero
  3848. * does not mean that an error has occurred. For
  3849. * decoders with AV_CODEC_CAP_DELAY set, no given decode
  3850. * call is guaranteed to produce a frame.
  3851. * @param[in] avpkt The input AVPacket containing the input buffer.
  3852. * At least avpkt->data and avpkt->size should be set. Some
  3853. * decoders might also require additional fields to be set.
  3854. * @return A negative error code is returned if an error occurred during
  3855. * decoding, otherwise the number of bytes consumed from the input
  3856. * AVPacket is returned.
  3857. *
  3858. * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
  3859. */
  3860. attribute_deprecated
  3861. int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
  3862. int *got_frame_ptr, AVPacket *avpkt);
  3863. /**
  3864. * Decode the video frame of size avpkt->size from avpkt->data into picture.
  3865. * Some decoders may support multiple frames in a single AVPacket, such
  3866. * decoders would then just decode the first frame.
  3867. *
  3868. * @warning The input buffer must be AV_INPUT_BUFFER_PADDING_SIZE larger than
  3869. * the actual read bytes because some optimized bitstream readers read 32 or 64
  3870. * bits at once and could read over the end.
  3871. *
  3872. * @warning The end of the input buffer buf should be set to 0 to ensure that
  3873. * no overreading happens for damaged MPEG streams.
  3874. *
  3875. * @note Codecs which have the AV_CODEC_CAP_DELAY capability set have a delay
  3876. * between input and output, these need to be fed with avpkt->data=NULL,
  3877. * avpkt->size=0 at the end to return the remaining frames.
  3878. *
  3879. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3880. * before packets may be fed to the decoder.
  3881. *
  3882. * @param avctx the codec context
  3883. * @param[out] picture The AVFrame in which the decoded video frame will be stored.
  3884. * Use av_frame_alloc() to get an AVFrame. The codec will
  3885. * allocate memory for the actual bitmap by calling the
  3886. * AVCodecContext.get_buffer2() callback.
  3887. * When AVCodecContext.refcounted_frames is set to 1, the frame is
  3888. * reference counted and the returned reference belongs to the
  3889. * caller. The caller must release the frame using av_frame_unref()
  3890. * when the frame is no longer needed. The caller may safely write
  3891. * to the frame if av_frame_is_writable() returns 1.
  3892. * When AVCodecContext.refcounted_frames is set to 0, the returned
  3893. * reference belongs to the decoder and is valid only until the
  3894. * next call to this function or until closing or flushing the
  3895. * decoder. The caller may not write to it.
  3896. *
  3897. * @param[in] avpkt The input AVPacket containing the input buffer.
  3898. * You can create such packet with av_init_packet() and by then setting
  3899. * data and size, some decoders might in addition need other fields like
  3900. * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
  3901. * fields possible.
  3902. * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
  3903. * @return On error a negative value is returned, otherwise the number of bytes
  3904. * used or zero if no frame could be decompressed.
  3905. *
  3906. * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
  3907. */
  3908. attribute_deprecated
  3909. int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
  3910. int *got_picture_ptr,
  3911. AVPacket *avpkt);
  3912. /**
  3913. * Decode a subtitle message.
  3914. * Return a negative value on error, otherwise return the number of bytes used.
  3915. * If no subtitle could be decompressed, got_sub_ptr is zero.
  3916. * Otherwise, the subtitle is stored in *sub.
  3917. * Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for
  3918. * simplicity, because the performance difference is expect to be negligible
  3919. * and reusing a get_buffer written for video codecs would probably perform badly
  3920. * due to a potentially very different allocation pattern.
  3921. *
  3922. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3923. * before packets may be fed to the decoder.
  3924. *
  3925. * @param avctx the codec context
  3926. * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
  3927. freed with avsubtitle_free if *got_sub_ptr is set.
  3928. * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
  3929. * @param[in] avpkt The input AVPacket containing the input buffer.
  3930. */
  3931. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  3932. int *got_sub_ptr,
  3933. AVPacket *avpkt);
  3934. /**
  3935. * Supply raw packet data as input to a decoder.
  3936. *
  3937. * Internally, this call will copy relevant AVCodecContext fields, which can
  3938. * influence decoding per-packet, and apply them when the packet is actually
  3939. * decoded. (For example AVCodecContext.skip_frame, which might direct the
  3940. * decoder to drop the frame contained by the packet sent with this function.)
  3941. *
  3942. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  3943. * larger than the actual read bytes because some optimized bitstream
  3944. * readers read 32 or 64 bits at once and could read over the end.
  3945. *
  3946. * @warning Do not mix this API with the legacy API (like avcodec_decode_video2())
  3947. * on the same AVCodecContext. It will return unexpected results now
  3948. * or in future libavcodec versions.
  3949. *
  3950. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  3951. * before packets may be fed to the decoder.
  3952. *
  3953. * @param avctx codec context
  3954. * @param[in] avpkt The input AVPacket. Usually, this will be a single video
  3955. * frame, or several complete audio frames.
  3956. * Ownership of the packet remains with the caller, and the
  3957. * decoder will not write to the packet. The decoder may create
  3958. * a reference to the packet data (or copy it if the packet is
  3959. * not reference-counted).
  3960. * Unlike with older APIs, the packet is always fully consumed,
  3961. * and if it contains multiple frames (e.g. some audio codecs),
  3962. * will require you to call avcodec_receive_frame() multiple
  3963. * times afterwards before you can send a new packet.
  3964. * It can be NULL (or an AVPacket with data set to NULL and
  3965. * size set to 0); in this case, it is considered a flush
  3966. * packet, which signals the end of the stream. Sending the
  3967. * first flush packet will return success. Subsequent ones are
  3968. * unnecessary and will return AVERROR_EOF. If the decoder
  3969. * still has frames buffered, it will return them after sending
  3970. * a flush packet.
  3971. *
  3972. * @return 0 on success, otherwise negative error code:
  3973. * AVERROR(EAGAIN): input is not accepted in the current state - user
  3974. * must read output with avcodec_receive_frame() (once
  3975. * all output is read, the packet should be resent, and
  3976. * the call will not fail with EAGAIN).
  3977. * AVERROR_EOF: the decoder has been flushed, and no new packets can
  3978. * be sent to it (also returned if more than 1 flush
  3979. * packet is sent)
  3980. * AVERROR(EINVAL): codec not opened, it is an encoder, or requires flush
  3981. * AVERROR(ENOMEM): failed to add packet to internal queue, or similar
  3982. * other errors: legitimate decoding errors
  3983. */
  3984. int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
  3985. /**
  3986. * Return decoded output data from a decoder.
  3987. *
  3988. * @param avctx codec context
  3989. * @param frame This will be set to a reference-counted video or audio
  3990. * frame (depending on the decoder type) allocated by the
  3991. * decoder. Note that the function will always call
  3992. * av_frame_unref(frame) before doing anything else.
  3993. *
  3994. * @return
  3995. * 0: success, a frame was returned
  3996. * AVERROR(EAGAIN): output is not available in this state - user must try
  3997. * to send new input
  3998. * AVERROR_EOF: the decoder has been fully flushed, and there will be
  3999. * no more output frames
  4000. * AVERROR(EINVAL): codec not opened, or it is an encoder
  4001. * other negative values: legitimate decoding errors
  4002. */
  4003. int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
  4004. /**
  4005. * Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet()
  4006. * to retrieve buffered output packets.
  4007. *
  4008. * @param avctx codec context
  4009. * @param[in] frame AVFrame containing the raw audio or video frame to be encoded.
  4010. * Ownership of the frame remains with the caller, and the
  4011. * encoder will not write to the frame. The encoder may create
  4012. * a reference to the frame data (or copy it if the frame is
  4013. * not reference-counted).
  4014. * It can be NULL, in which case it is considered a flush
  4015. * packet. This signals the end of the stream. If the encoder
  4016. * still has packets buffered, it will return them after this
  4017. * call. Once flushing mode has been entered, additional flush
  4018. * packets are ignored, and sending frames will return
  4019. * AVERROR_EOF.
  4020. *
  4021. * For audio:
  4022. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  4023. * can have any number of samples.
  4024. * If it is not set, frame->nb_samples must be equal to
  4025. * avctx->frame_size for all frames except the last.
  4026. * The final frame may be smaller than avctx->frame_size.
  4027. * @return 0 on success, otherwise negative error code:
  4028. * AVERROR(EAGAIN): input is not accepted in the current state - user
  4029. * must read output with avcodec_receive_packet() (once
  4030. * all output is read, the packet should be resent, and
  4031. * the call will not fail with EAGAIN).
  4032. * AVERROR_EOF: the encoder has been flushed, and no new frames can
  4033. * be sent to it
  4034. * AVERROR(EINVAL): codec not opened, refcounted_frames not set, it is a
  4035. * decoder, or requires flush
  4036. * AVERROR(ENOMEM): failed to add packet to internal queue, or similar
  4037. * other errors: legitimate decoding errors
  4038. */
  4039. int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
  4040. /**
  4041. * Read encoded data from the encoder.
  4042. *
  4043. * @param avctx codec context
  4044. * @param avpkt This will be set to a reference-counted packet allocated by the
  4045. * encoder. Note that the function will always call
  4046. * av_frame_unref(frame) before doing anything else.
  4047. * @return 0 on success, otherwise negative error code:
  4048. * AVERROR(EAGAIN): output is not available in the current state - user
  4049. * must try to send input
  4050. * AVERROR_EOF: the encoder has been fully flushed, and there will be
  4051. * no more output packets
  4052. * AVERROR(EINVAL): codec not opened, or it is an encoder
  4053. * other errors: legitimate decoding errors
  4054. */
  4055. int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  4056. /**
  4057. * @defgroup lavc_parsing Frame parsing
  4058. * @{
  4059. */
  4060. enum AVPictureStructure {
  4061. AV_PICTURE_STRUCTURE_UNKNOWN, //< unknown
  4062. AV_PICTURE_STRUCTURE_TOP_FIELD, //< coded as top field
  4063. AV_PICTURE_STRUCTURE_BOTTOM_FIELD, //< coded as bottom field
  4064. AV_PICTURE_STRUCTURE_FRAME, //< coded as frame
  4065. };
  4066. typedef struct AVCodecParserContext {
  4067. void *priv_data;
  4068. struct AVCodecParser *parser;
  4069. int64_t frame_offset; /* offset of the current frame */
  4070. int64_t cur_offset; /* current offset
  4071. (incremented by each av_parser_parse()) */
  4072. int64_t next_frame_offset; /* offset of the next frame */
  4073. /* video info */
  4074. int pict_type; /* XXX: Put it back in AVCodecContext. */
  4075. /**
  4076. * This field is used for proper frame duration computation in lavf.
  4077. * It signals, how much longer the frame duration of the current frame
  4078. * is compared to normal frame duration.
  4079. *
  4080. * frame_duration = (1 + repeat_pict) * time_base
  4081. *
  4082. * It is used by codecs like H.264 to display telecined material.
  4083. */
  4084. int repeat_pict; /* XXX: Put it back in AVCodecContext. */
  4085. int64_t pts; /* pts of the current frame */
  4086. int64_t dts; /* dts of the current frame */
  4087. /* private data */
  4088. int64_t last_pts;
  4089. int64_t last_dts;
  4090. int fetch_timestamp;
  4091. #define AV_PARSER_PTS_NB 4
  4092. int cur_frame_start_index;
  4093. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
  4094. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
  4095. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
  4096. int flags;
  4097. #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
  4098. #define PARSER_FLAG_ONCE 0x0002
  4099. /// Set if the parser has a valid file offset
  4100. #define PARSER_FLAG_FETCHED_OFFSET 0x0004
  4101. int64_t offset; ///< byte offset from starting packet start
  4102. int64_t cur_frame_end[AV_PARSER_PTS_NB];
  4103. /**
  4104. * Set by parser to 1 for key frames and 0 for non-key frames.
  4105. * It is initialized to -1, so if the parser doesn't set this flag,
  4106. * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
  4107. * will be used.
  4108. */
  4109. int key_frame;
  4110. #if FF_API_CONVERGENCE_DURATION
  4111. /**
  4112. * @deprecated unused
  4113. */
  4114. attribute_deprecated
  4115. int64_t convergence_duration;
  4116. #endif
  4117. // Timestamp generation support:
  4118. /**
  4119. * Synchronization point for start of timestamp generation.
  4120. *
  4121. * Set to >0 for sync point, 0 for no sync point and <0 for undefined
  4122. * (default).
  4123. *
  4124. * For example, this corresponds to presence of H.264 buffering period
  4125. * SEI message.
  4126. */
  4127. int dts_sync_point;
  4128. /**
  4129. * Offset of the current timestamp against last timestamp sync point in
  4130. * units of AVCodecContext.time_base.
  4131. *
  4132. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  4133. * contain a valid timestamp offset.
  4134. *
  4135. * Note that the timestamp of sync point has usually a nonzero
  4136. * dts_ref_dts_delta, which refers to the previous sync point. Offset of
  4137. * the next frame after timestamp sync point will be usually 1.
  4138. *
  4139. * For example, this corresponds to H.264 cpb_removal_delay.
  4140. */
  4141. int dts_ref_dts_delta;
  4142. /**
  4143. * Presentation delay of current frame in units of AVCodecContext.time_base.
  4144. *
  4145. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  4146. * contain valid non-negative timestamp delta (presentation time of a frame
  4147. * must not lie in the past).
  4148. *
  4149. * This delay represents the difference between decoding and presentation
  4150. * time of the frame.
  4151. *
  4152. * For example, this corresponds to H.264 dpb_output_delay.
  4153. */
  4154. int pts_dts_delta;
  4155. /**
  4156. * Position of the packet in file.
  4157. *
  4158. * Analogous to cur_frame_pts/dts
  4159. */
  4160. int64_t cur_frame_pos[AV_PARSER_PTS_NB];
  4161. /**
  4162. * Byte position of currently parsed frame in stream.
  4163. */
  4164. int64_t pos;
  4165. /**
  4166. * Previous frame byte position.
  4167. */
  4168. int64_t last_pos;
  4169. /**
  4170. * Duration of the current frame.
  4171. * For audio, this is in units of 1 / AVCodecContext.sample_rate.
  4172. * For all other types, this is in units of AVCodecContext.time_base.
  4173. */
  4174. int duration;
  4175. enum AVFieldOrder field_order;
  4176. /**
  4177. * Indicate whether a picture is coded as a frame, top field or bottom field.
  4178. *
  4179. * For example, H.264 field_pic_flag equal to 0 corresponds to
  4180. * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
  4181. * equal to 1 and bottom_field_flag equal to 0 corresponds to
  4182. * AV_PICTURE_STRUCTURE_TOP_FIELD.
  4183. */
  4184. enum AVPictureStructure picture_structure;
  4185. /**
  4186. * Picture number incremented in presentation or output order.
  4187. * This field may be reinitialized at the first picture of a new sequence.
  4188. *
  4189. * For example, this corresponds to H.264 PicOrderCnt.
  4190. */
  4191. int output_picture_number;
  4192. /**
  4193. * Dimensions of the decoded video intended for presentation.
  4194. */
  4195. int width;
  4196. int height;
  4197. /**
  4198. * Dimensions of the coded video.
  4199. */
  4200. int coded_width;
  4201. int coded_height;
  4202. /**
  4203. * The format of the coded data, corresponds to enum AVPixelFormat for video
  4204. * and for enum AVSampleFormat for audio.
  4205. *
  4206. * Note that a decoder can have considerable freedom in how exactly it
  4207. * decodes the data, so the format reported here might be different from the
  4208. * one returned by a decoder.
  4209. */
  4210. int format;
  4211. } AVCodecParserContext;
  4212. typedef struct AVCodecParser {
  4213. int codec_ids[5]; /* several codec IDs are permitted */
  4214. int priv_data_size;
  4215. int (*parser_init)(AVCodecParserContext *s);
  4216. /* This callback never returns an error, a negative value means that
  4217. * the frame start was in a previous packet. */
  4218. int (*parser_parse)(AVCodecParserContext *s,
  4219. AVCodecContext *avctx,
  4220. const uint8_t **poutbuf, int *poutbuf_size,
  4221. const uint8_t *buf, int buf_size);
  4222. void (*parser_close)(AVCodecParserContext *s);
  4223. int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  4224. struct AVCodecParser *next;
  4225. } AVCodecParser;
  4226. AVCodecParser *av_parser_next(const AVCodecParser *c);
  4227. void av_register_codec_parser(AVCodecParser *parser);
  4228. AVCodecParserContext *av_parser_init(int codec_id);
  4229. /**
  4230. * Parse a packet.
  4231. *
  4232. * @param s parser context.
  4233. * @param avctx codec context.
  4234. * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
  4235. * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
  4236. * @param buf input buffer.
  4237. * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
  4238. * @param pts input presentation timestamp.
  4239. * @param dts input decoding timestamp.
  4240. * @param pos input byte position in stream.
  4241. * @return the number of bytes of the input bitstream used.
  4242. *
  4243. * Example:
  4244. * @code
  4245. * while(in_len){
  4246. * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
  4247. * in_data, in_len,
  4248. * pts, dts, pos);
  4249. * in_data += len;
  4250. * in_len -= len;
  4251. *
  4252. * if(size)
  4253. * decode_frame(data, size);
  4254. * }
  4255. * @endcode
  4256. */
  4257. int av_parser_parse2(AVCodecParserContext *s,
  4258. AVCodecContext *avctx,
  4259. uint8_t **poutbuf, int *poutbuf_size,
  4260. const uint8_t *buf, int buf_size,
  4261. int64_t pts, int64_t dts,
  4262. int64_t pos);
  4263. /**
  4264. * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
  4265. * @deprecated use AVBitstreamFilter
  4266. */
  4267. int av_parser_change(AVCodecParserContext *s,
  4268. AVCodecContext *avctx,
  4269. uint8_t **poutbuf, int *poutbuf_size,
  4270. const uint8_t *buf, int buf_size, int keyframe);
  4271. void av_parser_close(AVCodecParserContext *s);
  4272. /**
  4273. * @}
  4274. * @}
  4275. */
  4276. /**
  4277. * @addtogroup lavc_encoding
  4278. * @{
  4279. */
  4280. /**
  4281. * Find a registered encoder with a matching codec ID.
  4282. *
  4283. * @param id AVCodecID of the requested encoder
  4284. * @return An encoder if one was found, NULL otherwise.
  4285. */
  4286. AVCodec *avcodec_find_encoder(enum AVCodecID id);
  4287. /**
  4288. * Find a registered encoder with the specified name.
  4289. *
  4290. * @param name name of the requested encoder
  4291. * @return An encoder if one was found, NULL otherwise.
  4292. */
  4293. AVCodec *avcodec_find_encoder_by_name(const char *name);
  4294. /**
  4295. * Encode a frame of audio.
  4296. *
  4297. * Takes input samples from frame and writes the next output packet, if
  4298. * available, to avpkt. The output packet does not necessarily contain data for
  4299. * the most recent frame, as encoders can delay, split, and combine input frames
  4300. * internally as needed.
  4301. *
  4302. * @param avctx codec context
  4303. * @param avpkt output AVPacket.
  4304. * The user can supply an output buffer by setting
  4305. * avpkt->data and avpkt->size prior to calling the
  4306. * function, but if the size of the user-provided data is not
  4307. * large enough, encoding will fail. All other AVPacket fields
  4308. * will be reset by the encoder using av_init_packet(). If
  4309. * avpkt->data is NULL, the encoder will allocate it.
  4310. * The encoder will set avpkt->size to the size of the
  4311. * output packet.
  4312. *
  4313. * If this function fails or produces no output, avpkt will be
  4314. * freed using av_packet_unref().
  4315. * @param[in] frame AVFrame containing the raw audio data to be encoded.
  4316. * May be NULL when flushing an encoder that has the
  4317. * AV_CODEC_CAP_DELAY capability set.
  4318. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  4319. * can have any number of samples.
  4320. * If it is not set, frame->nb_samples must be equal to
  4321. * avctx->frame_size for all frames except the last.
  4322. * The final frame may be smaller than avctx->frame_size.
  4323. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  4324. * output packet is non-empty, and to 0 if it is
  4325. * empty. If the function returns an error, the
  4326. * packet can be assumed to be invalid, and the
  4327. * value of got_packet_ptr is undefined and should
  4328. * not be used.
  4329. * @return 0 on success, negative error code on failure
  4330. *
  4331. * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead
  4332. */
  4333. attribute_deprecated
  4334. int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
  4335. const AVFrame *frame, int *got_packet_ptr);
  4336. /**
  4337. * Encode a frame of video.
  4338. *
  4339. * Takes input raw video data from frame and writes the next output packet, if
  4340. * available, to avpkt. The output packet does not necessarily contain data for
  4341. * the most recent frame, as encoders can delay and reorder input frames
  4342. * internally as needed.
  4343. *
  4344. * @param avctx codec context
  4345. * @param avpkt output AVPacket.
  4346. * The user can supply an output buffer by setting
  4347. * avpkt->data and avpkt->size prior to calling the
  4348. * function, but if the size of the user-provided data is not
  4349. * large enough, encoding will fail. All other AVPacket fields
  4350. * will be reset by the encoder using av_init_packet(). If
  4351. * avpkt->data is NULL, the encoder will allocate it.
  4352. * The encoder will set avpkt->size to the size of the
  4353. * output packet. The returned data (if any) belongs to the
  4354. * caller, he is responsible for freeing it.
  4355. *
  4356. * If this function fails or produces no output, avpkt will be
  4357. * freed using av_packet_unref().
  4358. * @param[in] frame AVFrame containing the raw video data to be encoded.
  4359. * May be NULL when flushing an encoder that has the
  4360. * AV_CODEC_CAP_DELAY capability set.
  4361. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  4362. * output packet is non-empty, and to 0 if it is
  4363. * empty. If the function returns an error, the
  4364. * packet can be assumed to be invalid, and the
  4365. * value of got_packet_ptr is undefined and should
  4366. * not be used.
  4367. * @return 0 on success, negative error code on failure
  4368. *
  4369. * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead
  4370. */
  4371. attribute_deprecated
  4372. int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
  4373. const AVFrame *frame, int *got_packet_ptr);
  4374. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  4375. const AVSubtitle *sub);
  4376. /**
  4377. * @}
  4378. */
  4379. #if FF_API_AVPICTURE
  4380. /**
  4381. * @addtogroup lavc_picture
  4382. * @{
  4383. */
  4384. /**
  4385. * @deprecated unused
  4386. */
  4387. attribute_deprecated
  4388. int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height);
  4389. /**
  4390. * @deprecated unused
  4391. */
  4392. attribute_deprecated
  4393. void avpicture_free(AVPicture *picture);
  4394. /**
  4395. * @deprecated use av_image_fill_arrays() instead.
  4396. */
  4397. attribute_deprecated
  4398. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  4399. enum AVPixelFormat pix_fmt, int width, int height);
  4400. /**
  4401. * @deprecated use av_image_copy_to_buffer() instead.
  4402. */
  4403. attribute_deprecated
  4404. int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt,
  4405. int width, int height,
  4406. unsigned char *dest, int dest_size);
  4407. /**
  4408. * @deprecated use av_image_get_buffer_size() instead.
  4409. */
  4410. attribute_deprecated
  4411. int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
  4412. /**
  4413. * @deprecated av_image_copy() instead.
  4414. */
  4415. attribute_deprecated
  4416. void av_picture_copy(AVPicture *dst, const AVPicture *src,
  4417. enum AVPixelFormat pix_fmt, int width, int height);
  4418. /**
  4419. * @deprecated unused
  4420. */
  4421. attribute_deprecated
  4422. int av_picture_crop(AVPicture *dst, const AVPicture *src,
  4423. enum AVPixelFormat pix_fmt, int top_band, int left_band);
  4424. /**
  4425. * @deprecated unused
  4426. */
  4427. attribute_deprecated
  4428. int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum AVPixelFormat pix_fmt,
  4429. int padtop, int padbottom, int padleft, int padright, int *color);
  4430. /**
  4431. * @}
  4432. */
  4433. #endif
  4434. /**
  4435. * @defgroup lavc_misc Utility functions
  4436. * @ingroup libavc
  4437. *
  4438. * Miscellaneous utility functions related to both encoding and decoding
  4439. * (or neither).
  4440. * @{
  4441. */
  4442. /**
  4443. * @defgroup lavc_misc_pixfmt Pixel formats
  4444. *
  4445. * Functions for working with pixel formats.
  4446. * @{
  4447. */
  4448. /**
  4449. * Return a value representing the fourCC code associated to the
  4450. * pixel format pix_fmt, or 0 if no associated fourCC code can be
  4451. * found.
  4452. */
  4453. unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt);
  4454. #define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
  4455. #define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
  4456. #define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
  4457. #define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
  4458. #define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
  4459. #define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
  4460. /**
  4461. * Compute what kind of losses will occur when converting from one specific
  4462. * pixel format to another.
  4463. * When converting from one pixel format to another, information loss may occur.
  4464. * For example, when converting from RGB24 to GRAY, the color information will
  4465. * be lost. Similarly, other losses occur when converting from some formats to
  4466. * other formats. These losses can involve loss of chroma, but also loss of
  4467. * resolution, loss of color depth, loss due to the color space conversion, loss
  4468. * of the alpha bits or loss due to color quantization.
  4469. * avcodec_get_fix_fmt_loss() informs you about the various types of losses
  4470. * which will occur when converting from one pixel format to another.
  4471. *
  4472. * @param[in] dst_pix_fmt destination pixel format
  4473. * @param[in] src_pix_fmt source pixel format
  4474. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  4475. * @return Combination of flags informing you what kind of losses will occur.
  4476. */
  4477. int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
  4478. int has_alpha);
  4479. /**
  4480. * Find the best pixel format to convert to given a certain source pixel
  4481. * format. When converting from one pixel format to another, information loss
  4482. * may occur. For example, when converting from RGB24 to GRAY, the color
  4483. * information will be lost. Similarly, other losses occur when converting from
  4484. * some formats to other formats. avcodec_find_best_pix_fmt2() searches which of
  4485. * the given pixel formats should be used to suffer the least amount of loss.
  4486. * The pixel formats from which it chooses one, are determined by the
  4487. * pix_fmt_list parameter.
  4488. *
  4489. *
  4490. * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
  4491. * @param[in] src_pix_fmt source pixel format
  4492. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  4493. * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
  4494. * @return The best pixel format to convert to or -1 if none was found.
  4495. */
  4496. enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat *pix_fmt_list,
  4497. enum AVPixelFormat src_pix_fmt,
  4498. int has_alpha, int *loss_ptr);
  4499. enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  4500. /**
  4501. * @}
  4502. */
  4503. /**
  4504. * Put a string representing the codec tag codec_tag in buf.
  4505. *
  4506. * @param buf buffer to place codec tag in
  4507. * @param buf_size size in bytes of buf
  4508. * @param codec_tag codec tag to assign
  4509. * @return the length of the string that would have been generated if
  4510. * enough space had been available, excluding the trailing null
  4511. */
  4512. size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);
  4513. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  4514. /**
  4515. * Return a name for the specified profile, if available.
  4516. *
  4517. * @param codec the codec that is searched for the given profile
  4518. * @param profile the profile value for which a name is requested
  4519. * @return A name for the profile if found, NULL otherwise.
  4520. */
  4521. const char *av_get_profile_name(const AVCodec *codec, int profile);
  4522. /**
  4523. * Return a name for the specified profile, if available.
  4524. *
  4525. * @param codec_id the ID of the codec to which the requested profile belongs
  4526. * @param profile the profile value for which a name is requested
  4527. * @return A name for the profile if found, NULL otherwise.
  4528. *
  4529. * @note unlike av_get_profile_name(), which searches a list of profiles
  4530. * supported by a specific decoder or encoder implementation, this
  4531. * function searches the list of profiles from the AVCodecDescriptor
  4532. */
  4533. const char *avcodec_profile_name(enum AVCodecID codec_id, int profile);
  4534. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
  4535. int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
  4536. //FIXME func typedef
  4537. /**
  4538. * Fill audio frame data and linesize.
  4539. * AVFrame extended_data channel pointers are allocated if necessary for
  4540. * planar audio.
  4541. *
  4542. * @param frame the AVFrame
  4543. * frame->nb_samples must be set prior to calling the
  4544. * function. This function fills in frame->data,
  4545. * frame->extended_data, frame->linesize[0].
  4546. * @param nb_channels channel count
  4547. * @param sample_fmt sample format
  4548. * @param buf buffer to use for frame data
  4549. * @param buf_size size of buffer
  4550. * @param align plane size sample alignment (0 = default)
  4551. * @return 0 on success, negative error code on failure
  4552. */
  4553. int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
  4554. enum AVSampleFormat sample_fmt, const uint8_t *buf,
  4555. int buf_size, int align);
  4556. /**
  4557. * Reset the internal decoder state / flush internal buffers. Should be called
  4558. * e.g. when seeking or when switching to a different stream.
  4559. *
  4560. * @note when refcounted frames are not used (i.e. avctx->refcounted_frames is 0),
  4561. * this invalidates the frames previously returned from the decoder. When
  4562. * refcounted frames are used, the decoder just releases any references it might
  4563. * keep internally, but the caller's reference remains valid.
  4564. */
  4565. void avcodec_flush_buffers(AVCodecContext *avctx);
  4566. /**
  4567. * Return codec bits per sample.
  4568. *
  4569. * @param[in] codec_id the codec
  4570. * @return Number of bits per sample or zero if unknown for the given codec.
  4571. */
  4572. int av_get_bits_per_sample(enum AVCodecID codec_id);
  4573. /**
  4574. * Return codec bits per sample.
  4575. * Only return non-zero if the bits per sample is exactly correct, not an
  4576. * approximation.
  4577. *
  4578. * @param[in] codec_id the codec
  4579. * @return Number of bits per sample or zero if unknown for the given codec.
  4580. */
  4581. int av_get_exact_bits_per_sample(enum AVCodecID codec_id);
  4582. /**
  4583. * Return audio frame duration.
  4584. *
  4585. * @param avctx codec context
  4586. * @param frame_bytes size of the frame, or 0 if unknown
  4587. * @return frame duration, in samples, if known. 0 if not able to
  4588. * determine.
  4589. */
  4590. int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
  4591. /**
  4592. * This function is the same as av_get_audio_frame_duration(), except it works
  4593. * with AVCodecParameters instead of an AVCodecContext.
  4594. */
  4595. int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes);
  4596. #if FF_API_OLD_BSF
  4597. typedef struct AVBitStreamFilterContext {
  4598. void *priv_data;
  4599. struct AVBitStreamFilter *filter;
  4600. AVCodecParserContext *parser;
  4601. struct AVBitStreamFilterContext *next;
  4602. } AVBitStreamFilterContext;
  4603. #endif
  4604. typedef struct AVBSFInternal AVBSFInternal;
  4605. /**
  4606. * The bitstream filter state.
  4607. *
  4608. * This struct must be allocated with av_bsf_alloc() and freed with
  4609. * av_bsf_free().
  4610. *
  4611. * The fields in the struct will only be changed (by the caller or by the
  4612. * filter) as described in their documentation, and are to be considered
  4613. * immutable otherwise.
  4614. */
  4615. typedef struct AVBSFContext {
  4616. /**
  4617. * A class for logging and AVOptions
  4618. */
  4619. const AVClass *av_class;
  4620. /**
  4621. * The bitstream filter this context is an instance of.
  4622. */
  4623. const struct AVBitStreamFilter *filter;
  4624. /**
  4625. * Opaque libavcodec internal data. Must not be touched by the caller in any
  4626. * way.
  4627. */
  4628. AVBSFInternal *internal;
  4629. /**
  4630. * Opaque filter-specific private data. If filter->priv_class is non-NULL,
  4631. * this is an AVOptions-enabled struct.
  4632. */
  4633. void *priv_data;
  4634. /**
  4635. * Parameters of the input stream. This field is allocated in
  4636. * av_bsf_alloc(), it needs to be filled by the caller before
  4637. * av_bsf_init().
  4638. */
  4639. AVCodecParameters *par_in;
  4640. /**
  4641. * Parameters of the output stream. This field is allocated in
  4642. * av_bsf_alloc(), it is set by the filter in av_bsf_init().
  4643. */
  4644. AVCodecParameters *par_out;
  4645. /**
  4646. * The timebase used for the timestamps of the input packets. Set by the
  4647. * caller before av_bsf_init().
  4648. */
  4649. AVRational time_base_in;
  4650. /**
  4651. * The timebase used for the timestamps of the output packets. Set by the
  4652. * filter in av_bsf_init().
  4653. */
  4654. AVRational time_base_out;
  4655. } AVBSFContext;
  4656. typedef struct AVBitStreamFilter {
  4657. const char *name;
  4658. /**
  4659. * A list of codec ids supported by the filter, terminated by
  4660. * AV_CODEC_ID_NONE.
  4661. * May be NULL, in that case the bitstream filter works with any codec id.
  4662. */
  4663. const enum AVCodecID *codec_ids;
  4664. /**
  4665. * A class for the private data, used to declare bitstream filter private
  4666. * AVOptions. This field is NULL for bitstream filters that do not declare
  4667. * any options.
  4668. *
  4669. * If this field is non-NULL, the first member of the filter private data
  4670. * must be a pointer to AVClass, which will be set by libavcodec generic
  4671. * code to this class.
  4672. */
  4673. const AVClass *priv_class;
  4674. /*****************************************************************
  4675. * No fields below this line are part of the public API. They
  4676. * may not be used outside of libavcodec and can be changed and
  4677. * removed at will.
  4678. * New public fields should be added right above.
  4679. *****************************************************************
  4680. */
  4681. int priv_data_size;
  4682. int (*init)(AVBSFContext *ctx);
  4683. int (*filter)(AVBSFContext *ctx, AVPacket *pkt);
  4684. void (*close)(AVBSFContext *ctx);
  4685. } AVBitStreamFilter;
  4686. #if FF_API_OLD_BSF
  4687. /**
  4688. * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
  4689. * is deprecated. Use the new bitstream filtering API (using AVBSFContext).
  4690. */
  4691. attribute_deprecated
  4692. void av_register_bitstream_filter(AVBitStreamFilter *bsf);
  4693. attribute_deprecated
  4694. AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
  4695. attribute_deprecated
  4696. int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
  4697. AVCodecContext *avctx, const char *args,
  4698. uint8_t **poutbuf, int *poutbuf_size,
  4699. const uint8_t *buf, int buf_size, int keyframe);
  4700. attribute_deprecated
  4701. void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
  4702. attribute_deprecated
  4703. AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f);
  4704. #endif
  4705. /**
  4706. * @return a bitstream filter with the specified name or NULL if no such
  4707. * bitstream filter exists.
  4708. */
  4709. const AVBitStreamFilter *av_bsf_get_by_name(const char *name);
  4710. /**
  4711. * Iterate over all registered bitstream filters.
  4712. *
  4713. * @param opaque a pointer where libavcodec will store the iteration state. Must
  4714. * point to NULL to start the iteration.
  4715. *
  4716. * @return the next registered bitstream filter or NULL when the iteration is
  4717. * finished
  4718. */
  4719. const AVBitStreamFilter *av_bsf_next(void **opaque);
  4720. /**
  4721. * Allocate a context for a given bitstream filter. The caller must fill in the
  4722. * context parameters as described in the documentation and then call
  4723. * av_bsf_init() before sending any data to the filter.
  4724. *
  4725. * @param filter the filter for which to allocate an instance.
  4726. * @param ctx a pointer into which the pointer to the newly-allocated context
  4727. * will be written. It must be freed with av_bsf_free() after the
  4728. * filtering is done.
  4729. *
  4730. * @return 0 on success, a negative AVERROR code on failure
  4731. */
  4732. int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx);
  4733. /**
  4734. * Prepare the filter for use, after all the parameters and options have been
  4735. * set.
  4736. */
  4737. int av_bsf_init(AVBSFContext *ctx);
  4738. /**
  4739. * Submit a packet for filtering.
  4740. *
  4741. * After sending each packet, the filter must be completely drained by calling
  4742. * av_bsf_receive_packet() repeatedly until it returns AVERROR(EAGAIN) or
  4743. * AVERROR_EOF.
  4744. *
  4745. * @param pkt the packet to filter. The bitstream filter will take ownership of
  4746. * the packet and reset the contents of pkt. pkt is not touched if an error occurs.
  4747. * This parameter may be NULL, which signals the end of the stream (i.e. no more
  4748. * packets will be sent). That will cause the filter to output any packets it
  4749. * may have buffered internally.
  4750. *
  4751. * @return 0 on success, a negative AVERROR on error.
  4752. */
  4753. int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt);
  4754. /**
  4755. * Retrieve a filtered packet.
  4756. *
  4757. * @param[out] pkt this struct will be filled with the contents of the filtered
  4758. * packet. It is owned by the caller and must be freed using
  4759. * av_packet_unref() when it is no longer needed.
  4760. * This parameter should be "clean" (i.e. freshly allocated
  4761. * with av_packet_alloc() or unreffed with av_packet_unref())
  4762. * when this function is called. If this function returns
  4763. * successfully, the contents of pkt will be completely
  4764. * overwritten by the returned data. On failure, pkt is not
  4765. * touched.
  4766. *
  4767. * @return 0 on success. AVERROR(EAGAIN) if more packets need to be sent to the
  4768. * filter (using av_bsf_send_packet()) to get more output. AVERROR_EOF if there
  4769. * will be no further output from the filter. Another negative AVERROR value if
  4770. * an error occurs.
  4771. *
  4772. * @note one input packet may result in several output packets, so after sending
  4773. * a packet with av_bsf_send_packet(), this function needs to be called
  4774. * repeatedly until it stops returning 0. It is also possible for a filter to
  4775. * output fewer packets than were sent to it, so this function may return
  4776. * AVERROR(EAGAIN) immediately after a successful av_bsf_send_packet() call.
  4777. */
  4778. int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt);
  4779. /**
  4780. * Free a bitstream filter context and everything associated with it; write NULL
  4781. * into the supplied pointer.
  4782. */
  4783. void av_bsf_free(AVBSFContext **ctx);
  4784. /**
  4785. * Get the AVClass for AVBSFContext. It can be used in combination with
  4786. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  4787. *
  4788. * @see av_opt_find().
  4789. */
  4790. const AVClass *av_bsf_get_class(void);
  4791. /* memory */
  4792. /**
  4793. * Allocate a buffer with padding, reusing the given one if large enough.
  4794. *
  4795. * Same behaviour av_fast_malloc but the buffer has additional
  4796. * AV_INPUT_PADDING_SIZE at the end which will always memset to 0.
  4797. */
  4798. void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
  4799. /**
  4800. * Encode extradata length to a buffer. Used by xiph codecs.
  4801. *
  4802. * @param s buffer to write to; must be at least (v/255+1) bytes long
  4803. * @param v size of extradata in bytes
  4804. * @return number of bytes written to the buffer.
  4805. */
  4806. unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
  4807. /**
  4808. * Register the hardware accelerator hwaccel.
  4809. */
  4810. void av_register_hwaccel(AVHWAccel *hwaccel);
  4811. /**
  4812. * If hwaccel is NULL, returns the first registered hardware accelerator,
  4813. * if hwaccel is non-NULL, returns the next registered hardware accelerator
  4814. * after hwaccel, or NULL if hwaccel is the last one.
  4815. */
  4816. AVHWAccel *av_hwaccel_next(const AVHWAccel *hwaccel);
  4817. /**
  4818. * Lock operation used by lockmgr
  4819. */
  4820. enum AVLockOp {
  4821. AV_LOCK_CREATE, ///< Create a mutex
  4822. AV_LOCK_OBTAIN, ///< Lock the mutex
  4823. AV_LOCK_RELEASE, ///< Unlock the mutex
  4824. AV_LOCK_DESTROY, ///< Free mutex resources
  4825. };
  4826. /**
  4827. * Register a user provided lock manager supporting the operations
  4828. * specified by AVLockOp. The "mutex" argument to the function points
  4829. * to a (void *) where the lockmgr should store/get a pointer to a user
  4830. * allocated mutex. It is NULL upon AV_LOCK_CREATE and equal to the
  4831. * value left by the last call for all other ops. If the lock manager is
  4832. * unable to perform the op then it should leave the mutex in the same
  4833. * state as when it was called and return a non-zero value. However,
  4834. * when called with AV_LOCK_DESTROY the mutex will always be assumed to
  4835. * have been successfully destroyed. If av_lockmgr_register succeeds
  4836. * it will return a non-negative value, if it fails it will return a
  4837. * negative value and destroy all mutex and unregister all callbacks.
  4838. * av_lockmgr_register is not thread-safe, it must be called from a
  4839. * single thread before any calls which make use of locking are used.
  4840. *
  4841. * @param cb User defined callback. av_lockmgr_register invokes calls
  4842. * to this callback and the previously registered callback.
  4843. * The callback will be used to create more than one mutex
  4844. * each of which must be backed by its own underlying locking
  4845. * mechanism (i.e. do not use a single static object to
  4846. * implement your lock manager). If cb is set to NULL the
  4847. * lockmgr will be unregistered.
  4848. */
  4849. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
  4850. /**
  4851. * Get the type of the given codec.
  4852. */
  4853. enum AVMediaType avcodec_get_type(enum AVCodecID codec_id);
  4854. /**
  4855. * @return a positive value if s is open (i.e. avcodec_open2() was called on it
  4856. * with no corresponding avcodec_close()), 0 otherwise.
  4857. */
  4858. int avcodec_is_open(AVCodecContext *s);
  4859. /**
  4860. * @return a non-zero number if codec is an encoder, zero otherwise
  4861. */
  4862. int av_codec_is_encoder(const AVCodec *codec);
  4863. /**
  4864. * @return a non-zero number if codec is a decoder, zero otherwise
  4865. */
  4866. int av_codec_is_decoder(const AVCodec *codec);
  4867. /**
  4868. * @return descriptor for given codec ID or NULL if no descriptor exists.
  4869. */
  4870. const AVCodecDescriptor *avcodec_descriptor_get(enum AVCodecID id);
  4871. /**
  4872. * Iterate over all codec descriptors known to libavcodec.
  4873. *
  4874. * @param prev previous descriptor. NULL to get the first descriptor.
  4875. *
  4876. * @return next descriptor or NULL after the last descriptor
  4877. */
  4878. const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev);
  4879. /**
  4880. * @return codec descriptor with the given name or NULL if no such descriptor
  4881. * exists.
  4882. */
  4883. const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
  4884. /**
  4885. * Allocate a CPB properties structure and initialize its fields to default
  4886. * values.
  4887. *
  4888. * @param size if non-NULL, the size of the allocated struct will be written
  4889. * here. This is useful for embedding it in side data.
  4890. *
  4891. * @return the newly allocated struct or NULL on failure
  4892. */
  4893. AVCPBProperties *av_cpb_properties_alloc(size_t *size);
  4894. /**
  4895. * @}
  4896. */
  4897. #endif /* AVCODEC_AVCODEC_H */