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.

4705 lines
148KB

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