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.

4980 lines
168KB

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