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.

4936 lines
165KB

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