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.

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