frame.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file
  20. * @ingroup lavu_frame
  21. * reference-counted frame API
  22. */
  23. #ifndef AVUTIL_FRAME_H
  24. #define AVUTIL_FRAME_H
  25. #include <stddef.h>
  26. #include <stdint.h>
  27. #include "avutil.h"
  28. #include "buffer.h"
  29. #include "channel_layout.h"
  30. #include "dict.h"
  31. #include "rational.h"
  32. #include "samplefmt.h"
  33. #include "pixfmt.h"
  34. #include "version.h"
  35. /**
  36. * @defgroup lavu_frame AVFrame
  37. * @ingroup lavu_data
  38. *
  39. * @{
  40. * AVFrame is an abstraction for reference-counted raw multimedia data.
  41. */
  42. enum AVFrameSideDataType {
  43. /**
  44. * The data is the AVPanScan struct defined in libavcodec.
  45. */
  46. AV_FRAME_DATA_PANSCAN,
  47. /**
  48. * ATSC A53 Part 4 Closed Captions.
  49. * A53 CC bitstream is stored as uint8_t in AVFrameSideData.data.
  50. * The number of bytes of CC data is AVFrameSideData.size.
  51. */
  52. AV_FRAME_DATA_A53_CC,
  53. /**
  54. * Stereoscopic 3d metadata.
  55. * The data is the AVStereo3D struct defined in libavutil/stereo3d.h.
  56. */
  57. AV_FRAME_DATA_STEREO3D,
  58. /**
  59. * The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
  60. */
  61. AV_FRAME_DATA_MATRIXENCODING,
  62. /**
  63. * Metadata relevant to a downmix procedure.
  64. * The data is the AVDownmixInfo struct defined in libavutil/downmix_info.h.
  65. */
  66. AV_FRAME_DATA_DOWNMIX_INFO,
  67. /**
  68. * ReplayGain information in the form of the AVReplayGain struct.
  69. */
  70. AV_FRAME_DATA_REPLAYGAIN,
  71. /**
  72. * This side data contains a 3x3 transformation matrix describing an affine
  73. * transformation that needs to be applied to the frame for correct
  74. * presentation.
  75. *
  76. * See libavutil/display.h for a detailed description of the data.
  77. */
  78. AV_FRAME_DATA_DISPLAYMATRIX,
  79. /**
  80. * Active Format Description data consisting of a single byte as specified
  81. * in ETSI TS 101 154 using AVActiveFormatDescription enum.
  82. */
  83. AV_FRAME_DATA_AFD,
  84. /**
  85. * Motion vectors exported by some codecs (on demand through the export_mvs
  86. * flag set in the libavcodec AVCodecContext flags2 option).
  87. * The data is the AVMotionVector struct defined in
  88. * libavutil/motion_vector.h.
  89. */
  90. AV_FRAME_DATA_MOTION_VECTORS,
  91. /**
  92. * Recommmends skipping the specified number of samples. This is exported
  93. * only if the "skip_manual" AVOption is set in libavcodec.
  94. * This has the same format as AV_PKT_DATA_SKIP_SAMPLES.
  95. * @code
  96. * u32le number of samples to skip from start of this packet
  97. * u32le number of samples to skip from end of this packet
  98. * u8 reason for start skip
  99. * u8 reason for end skip (0=padding silence, 1=convergence)
  100. * @endcode
  101. */
  102. AV_FRAME_DATA_SKIP_SAMPLES,
  103. /**
  104. * This side data must be associated with an audio frame and corresponds to
  105. * enum AVAudioServiceType defined in avcodec.h.
  106. */
  107. AV_FRAME_DATA_AUDIO_SERVICE_TYPE,
  108. /**
  109. * Mastering display metadata associated with a video frame. The payload is
  110. * an AVMasteringDisplayMetadata type and contains information about the
  111. * mastering display color volume.
  112. */
  113. AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
  114. /**
  115. * The GOP timecode in 25 bit timecode format. Data format is 64-bit integer.
  116. * This is set on the first frame of a GOP that has a temporal reference of 0.
  117. */
  118. AV_FRAME_DATA_GOP_TIMECODE,
  119. /**
  120. * The data represents the AVSphericalMapping structure defined in
  121. * libavutil/spherical.h.
  122. */
  123. AV_FRAME_DATA_SPHERICAL,
  124. /**
  125. * Content light level (based on CTA-861.3). This payload contains data in
  126. * the form of the AVContentLightMetadata struct.
  127. */
  128. AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
  129. /**
  130. * The data contains an ICC profile as an opaque octet buffer following the
  131. * format described by ISO 15076-1 with an optional name defined in the
  132. * metadata key entry "name".
  133. */
  134. AV_FRAME_DATA_ICC_PROFILE,
  135. /**
  136. * Timecode which conforms to SMPTE ST 12-1. The data is an array of 4 uint32_t
  137. * where the first uint32_t describes how many (1-3) of the other timecodes are used.
  138. * The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
  139. * function in libavutil/timecode.h.
  140. */
  141. AV_FRAME_DATA_S12M_TIMECODE,
  142. /**
  143. * HDR dynamic metadata associated with a video frame. The payload is
  144. * an AVDynamicHDRPlus type and contains information for color
  145. * volume transform - application 4 of SMPTE 2094-40:2016 standard.
  146. */
  147. AV_FRAME_DATA_DYNAMIC_HDR_PLUS,
  148. /**
  149. * Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of
  150. * array element is implied by AVFrameSideData.size / AVRegionOfInterest.self_size.
  151. */
  152. AV_FRAME_DATA_REGIONS_OF_INTEREST,
  153. /**
  154. * Encoding parameters for a video frame, as described by AVVideoEncParams.
  155. */
  156. AV_FRAME_DATA_VIDEO_ENC_PARAMS,
  157. /**
  158. * User data unregistered metadata associated with a video frame.
  159. * This is the H.26[45] UDU SEI message, and shouldn't be used for any other purpose
  160. * The data is stored as uint8_t in AVFrameSideData.data which is 16 bytes of
  161. * uuid_iso_iec_11578 followed by AVFrameSideData.size - 16 bytes of user_data_payload_byte.
  162. */
  163. AV_FRAME_DATA_SEI_UNREGISTERED,
  164. /**
  165. * Film grain parameters for a frame, described by AVFilmGrainParams.
  166. * Must be present for every frame which should have film grain applied.
  167. */
  168. AV_FRAME_DATA_FILM_GRAIN_PARAMS,
  169. /**
  170. * Bounding boxes for object detection and classification,
  171. * as described by AVDetectionBBoxHeader.
  172. */
  173. AV_FRAME_DATA_DETECTION_BBOXES,
  174. /**
  175. * Dolby Vision RPU raw data, suitable for passing to x265
  176. * or other libraries. Array of uint8_t, with NAL emulation
  177. * bytes intact.
  178. */
  179. AV_FRAME_DATA_DOVI_RPU_BUFFER,
  180. /**
  181. * Parsed Dolby Vision metadata, suitable for passing to a software
  182. * implementation. The payload is the AVDOVIMetadata struct defined in
  183. * libavutil/dovi_meta.h.
  184. */
  185. AV_FRAME_DATA_DOVI_METADATA,
  186. /**
  187. * HDR Vivid dynamic metadata associated with a video frame. The payload is
  188. * an AVDynamicHDRVivid type and contains information for color
  189. * volume transform - CUVA 005.1-2021.
  190. */
  191. AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
  192. };
  193. enum AVActiveFormatDescription {
  194. AV_AFD_SAME = 8,
  195. AV_AFD_4_3 = 9,
  196. AV_AFD_16_9 = 10,
  197. AV_AFD_14_9 = 11,
  198. AV_AFD_4_3_SP_14_9 = 13,
  199. AV_AFD_16_9_SP_14_9 = 14,
  200. AV_AFD_SP_4_3 = 15,
  201. };
  202. /**
  203. * Structure to hold side data for an AVFrame.
  204. *
  205. * sizeof(AVFrameSideData) is not a part of the public ABI, so new fields may be added
  206. * to the end with a minor bump.
  207. */
  208. typedef struct AVFrameSideData {
  209. enum AVFrameSideDataType type;
  210. uint8_t *data;
  211. size_t size;
  212. AVDictionary *metadata;
  213. AVBufferRef *buf;
  214. } AVFrameSideData;
  215. /**
  216. * Structure describing a single Region Of Interest.
  217. *
  218. * When multiple regions are defined in a single side-data block, they
  219. * should be ordered from most to least important - some encoders are only
  220. * capable of supporting a limited number of distinct regions, so will have
  221. * to truncate the list.
  222. *
  223. * When overlapping regions are defined, the first region containing a given
  224. * area of the frame applies.
  225. */
  226. typedef struct AVRegionOfInterest {
  227. /**
  228. * Must be set to the size of this data structure (that is,
  229. * sizeof(AVRegionOfInterest)).
  230. */
  231. uint32_t self_size;
  232. /**
  233. * Distance in pixels from the top edge of the frame to the top and
  234. * bottom edges and from the left edge of the frame to the left and
  235. * right edges of the rectangle defining this region of interest.
  236. *
  237. * The constraints on a region are encoder dependent, so the region
  238. * actually affected may be slightly larger for alignment or other
  239. * reasons.
  240. */
  241. int top;
  242. int bottom;
  243. int left;
  244. int right;
  245. /**
  246. * Quantisation offset.
  247. *
  248. * Must be in the range -1 to +1. A value of zero indicates no quality
  249. * change. A negative value asks for better quality (less quantisation),
  250. * while a positive value asks for worse quality (greater quantisation).
  251. *
  252. * The range is calibrated so that the extreme values indicate the
  253. * largest possible offset - if the rest of the frame is encoded with the
  254. * worst possible quality, an offset of -1 indicates that this region
  255. * should be encoded with the best possible quality anyway. Intermediate
  256. * values are then interpolated in some codec-dependent way.
  257. *
  258. * For example, in 10-bit H.264 the quantisation parameter varies between
  259. * -12 and 51. A typical qoffset value of -1/10 therefore indicates that
  260. * this region should be encoded with a QP around one-tenth of the full
  261. * range better than the rest of the frame. So, if most of the frame
  262. * were to be encoded with a QP of around 30, this region would get a QP
  263. * of around 24 (an offset of approximately -1/10 * (51 - -12) = -6.3).
  264. * An extreme value of -1 would indicate that this region should be
  265. * encoded with the best possible quality regardless of the treatment of
  266. * the rest of the frame - that is, should be encoded at a QP of -12.
  267. */
  268. AVRational qoffset;
  269. } AVRegionOfInterest;
  270. /**
  271. * 此结构描述解码(原始)音频或视频数据。
  272. *
  273. * AVFrame必须使用av_frame_alloc()分配。
  274. * 注意,这只分配AVFrame本身,数据的缓冲区必须通过其他方式进行管理(见下文)。
  275. * 必须使用av_frame_free()释放AVFrame。
  276. *
  277. * AVFrame通常分配一次,然后多次重复使用,以保存不同的数据(例如,单个AVFrame用于保存从解码器接收的帧)。
  278. * 在这种情况下,av_frame_unref()将释放帧持有的所有引用,并将其重置为原始干净状态,然后再重新使用。
  279. *
  280. * AVFrame描述的数据通常通过AVBuffer API进行引用计数。
  281. * 底层缓冲区引用存储在AVFrame中。
  282. * buf / AVFrame.extended_buf。
  283. * 如果至少设置了一个引用,即如果AVFrame,则认为该AVFrame已被引用计数。
  284. * buf[0]! = NULL。在这种情况下,每个数据平面都必须包含在AVFrame中的一个缓冲区中。
  285. * 缓冲区或AVFrame.extended_buf。
  286. * 所有数据可能有一个缓冲区,或者每个平面有一个单独的缓冲区,或两者之间的任何缓冲区。
  287. *
  288. * sizeof(AVFrame) is not a part of the public ABI, so new fields may be added
  289. * to the end with a minor bump.
  290. *
  291. * Fields can be accessed through AVOptions, the name string used, matches the
  292. * C structure field name for fields accessible through AVOptions. The AVClass
  293. * for AVFrame can be obtained from avcodec_get_frame_class()
  294. */
  295. typedef struct AVFrame {
  296. #define AV_NUM_DATA_POINTERS 8
  297. /**
  298. * pointer to the picture/channel planes.
  299. * This might be different from the first allocated byte. For video,
  300. * it could even point to the end of the image data.
  301. *
  302. * All pointers in data and extended_data must point into one of the
  303. * AVBufferRef in buf or extended_buf.
  304. *
  305. * Some decoders access areas outside 0,0 - width,height, please
  306. * see avcodec_align_dimensions2(). Some filters and swscale can read
  307. * up to 16 bytes beyond the planes, if these filters are to be used,
  308. * then 16 extra bytes must be allocated.
  309. *
  310. * NOTE: Pointers not needed by the format MUST be set to NULL.
  311. *
  312. * @attention In case of video, the data[] pointers can point to the
  313. * end of image data in order to reverse line order, when used in
  314. * combination with negative values in the linesize[] array.
  315. */
  316. uint8_t *data[AV_NUM_DATA_POINTERS];
  317. /**
  318. * For video, a positive or negative value, which is typically indicating
  319. * the size in bytes of each picture line, but it can also be:
  320. * - the negative byte size of lines for vertical flipping
  321. * (with data[n] pointing to the end of the data
  322. * - a positive or negative multiple of the byte size as for accessing
  323. * even and odd fields of a frame (possibly flipped)
  324. *
  325. * For audio, only linesize[0] may be set. For planar audio, each channel
  326. * plane must be the same size.
  327. *
  328. * For video the linesizes should be multiples of the CPUs alignment
  329. * preference, this is 16 or 32 for modern desktop CPUs.
  330. * Some code requires such alignment other code can be slower without
  331. * correct alignment, for yet other it makes no difference.
  332. *
  333. * @note The linesize may be larger than the size of usable data -- there
  334. * may be extra padding present for performance reasons.
  335. *
  336. * @attention In case of video, line size values can be negative to achieve
  337. * a vertically inverted iteration over image lines.
  338. */
  339. int linesize[AV_NUM_DATA_POINTERS];
  340. /**
  341. * pointers to the data planes/channels.
  342. *
  343. * For video, this should simply point to data[].
  344. *
  345. * For planar audio, each channel has a separate data pointer, and
  346. * linesize[0] contains the size of each channel buffer.
  347. * For packed audio, there is just one data pointer, and linesize[0]
  348. * contains the total size of the buffer for all channels.
  349. *
  350. * Note: Both data and extended_data should always be set in a valid frame,
  351. * but for planar audio with more channels that can fit in data,
  352. * extended_data must be used in order to access all channels.
  353. */
  354. uint8_t **extended_data;
  355. /**
  356. * @name Video dimensions
  357. * Video frames only. The coded dimensions (in pixels) of the video frame,
  358. * i.e. the size of the rectangle that contains some well-defined values.
  359. *
  360. * @note The part of the frame intended for display/presentation is further
  361. * restricted by the @ref cropping "Cropping rectangle".
  362. * @{
  363. */
  364. int width, height;
  365. /**
  366. * @}
  367. */
  368. /**
  369. * number of audio samples (per channel) described by this frame
  370. */
  371. int nb_samples;
  372. /**
  373. * format of the frame, -1 if unknown or unset
  374. * Values correspond to enum AVPixelFormat for video frames,
  375. * enum AVSampleFormat for audio)
  376. */
  377. int format;
  378. /**
  379. * 1 -> keyframe, 0-> not
  380. */
  381. int key_frame;
  382. /**
  383. * 框架的图片类型。
  384. */
  385. enum AVPictureType pict_type;
  386. /**
  387. * 视频帧的采样纵横比,如果未知/未指定,则为0/1。
  388. */
  389. AVRational sample_aspect_ratio;
  390. /**
  391. * 以time_base单元表示的时间戳(帧应该显示给用户的时间)。
  392. */
  393. int64_t pts;
  394. /**
  395. * 从触发返回此帧的AVPacket中复制DTS。(如果不使用帧线程)
  396. * 这也是该AVFrame的呈现时间,仅从AVPacket计算。没有PTS值的DTS值。
  397. */
  398. int64_t pkt_dts;
  399. /**
  400. * 此帧中时间戳的时间基数。
  401. * 将来,这个字段可能在解码器或过滤器输出的帧上设置,但在默认情况下,它的值将在编码器或过滤器的输入上被忽略。
  402. */
  403. AVRational time_base;
  404. /**
  405. * picture number in bitstream order
  406. */
  407. int coded_picture_number;
  408. /**
  409. * picture number in display order
  410. */
  411. int display_picture_number;
  412. /**
  413. * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
  414. */
  415. int quality;
  416. /**
  417. * for some private data of the user
  418. */
  419. void *opaque;
  420. /**
  421. * When decoding, this signals how much the picture must be delayed.
  422. * extra_delay = repeat_pict / (2*fps)
  423. */
  424. int repeat_pict;
  425. /**
  426. * The content of the picture is interlaced.
  427. */
  428. int interlaced_frame;
  429. /**
  430. * If the content is interlaced, is top field displayed first.
  431. */
  432. int top_field_first;
  433. /**
  434. * Tell user application that palette has changed from previous frame.
  435. */
  436. int palette_has_changed;
  437. /**
  438. * reordered opaque 64 bits (generally an integer or a double precision float
  439. * PTS but can be anything).
  440. * The user sets AVCodecContext.reordered_opaque to represent the input at
  441. * that time,
  442. * the decoder reorders values as needed and sets AVFrame.reordered_opaque
  443. * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
  444. */
  445. int64_t reordered_opaque;
  446. /**
  447. * Sample rate of the audio data.
  448. */
  449. int sample_rate;
  450. #if FF_API_OLD_CHANNEL_LAYOUT
  451. /**
  452. * Channel layout of the audio data.
  453. * @deprecated use ch_layout instead
  454. */
  455. attribute_deprecated
  456. uint64_t channel_layout;
  457. #endif
  458. /**
  459. * AVBuffer references backing the data for this frame. All the pointers in
  460. * data and extended_data must point inside one of the buffers in buf or
  461. * extended_buf. This array must be filled contiguously -- if buf[i] is
  462. * non-NULL then buf[j] must also be non-NULL for all j < i.
  463. *
  464. * There may be at most one AVBuffer per data plane, so for video this array
  465. * always contains all the references. For planar audio with more than
  466. * AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in
  467. * this array. Then the extra AVBufferRef pointers are stored in the
  468. * extended_buf array.
  469. */
  470. AVBufferRef *buf[AV_NUM_DATA_POINTERS];
  471. /**
  472. * For planar audio which requires more than AV_NUM_DATA_POINTERS
  473. * AVBufferRef pointers, this array will hold all the references which
  474. * cannot fit into AVFrame.buf.
  475. *
  476. * Note that this is different from AVFrame.extended_data, which always
  477. * contains all the pointers. This array only contains the extra pointers,
  478. * which cannot fit into AVFrame.buf.
  479. *
  480. * This array is always allocated using av_malloc() by whoever constructs
  481. * the frame. It is freed in av_frame_unref().
  482. */
  483. AVBufferRef **extended_buf;
  484. /**
  485. * Number of elements in extended_buf.
  486. */
  487. int nb_extended_buf;
  488. AVFrameSideData **side_data;
  489. int nb_side_data;
  490. /**
  491. * @defgroup lavu_frame_flags AV_FRAME_FLAGS
  492. * @ingroup lavu_frame
  493. * Flags describing additional frame properties.
  494. *
  495. * @{
  496. */
  497. /**
  498. * The frame data may be corrupted, e.g. due to decoding errors.
  499. */
  500. #define AV_FRAME_FLAG_CORRUPT (1 << 0)
  501. /**
  502. * A flag to mark the frames which need to be decoded, but shouldn't be output.
  503. */
  504. #define AV_FRAME_FLAG_DISCARD (1 << 2)
  505. /**
  506. * @}
  507. */
  508. /**
  509. * Frame flags, a combination of @ref lavu_frame_flags
  510. */
  511. int flags;
  512. /**
  513. * MPEG vs JPEG YUV range.
  514. * - encoding: Set by user
  515. * - decoding: Set by libavcodec
  516. */
  517. enum AVColorRange color_range;
  518. enum AVColorPrimaries color_primaries;
  519. enum AVColorTransferCharacteristic color_trc;
  520. /**
  521. * YUV colorspace type.
  522. * - encoding: Set by user
  523. * - decoding: Set by libavcodec
  524. */
  525. enum AVColorSpace colorspace;
  526. enum AVChromaLocation chroma_location;
  527. /**
  528. * frame timestamp estimated using various heuristics, in stream time base
  529. * - encoding: unused
  530. * - decoding: set by libavcodec, read by user.
  531. */
  532. int64_t best_effort_timestamp;
  533. /**
  534. * 从已输入到解码器的最后一个AVPacket中重新排序的pos
  535. * - encoding: unused
  536. * - decoding: Read by user.
  537. */
  538. int64_t pkt_pos;
  539. /**
  540. * 相应数据包的持续时间,以AVStream->time_base单位表示,如果未知,则为0。
  541. * - encoding: unused
  542. * - decoding: Read by user.
  543. */
  544. int64_t pkt_duration;
  545. /**
  546. * metadata.
  547. * - encoding: Set by user.
  548. * - decoding: Set by libavcodec.
  549. */
  550. AVDictionary *metadata;
  551. /**
  552. * decode error flags of the frame, set to a combination of
  553. * FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there
  554. * were errors during the decoding.
  555. * - encoding: unused
  556. * - decoding: set by libavcodec, read by user.
  557. */
  558. int decode_error_flags;
  559. #define FF_DECODE_ERROR_INVALID_BITSTREAM 1
  560. #define FF_DECODE_ERROR_MISSING_REFERENCE 2
  561. #define FF_DECODE_ERROR_CONCEALMENT_ACTIVE 4
  562. #define FF_DECODE_ERROR_DECODE_SLICES 8
  563. #if FF_API_OLD_CHANNEL_LAYOUT
  564. /**
  565. * number of audio channels, only used for audio.
  566. * - encoding: unused
  567. * - decoding: Read by user.
  568. * @deprecated use ch_layout instead
  569. */
  570. attribute_deprecated
  571. int channels;
  572. #endif
  573. /**
  574. * 包含压缩帧的相应数据包的大小。
  575. * 如果未知,则将其设置为负值。
  576. * - encoding: unused
  577. * - decoding: set by libavcodec, read by user.
  578. */
  579. int pkt_size;
  580. /**
  581. * For hwaccel-format frames, this should be a reference to the
  582. * AVHWFramesContext describing the frame.
  583. */
  584. AVBufferRef *hw_frames_ctx;
  585. /**
  586. * AVBufferRef for free use by the API user. FFmpeg will never check the
  587. * contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when
  588. * the frame is unreferenced. av_frame_copy_props() calls create a new
  589. * reference with av_buffer_ref() for the target frame's opaque_ref field.
  590. *
  591. * This is unrelated to the opaque field, although it serves a similar
  592. * purpose.
  593. */
  594. AVBufferRef *opaque_ref;
  595. /**
  596. * @anchor cropping
  597. * @name Cropping
  598. * Video frames only. The number of pixels to discard from the the
  599. * top/bottom/left/right border of the frame to obtain the sub-rectangle of
  600. * the frame intended for presentation.
  601. * @{
  602. */
  603. size_t crop_top;
  604. size_t crop_bottom;
  605. size_t crop_left;
  606. size_t crop_right;
  607. /**
  608. * @}
  609. */
  610. /**
  611. * AVBufferRef for internal use by a single libav* library.
  612. * Must not be used to transfer data between libraries.
  613. * Has to be NULL when ownership of the frame leaves the respective library.
  614. *
  615. * Code outside the FFmpeg libs should never check or change the contents of the buffer ref.
  616. *
  617. * FFmpeg calls av_buffer_unref() on it when the frame is unreferenced.
  618. * av_frame_copy_props() calls create a new reference with av_buffer_ref()
  619. * for the target frame's private_ref field.
  620. */
  621. AVBufferRef *private_ref;
  622. /**
  623. * Channel layout of the audio data.
  624. */
  625. AVChannelLayout ch_layout;
  626. } AVFrame;
  627. #if FF_API_COLORSPACE_NAME
  628. /**
  629. * Get the name of a colorspace.
  630. * @return a static string identifying the colorspace; can be NULL.
  631. * @deprecated use av_color_space_name()
  632. */
  633. attribute_deprecated
  634. const char *av_get_colorspace_name(enum AVColorSpace val);
  635. #endif
  636. /**
  637. * 分配AVFrame并将其字段设置为默认值。必须使用av_frame_free()释放生成的结构。
  638. *
  639. * @return AVFrame填充了默认值或失败时为NULL。
  640. *
  641. * @note 这只分配AVFrame本身,而不是数据缓冲区。
  642. * 这些必须通过其他方式分配,例如使用av_frame_get_buffer()或手动分配。
  643. */
  644. AVFrame *av_frame_alloc(void);
  645. /**
  646. * 释放帧和其中任何动态分配的对象,
  647. * e.g.扩展数据。如果帧是引用计数的,则首先将取消引用。
  648. * @param 要释放的帧帧。指针将设置为NULL。
  649. */
  650. void av_frame_free(AVFrame **frame);
  651. /**
  652. * Set up a new reference to the data described by the source frame.
  653. *
  654. * Copy frame properties from src to dst and create a new reference for each
  655. * AVBufferRef from src.
  656. *
  657. * If src is not reference counted, new buffers are allocated and the data is
  658. * copied.
  659. *
  660. * @warning: dst MUST have been either unreferenced with av_frame_unref(dst),
  661. * or newly allocated with av_frame_alloc() before calling this
  662. * function, or undefined behavior will occur.
  663. *
  664. * @return 0 on success, a negative AVERROR on error
  665. */
  666. int av_frame_ref(AVFrame *dst, const AVFrame *src);
  667. /**
  668. * Create a new frame that references the same data as src.
  669. *
  670. * This is a shortcut for av_frame_alloc()+av_frame_ref().
  671. *
  672. * @return newly created AVFrame on success, NULL on error.
  673. */
  674. AVFrame *av_frame_clone(const AVFrame *src);
  675. /**
  676. * 取消引用帧引用的所有缓冲区并重置帧字段。
  677. */
  678. void av_frame_unref(AVFrame *frame);
  679. /**
  680. * Move everything contained in src to dst and reset src.
  681. *
  682. * @warning: dst is not unreferenced, but directly overwritten without reading
  683. * or deallocating its contents. Call av_frame_unref(dst) manually
  684. * before calling this function to ensure that no memory is leaked.
  685. */
  686. void av_frame_move_ref(AVFrame *dst, AVFrame *src);
  687. /**
  688. * Allocate new buffer(s) for audio or video data.
  689. *
  690. * The following fields must be set on frame before calling this function:
  691. * - format (pixel format for video, sample format for audio)
  692. * - width and height for video
  693. * - nb_samples and ch_layout for audio
  694. *
  695. * This function will fill AVFrame.data and AVFrame.buf arrays and, if
  696. * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
  697. * For planar formats, one buffer will be allocated for each plane.
  698. *
  699. * @warning: if frame already has been allocated, calling this function will
  700. * leak memory. In addition, undefined behavior can occur in certain
  701. * cases.
  702. *
  703. * @param frame frame in which to store the new buffers.
  704. * @param align Required buffer size alignment. If equal to 0, alignment will be
  705. * chosen automatically for the current CPU. It is highly
  706. * recommended to pass 0 here unless you know what you are doing.
  707. *
  708. * @return 0 on success, a negative AVERROR on error.
  709. */
  710. int av_frame_get_buffer(AVFrame *frame, int align);
  711. /**
  712. * Check if the frame data is writable.
  713. *
  714. * @return A positive value if the frame data is writable (which is true if and
  715. * only if each of the underlying buffers has only one reference, namely the one
  716. * stored in this frame). Return 0 otherwise.
  717. *
  718. * If 1 is returned the answer is valid until av_buffer_ref() is called on any
  719. * of the underlying AVBufferRefs (e.g. through av_frame_ref() or directly).
  720. *
  721. * @see av_frame_make_writable(), av_buffer_is_writable()
  722. */
  723. int av_frame_is_writable(AVFrame *frame);
  724. /**
  725. * Ensure that the frame data is writable, avoiding data copy if possible.
  726. *
  727. * Do nothing if the frame is writable, allocate new buffers and copy the data
  728. * if it is not.
  729. *
  730. * @return 0 on success, a negative AVERROR on error.
  731. *
  732. * @see av_frame_is_writable(), av_buffer_is_writable(),
  733. * av_buffer_make_writable()
  734. */
  735. int av_frame_make_writable(AVFrame *frame);
  736. /**
  737. * Copy the frame data from src to dst.
  738. *
  739. * This function does not allocate anything, dst must be already initialized and
  740. * allocated with the same parameters as src.
  741. *
  742. * This function only copies the frame data (i.e. the contents of the data /
  743. * extended data arrays), not any other properties.
  744. *
  745. * @return >= 0 on success, a negative AVERROR on error.
  746. */
  747. int av_frame_copy(AVFrame *dst, const AVFrame *src);
  748. /**
  749. * 仅将“metadata”字段从src复制到dst。
  750. *
  751. * 用于此函数的元数据是那些不影响缓冲区中的数据布局的字段。
  752. * 例如,pts,采样率(音频)或采样长宽比(视频),但不是宽度/高度或频道布局。
  753. * 侧数据也会被复制。
  754. */
  755. int av_frame_copy_props(AVFrame *dst, const AVFrame *src);
  756. /**
  757. * Get the buffer reference a given data plane is stored in.
  758. *
  759. * @param plane index of the data plane of interest in frame->extended_data.
  760. *
  761. * @return the buffer reference that contains the plane or NULL if the input
  762. * frame is not valid.
  763. */
  764. AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane);
  765. /**
  766. * Add a new side data to a frame.
  767. *
  768. * @param frame a frame to which the side data should be added
  769. * @param type type of the added side data
  770. * @param size size of the side data
  771. *
  772. * @return newly added side data on success, NULL on error
  773. */
  774. AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
  775. enum AVFrameSideDataType type,
  776. size_t size);
  777. /**
  778. * Add a new side data to a frame from an existing AVBufferRef
  779. *
  780. * @param frame a frame to which the side data should be added
  781. * @param type the type of the added side data
  782. * @param buf an AVBufferRef to add as side data. The ownership of
  783. * the reference is transferred to the frame.
  784. *
  785. * @return newly added side data on success, NULL on error. On failure
  786. * the frame is unchanged and the AVBufferRef remains owned by
  787. * the caller.
  788. */
  789. AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
  790. enum AVFrameSideDataType type,
  791. AVBufferRef *buf);
  792. /**
  793. * @return a pointer to the side data of a given type on success, NULL if there
  794. * is no side data with such type in this frame.
  795. */
  796. AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
  797. enum AVFrameSideDataType type);
  798. /**
  799. * Remove and free all side data instances of the given type.
  800. */
  801. void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
  802. /**
  803. * Flags for frame cropping.
  804. */
  805. enum {
  806. /**
  807. * Apply the maximum possible cropping, even if it requires setting the
  808. * AVFrame.data[] entries to unaligned pointers. Passing unaligned data
  809. * to FFmpeg API is generally not allowed, and causes undefined behavior
  810. * (such as crashes). You can pass unaligned data only to FFmpeg APIs that
  811. * are explicitly documented to accept it. Use this flag only if you
  812. * absolutely know what you are doing.
  813. */
  814. AV_FRAME_CROP_UNALIGNED = 1 << 0,
  815. };
  816. /**
  817. * Crop the given video AVFrame according to its crop_left/crop_top/crop_right/
  818. * crop_bottom fields. If cropping is successful, the function will adjust the
  819. * data pointers and the width/height fields, and set the crop fields to 0.
  820. *
  821. * In all cases, the cropping boundaries will be rounded to the inherent
  822. * alignment of the pixel format. In some cases, such as for opaque hwaccel
  823. * formats, the left/top cropping is ignored. The crop fields are set to 0 even
  824. * if the cropping was rounded or ignored.
  825. *
  826. * @param frame the frame which should be cropped
  827. * @param flags Some combination of AV_FRAME_CROP_* flags, or 0.
  828. *
  829. * @return >= 0 on success, a negative AVERROR on error. If the cropping fields
  830. * were invalid, AVERROR(ERANGE) is returned, and nothing is changed.
  831. */
  832. int av_frame_apply_cropping(AVFrame *frame, int flags);
  833. /**
  834. * @return a string identifying the side data type
  835. */
  836. const char *av_frame_side_data_name(enum AVFrameSideDataType type);
  837. /**
  838. * @}
  839. */
  840. #endif /* AVUTIL_FRAME_H */