Path: blob/master/dep/ffmpeg/include/libavutil/frame.h
4216 views
/*1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718/**19* @file20* @ingroup lavu_frame21* reference-counted frame API22*/2324#ifndef AVUTIL_FRAME_H25#define AVUTIL_FRAME_H2627#include <stddef.h>28#include <stdint.h>2930#include "avutil.h"31#include "buffer.h"32#include "channel_layout.h"33#include "dict.h"34#include "rational.h"35#include "samplefmt.h"36#include "pixfmt.h"37#include "version.h"383940/**41* @defgroup lavu_frame AVFrame42* @ingroup lavu_data43*44* @{45* AVFrame is an abstraction for reference-counted raw multimedia data.46*/4748enum AVFrameSideDataType {49/**50* The data is the AVPanScan struct defined in libavcodec.51*/52AV_FRAME_DATA_PANSCAN,53/**54* ATSC A53 Part 4 Closed Captions.55* A53 CC bitstream is stored as uint8_t in AVFrameSideData.data.56* The number of bytes of CC data is AVFrameSideData.size.57*/58AV_FRAME_DATA_A53_CC,59/**60* Stereoscopic 3d metadata.61* The data is the AVStereo3D struct defined in libavutil/stereo3d.h.62*/63AV_FRAME_DATA_STEREO3D,64/**65* The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.66*/67AV_FRAME_DATA_MATRIXENCODING,68/**69* Metadata relevant to a downmix procedure.70* The data is the AVDownmixInfo struct defined in libavutil/downmix_info.h.71*/72AV_FRAME_DATA_DOWNMIX_INFO,73/**74* ReplayGain information in the form of the AVReplayGain struct.75*/76AV_FRAME_DATA_REPLAYGAIN,77/**78* This side data contains a 3x3 transformation matrix describing an affine79* transformation that needs to be applied to the frame for correct80* presentation.81*82* See libavutil/display.h for a detailed description of the data.83*/84AV_FRAME_DATA_DISPLAYMATRIX,85/**86* Active Format Description data consisting of a single byte as specified87* in ETSI TS 101 154 using AVActiveFormatDescription enum.88*/89AV_FRAME_DATA_AFD,90/**91* Motion vectors exported by some codecs (on demand through the export_mvs92* flag set in the libavcodec AVCodecContext flags2 option).93* The data is the AVMotionVector struct defined in94* libavutil/motion_vector.h.95*/96AV_FRAME_DATA_MOTION_VECTORS,97/**98* Recommmends skipping the specified number of samples. This is exported99* only if the "skip_manual" AVOption is set in libavcodec.100* This has the same format as AV_PKT_DATA_SKIP_SAMPLES.101* @code102* u32le number of samples to skip from start of this packet103* u32le number of samples to skip from end of this packet104* u8 reason for start skip105* u8 reason for end skip (0=padding silence, 1=convergence)106* @endcode107*/108AV_FRAME_DATA_SKIP_SAMPLES,109/**110* This side data must be associated with an audio frame and corresponds to111* enum AVAudioServiceType defined in avcodec.h.112*/113AV_FRAME_DATA_AUDIO_SERVICE_TYPE,114/**115* Mastering display metadata associated with a video frame. The payload is116* an AVMasteringDisplayMetadata type and contains information about the117* mastering display color volume.118*/119AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,120/**121* The GOP timecode in 25 bit timecode format. Data format is 64-bit integer.122* This is set on the first frame of a GOP that has a temporal reference of 0.123*/124AV_FRAME_DATA_GOP_TIMECODE,125126/**127* The data represents the AVSphericalMapping structure defined in128* libavutil/spherical.h.129*/130AV_FRAME_DATA_SPHERICAL,131132/**133* Content light level (based on CTA-861.3). This payload contains data in134* the form of the AVContentLightMetadata struct.135*/136AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,137138/**139* The data contains an ICC profile as an opaque octet buffer following the140* format described by ISO 15076-1 with an optional name defined in the141* metadata key entry "name".142*/143AV_FRAME_DATA_ICC_PROFILE,144145/**146* Timecode which conforms to SMPTE ST 12-1. The data is an array of 4 uint32_t147* where the first uint32_t describes how many (1-3) of the other timecodes are used.148* The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()149* function in libavutil/timecode.h.150*/151AV_FRAME_DATA_S12M_TIMECODE,152153/**154* HDR dynamic metadata associated with a video frame. The payload is155* an AVDynamicHDRPlus type and contains information for color156* volume transform - application 4 of SMPTE 2094-40:2016 standard.157*/158AV_FRAME_DATA_DYNAMIC_HDR_PLUS,159160/**161* Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of162* array element is implied by AVFrameSideData.size / AVRegionOfInterest.self_size.163*/164AV_FRAME_DATA_REGIONS_OF_INTEREST,165166/**167* Encoding parameters for a video frame, as described by AVVideoEncParams.168*/169AV_FRAME_DATA_VIDEO_ENC_PARAMS,170171/**172* User data unregistered metadata associated with a video frame.173* This is the H.26[45] UDU SEI message, and shouldn't be used for any other purpose174* The data is stored as uint8_t in AVFrameSideData.data which is 16 bytes of175* uuid_iso_iec_11578 followed by AVFrameSideData.size - 16 bytes of user_data_payload_byte.176*/177AV_FRAME_DATA_SEI_UNREGISTERED,178179/**180* Film grain parameters for a frame, described by AVFilmGrainParams.181* Must be present for every frame which should have film grain applied.182*183* May be present multiple times, for example when there are multiple184* alternative parameter sets for different video signal characteristics.185* The user should select the most appropriate set for the application.186*/187AV_FRAME_DATA_FILM_GRAIN_PARAMS,188189/**190* Bounding boxes for object detection and classification,191* as described by AVDetectionBBoxHeader.192*/193AV_FRAME_DATA_DETECTION_BBOXES,194195/**196* Dolby Vision RPU raw data, suitable for passing to x265197* or other libraries. Array of uint8_t, with NAL emulation198* bytes intact.199*/200AV_FRAME_DATA_DOVI_RPU_BUFFER,201202/**203* Parsed Dolby Vision metadata, suitable for passing to a software204* implementation. The payload is the AVDOVIMetadata struct defined in205* libavutil/dovi_meta.h.206*/207AV_FRAME_DATA_DOVI_METADATA,208209/**210* HDR Vivid dynamic metadata associated with a video frame. The payload is211* an AVDynamicHDRVivid type and contains information for color212* volume transform - CUVA 005.1-2021.213*/214AV_FRAME_DATA_DYNAMIC_HDR_VIVID,215216/**217* Ambient viewing environment metadata, as defined by H.274.218*/219AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT,220221/**222* Provide encoder-specific hinting information about changed/unchanged223* portions of a frame. It can be used to pass information about which224* macroblocks can be skipped because they didn't change from the225* corresponding ones in the previous frame. This could be useful for226* applications which know this information in advance to speed up227* encoding.228*/229AV_FRAME_DATA_VIDEO_HINT,230231/**232* Raw LCEVC payload data, as a uint8_t array, with NAL emulation233* bytes intact.234*/235AV_FRAME_DATA_LCEVC,236237/**238* This side data must be associated with a video frame.239* The presence of this side data indicates that the video stream is240* composed of multiple views (e.g. stereoscopic 3D content,241* cf. H.264 Annex H or H.265 Annex G).242* The data is an int storing the view ID.243*/244AV_FRAME_DATA_VIEW_ID,245};246247enum AVActiveFormatDescription {248AV_AFD_SAME = 8,249AV_AFD_4_3 = 9,250AV_AFD_16_9 = 10,251AV_AFD_14_9 = 11,252AV_AFD_4_3_SP_14_9 = 13,253AV_AFD_16_9_SP_14_9 = 14,254AV_AFD_SP_4_3 = 15,255};256257258/**259* Structure to hold side data for an AVFrame.260*261* sizeof(AVFrameSideData) is not a part of the public ABI, so new fields may be added262* to the end with a minor bump.263*/264typedef struct AVFrameSideData {265enum AVFrameSideDataType type;266uint8_t *data;267size_t size;268AVDictionary *metadata;269AVBufferRef *buf;270} AVFrameSideData;271272enum AVSideDataProps {273/**274* The side data type can be used in stream-global structures.275* Side data types without this property are only meaningful on per-frame276* basis.277*/278AV_SIDE_DATA_PROP_GLOBAL = (1 << 0),279280/**281* Multiple instances of this side data type can be meaningfully present in282* a single side data array.283*/284AV_SIDE_DATA_PROP_MULTI = (1 << 1),285};286287/**288* This struct describes the properties of a side data type. Its instance289* corresponding to a given type can be obtained from av_frame_side_data_desc().290*/291typedef struct AVSideDataDescriptor {292/**293* Human-readable side data description.294*/295const char *name;296297/**298* Side data property flags, a combination of AVSideDataProps values.299*/300unsigned props;301} AVSideDataDescriptor;302303/**304* Structure describing a single Region Of Interest.305*306* When multiple regions are defined in a single side-data block, they307* should be ordered from most to least important - some encoders are only308* capable of supporting a limited number of distinct regions, so will have309* to truncate the list.310*311* When overlapping regions are defined, the first region containing a given312* area of the frame applies.313*/314typedef struct AVRegionOfInterest {315/**316* Must be set to the size of this data structure (that is,317* sizeof(AVRegionOfInterest)).318*/319uint32_t self_size;320/**321* Distance in pixels from the top edge of the frame to the top and322* bottom edges and from the left edge of the frame to the left and323* right edges of the rectangle defining this region of interest.324*325* The constraints on a region are encoder dependent, so the region326* actually affected may be slightly larger for alignment or other327* reasons.328*/329int top;330int bottom;331int left;332int right;333/**334* Quantisation offset.335*336* Must be in the range -1 to +1. A value of zero indicates no quality337* change. A negative value asks for better quality (less quantisation),338* while a positive value asks for worse quality (greater quantisation).339*340* The range is calibrated so that the extreme values indicate the341* largest possible offset - if the rest of the frame is encoded with the342* worst possible quality, an offset of -1 indicates that this region343* should be encoded with the best possible quality anyway. Intermediate344* values are then interpolated in some codec-dependent way.345*346* For example, in 10-bit H.264 the quantisation parameter varies between347* -12 and 51. A typical qoffset value of -1/10 therefore indicates that348* this region should be encoded with a QP around one-tenth of the full349* range better than the rest of the frame. So, if most of the frame350* were to be encoded with a QP of around 30, this region would get a QP351* of around 24 (an offset of approximately -1/10 * (51 - -12) = -6.3).352* An extreme value of -1 would indicate that this region should be353* encoded with the best possible quality regardless of the treatment of354* the rest of the frame - that is, should be encoded at a QP of -12.355*/356AVRational qoffset;357} AVRegionOfInterest;358359/**360* This structure describes decoded (raw) audio or video data.361*362* AVFrame must be allocated using av_frame_alloc(). Note that this only363* allocates the AVFrame itself, the buffers for the data must be managed364* through other means (see below).365* AVFrame must be freed with av_frame_free().366*367* AVFrame is typically allocated once and then reused multiple times to hold368* different data (e.g. a single AVFrame to hold frames received from a369* decoder). In such a case, av_frame_unref() will free any references held by370* the frame and reset it to its original clean state before it371* is reused again.372*373* The data described by an AVFrame is usually reference counted through the374* AVBuffer API. The underlying buffer references are stored in AVFrame.buf /375* AVFrame.extended_buf. An AVFrame is considered to be reference counted if at376* least one reference is set, i.e. if AVFrame.buf[0] != NULL. In such a case,377* every single data plane must be contained in one of the buffers in378* AVFrame.buf or AVFrame.extended_buf.379* There may be a single buffer for all the data, or one separate buffer for380* each plane, or anything in between.381*382* sizeof(AVFrame) is not a part of the public ABI, so new fields may be added383* to the end with a minor bump.384*385* Fields can be accessed through AVOptions, the name string used, matches the386* C structure field name for fields accessible through AVOptions.387*/388typedef struct AVFrame {389#define AV_NUM_DATA_POINTERS 8390/**391* pointer to the picture/channel planes.392* This might be different from the first allocated byte. For video,393* it could even point to the end of the image data.394*395* All pointers in data and extended_data must point into one of the396* AVBufferRef in buf or extended_buf.397*398* Some decoders access areas outside 0,0 - width,height, please399* see avcodec_align_dimensions2(). Some filters and swscale can read400* up to 16 bytes beyond the planes, if these filters are to be used,401* then 16 extra bytes must be allocated.402*403* NOTE: Pointers not needed by the format MUST be set to NULL.404*405* @attention In case of video, the data[] pointers can point to the406* end of image data in order to reverse line order, when used in407* combination with negative values in the linesize[] array.408*/409uint8_t *data[AV_NUM_DATA_POINTERS];410411/**412* For video, a positive or negative value, which is typically indicating413* the size in bytes of each picture line, but it can also be:414* - the negative byte size of lines for vertical flipping415* (with data[n] pointing to the end of the data416* - a positive or negative multiple of the byte size as for accessing417* even and odd fields of a frame (possibly flipped)418*419* For audio, only linesize[0] may be set. For planar audio, each channel420* plane must be the same size.421*422* For video the linesizes should be multiples of the CPUs alignment423* preference, this is 16 or 32 for modern desktop CPUs.424* Some code requires such alignment other code can be slower without425* correct alignment, for yet other it makes no difference.426*427* @note The linesize may be larger than the size of usable data -- there428* may be extra padding present for performance reasons.429*430* @attention In case of video, line size values can be negative to achieve431* a vertically inverted iteration over image lines.432*/433int linesize[AV_NUM_DATA_POINTERS];434435/**436* pointers to the data planes/channels.437*438* For video, this should simply point to data[].439*440* For planar audio, each channel has a separate data pointer, and441* linesize[0] contains the size of each channel buffer.442* For packed audio, there is just one data pointer, and linesize[0]443* contains the total size of the buffer for all channels.444*445* Note: Both data and extended_data should always be set in a valid frame,446* but for planar audio with more channels that can fit in data,447* extended_data must be used in order to access all channels.448*/449uint8_t **extended_data;450451/**452* @name Video dimensions453* Video frames only. The coded dimensions (in pixels) of the video frame,454* i.e. the size of the rectangle that contains some well-defined values.455*456* @note The part of the frame intended for display/presentation is further457* restricted by the @ref cropping "Cropping rectangle".458* @{459*/460int width, height;461/**462* @}463*/464465/**466* number of audio samples (per channel) described by this frame467*/468int nb_samples;469470/**471* format of the frame, -1 if unknown or unset472* Values correspond to enum AVPixelFormat for video frames,473* enum AVSampleFormat for audio)474*/475int format;476477#if FF_API_FRAME_KEY478/**479* 1 -> keyframe, 0-> not480*481* @deprecated Use AV_FRAME_FLAG_KEY instead482*/483attribute_deprecated484int key_frame;485#endif486487/**488* Picture type of the frame.489*/490enum AVPictureType pict_type;491492/**493* Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.494*/495AVRational sample_aspect_ratio;496497/**498* Presentation timestamp in time_base units (time when frame should be shown to user).499*/500int64_t pts;501502/**503* DTS copied from the AVPacket that triggered returning this frame. (if frame threading isn't used)504* This is also the Presentation time of this AVFrame calculated from505* only AVPacket.dts values without pts values.506*/507int64_t pkt_dts;508509/**510* Time base for the timestamps in this frame.511* In the future, this field may be set on frames output by decoders or512* filters, but its value will be by default ignored on input to encoders513* or filters.514*/515AVRational time_base;516517/**518* quality (between 1 (good) and FF_LAMBDA_MAX (bad))519*/520int quality;521522/**523* Frame owner's private data.524*525* This field may be set by the code that allocates/owns the frame data.526* It is then not touched by any library functions, except:527* - it is copied to other references by av_frame_copy_props() (and hence by528* av_frame_ref());529* - it is set to NULL when the frame is cleared by av_frame_unref()530* - on the caller's explicit request. E.g. libavcodec encoders/decoders531* will copy this field to/from @ref AVPacket "AVPackets" if the caller sets532* @ref AV_CODEC_FLAG_COPY_OPAQUE.533*534* @see opaque_ref the reference-counted analogue535*/536void *opaque;537538/**539* Number of fields in this frame which should be repeated, i.e. the total540* duration of this frame should be repeat_pict + 2 normal field durations.541*542* For interlaced frames this field may be set to 1, which signals that this543* frame should be presented as 3 fields: beginning with the first field (as544* determined by AV_FRAME_FLAG_TOP_FIELD_FIRST being set or not), followed545* by the second field, and then the first field again.546*547* For progressive frames this field may be set to a multiple of 2, which548* signals that this frame's duration should be (repeat_pict + 2) / 2549* normal frame durations.550*551* @note This field is computed from MPEG2 repeat_first_field flag and its552* associated flags, H.264 pic_struct from picture timing SEI, and553* their analogues in other codecs. Typically it should only be used when554* higher-layer timing information is not available.555*/556int repeat_pict;557558#if FF_API_INTERLACED_FRAME559/**560* The content of the picture is interlaced.561*562* @deprecated Use AV_FRAME_FLAG_INTERLACED instead563*/564attribute_deprecated565int interlaced_frame;566567/**568* If the content is interlaced, is top field displayed first.569*570* @deprecated Use AV_FRAME_FLAG_TOP_FIELD_FIRST instead571*/572attribute_deprecated573int top_field_first;574#endif575576#if FF_API_PALETTE_HAS_CHANGED577/**578* Tell user application that palette has changed from previous frame.579*/580attribute_deprecated581int palette_has_changed;582#endif583584/**585* Sample rate of the audio data.586*/587int sample_rate;588589/**590* AVBuffer references backing the data for this frame. All the pointers in591* data and extended_data must point inside one of the buffers in buf or592* extended_buf. This array must be filled contiguously -- if buf[i] is593* non-NULL then buf[j] must also be non-NULL for all j < i.594*595* There may be at most one AVBuffer per data plane, so for video this array596* always contains all the references. For planar audio with more than597* AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in598* this array. Then the extra AVBufferRef pointers are stored in the599* extended_buf array.600*/601AVBufferRef *buf[AV_NUM_DATA_POINTERS];602603/**604* For planar audio which requires more than AV_NUM_DATA_POINTERS605* AVBufferRef pointers, this array will hold all the references which606* cannot fit into AVFrame.buf.607*608* Note that this is different from AVFrame.extended_data, which always609* contains all the pointers. This array only contains the extra pointers,610* which cannot fit into AVFrame.buf.611*612* This array is always allocated using av_malloc() by whoever constructs613* the frame. It is freed in av_frame_unref().614*/615AVBufferRef **extended_buf;616/**617* Number of elements in extended_buf.618*/619int nb_extended_buf;620621AVFrameSideData **side_data;622int nb_side_data;623624/**625* @defgroup lavu_frame_flags AV_FRAME_FLAGS626* @ingroup lavu_frame627* Flags describing additional frame properties.628*629* @{630*/631632/**633* The frame data may be corrupted, e.g. due to decoding errors.634*/635#define AV_FRAME_FLAG_CORRUPT (1 << 0)636/**637* A flag to mark frames that are keyframes.638*/639#define AV_FRAME_FLAG_KEY (1 << 1)640/**641* A flag to mark the frames which need to be decoded, but shouldn't be output.642*/643#define AV_FRAME_FLAG_DISCARD (1 << 2)644/**645* A flag to mark frames whose content is interlaced.646*/647#define AV_FRAME_FLAG_INTERLACED (1 << 3)648/**649* A flag to mark frames where the top field is displayed first if the content650* is interlaced.651*/652#define AV_FRAME_FLAG_TOP_FIELD_FIRST (1 << 4)653/**654* @}655*/656657/**658* Frame flags, a combination of @ref lavu_frame_flags659*/660int flags;661662/**663* MPEG vs JPEG YUV range.664* - encoding: Set by user665* - decoding: Set by libavcodec666*/667enum AVColorRange color_range;668669enum AVColorPrimaries color_primaries;670671enum AVColorTransferCharacteristic color_trc;672673/**674* YUV colorspace type.675* - encoding: Set by user676* - decoding: Set by libavcodec677*/678enum AVColorSpace colorspace;679680enum AVChromaLocation chroma_location;681682/**683* frame timestamp estimated using various heuristics, in stream time base684* - encoding: unused685* - decoding: set by libavcodec, read by user.686*/687int64_t best_effort_timestamp;688689#if FF_API_FRAME_PKT690/**691* reordered pos from the last AVPacket that has been input into the decoder692* - encoding: unused693* - decoding: Read by user.694* @deprecated use AV_CODEC_FLAG_COPY_OPAQUE to pass through arbitrary user695* data from packets to frames696*/697attribute_deprecated698int64_t pkt_pos;699#endif700701/**702* metadata.703* - encoding: Set by user.704* - decoding: Set by libavcodec.705*/706AVDictionary *metadata;707708/**709* decode error flags of the frame, set to a combination of710* FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there711* were errors during the decoding.712* - encoding: unused713* - decoding: set by libavcodec, read by user.714*/715int decode_error_flags;716#define FF_DECODE_ERROR_INVALID_BITSTREAM 1717#define FF_DECODE_ERROR_MISSING_REFERENCE 2718#define FF_DECODE_ERROR_CONCEALMENT_ACTIVE 4719#define FF_DECODE_ERROR_DECODE_SLICES 8720721#if FF_API_FRAME_PKT722/**723* size of the corresponding packet containing the compressed724* frame.725* It is set to a negative value if unknown.726* - encoding: unused727* - decoding: set by libavcodec, read by user.728* @deprecated use AV_CODEC_FLAG_COPY_OPAQUE to pass through arbitrary user729* data from packets to frames730*/731attribute_deprecated732int pkt_size;733#endif734735/**736* For hwaccel-format frames, this should be a reference to the737* AVHWFramesContext describing the frame.738*/739AVBufferRef *hw_frames_ctx;740741/**742* Frame owner's private data.743*744* This field may be set by the code that allocates/owns the frame data.745* It is then not touched by any library functions, except:746* - a new reference to the underlying buffer is propagated by747* av_frame_copy_props() (and hence by av_frame_ref());748* - it is unreferenced in av_frame_unref();749* - on the caller's explicit request. E.g. libavcodec encoders/decoders750* will propagate a new reference to/from @ref AVPacket "AVPackets" if the751* caller sets @ref AV_CODEC_FLAG_COPY_OPAQUE.752*753* @see opaque the plain pointer analogue754*/755AVBufferRef *opaque_ref;756757/**758* @anchor cropping759* @name Cropping760* Video frames only. The number of pixels to discard from the the761* top/bottom/left/right border of the frame to obtain the sub-rectangle of762* the frame intended for presentation.763* @{764*/765size_t crop_top;766size_t crop_bottom;767size_t crop_left;768size_t crop_right;769/**770* @}771*/772773/**774* AVBufferRef for internal use by a single libav* library.775* Must not be used to transfer data between libraries.776* Has to be NULL when ownership of the frame leaves the respective library.777*778* Code outside the FFmpeg libs should never check or change the contents of the buffer ref.779*780* FFmpeg calls av_buffer_unref() on it when the frame is unreferenced.781* av_frame_copy_props() calls create a new reference with av_buffer_ref()782* for the target frame's private_ref field.783*/784AVBufferRef *private_ref;785786/**787* Channel layout of the audio data.788*/789AVChannelLayout ch_layout;790791/**792* Duration of the frame, in the same units as pts. 0 if unknown.793*/794int64_t duration;795} AVFrame;796797798/**799* Allocate an AVFrame and set its fields to default values. The resulting800* struct must be freed using av_frame_free().801*802* @return An AVFrame filled with default values or NULL on failure.803*804* @note this only allocates the AVFrame itself, not the data buffers. Those805* must be allocated through other means, e.g. with av_frame_get_buffer() or806* manually.807*/808AVFrame *av_frame_alloc(void);809810/**811* Free the frame and any dynamically allocated objects in it,812* e.g. extended_data. If the frame is reference counted, it will be813* unreferenced first.814*815* @param frame frame to be freed. The pointer will be set to NULL.816*/817void av_frame_free(AVFrame **frame);818819/**820* Set up a new reference to the data described by the source frame.821*822* Copy frame properties from src to dst and create a new reference for each823* AVBufferRef from src.824*825* If src is not reference counted, new buffers are allocated and the data is826* copied.827*828* @warning: dst MUST have been either unreferenced with av_frame_unref(dst),829* or newly allocated with av_frame_alloc() before calling this830* function, or undefined behavior will occur.831*832* @return 0 on success, a negative AVERROR on error833*/834int av_frame_ref(AVFrame *dst, const AVFrame *src);835836/**837* Ensure the destination frame refers to the same data described by the source838* frame, either by creating a new reference for each AVBufferRef from src if839* they differ from those in dst, by allocating new buffers and copying data if840* src is not reference counted, or by unrefencing it if src is empty.841*842* Frame properties on dst will be replaced by those from src.843*844* @return 0 on success, a negative AVERROR on error. On error, dst is845* unreferenced.846*/847int av_frame_replace(AVFrame *dst, const AVFrame *src);848849/**850* Create a new frame that references the same data as src.851*852* This is a shortcut for av_frame_alloc()+av_frame_ref().853*854* @return newly created AVFrame on success, NULL on error.855*/856AVFrame *av_frame_clone(const AVFrame *src);857858/**859* Unreference all the buffers referenced by frame and reset the frame fields.860*/861void av_frame_unref(AVFrame *frame);862863/**864* Move everything contained in src to dst and reset src.865*866* @warning: dst is not unreferenced, but directly overwritten without reading867* or deallocating its contents. Call av_frame_unref(dst) manually868* before calling this function to ensure that no memory is leaked.869*/870void av_frame_move_ref(AVFrame *dst, AVFrame *src);871872/**873* Allocate new buffer(s) for audio or video data.874*875* The following fields must be set on frame before calling this function:876* - format (pixel format for video, sample format for audio)877* - width and height for video878* - nb_samples and ch_layout for audio879*880* This function will fill AVFrame.data and AVFrame.buf arrays and, if881* necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.882* For planar formats, one buffer will be allocated for each plane.883*884* @warning: if frame already has been allocated, calling this function will885* leak memory. In addition, undefined behavior can occur in certain886* cases.887*888* @param frame frame in which to store the new buffers.889* @param align Required buffer size alignment. If equal to 0, alignment will be890* chosen automatically for the current CPU. It is highly891* recommended to pass 0 here unless you know what you are doing.892*893* @return 0 on success, a negative AVERROR on error.894*/895int av_frame_get_buffer(AVFrame *frame, int align);896897/**898* Check if the frame data is writable.899*900* @return A positive value if the frame data is writable (which is true if and901* only if each of the underlying buffers has only one reference, namely the one902* stored in this frame). Return 0 otherwise.903*904* If 1 is returned the answer is valid until av_buffer_ref() is called on any905* of the underlying AVBufferRefs (e.g. through av_frame_ref() or directly).906*907* @see av_frame_make_writable(), av_buffer_is_writable()908*/909int av_frame_is_writable(AVFrame *frame);910911/**912* Ensure that the frame data is writable, avoiding data copy if possible.913*914* Do nothing if the frame is writable, allocate new buffers and copy the data915* if it is not. Non-refcounted frames behave as non-writable, i.e. a copy916* is always made.917*918* @return 0 on success, a negative AVERROR on error.919*920* @see av_frame_is_writable(), av_buffer_is_writable(),921* av_buffer_make_writable()922*/923int av_frame_make_writable(AVFrame *frame);924925/**926* Copy the frame data from src to dst.927*928* This function does not allocate anything, dst must be already initialized and929* allocated with the same parameters as src.930*931* This function only copies the frame data (i.e. the contents of the data /932* extended data arrays), not any other properties.933*934* @return >= 0 on success, a negative AVERROR on error.935*/936int av_frame_copy(AVFrame *dst, const AVFrame *src);937938/**939* Copy only "metadata" fields from src to dst.940*941* Metadata for the purpose of this function are those fields that do not affect942* the data layout in the buffers. E.g. pts, sample rate (for audio) or sample943* aspect ratio (for video), but not width/height or channel layout.944* Side data is also copied.945*/946int av_frame_copy_props(AVFrame *dst, const AVFrame *src);947948/**949* Get the buffer reference a given data plane is stored in.950*951* @param frame the frame to get the plane's buffer from952* @param plane index of the data plane of interest in frame->extended_data.953*954* @return the buffer reference that contains the plane or NULL if the input955* frame is not valid.956*/957AVBufferRef *av_frame_get_plane_buffer(const AVFrame *frame, int plane);958959/**960* Add a new side data to a frame.961*962* @param frame a frame to which the side data should be added963* @param type type of the added side data964* @param size size of the side data965*966* @return newly added side data on success, NULL on error967*/968AVFrameSideData *av_frame_new_side_data(AVFrame *frame,969enum AVFrameSideDataType type,970size_t size);971972/**973* Add a new side data to a frame from an existing AVBufferRef974*975* @param frame a frame to which the side data should be added976* @param type the type of the added side data977* @param buf an AVBufferRef to add as side data. The ownership of978* the reference is transferred to the frame.979*980* @return newly added side data on success, NULL on error. On failure981* the frame is unchanged and the AVBufferRef remains owned by982* the caller.983*/984AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,985enum AVFrameSideDataType type,986AVBufferRef *buf);987988/**989* @return a pointer to the side data of a given type on success, NULL if there990* is no side data with such type in this frame.991*/992AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,993enum AVFrameSideDataType type);994995/**996* Remove and free all side data instances of the given type.997*/998void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);99910001001/**1002* Flags for frame cropping.1003*/1004enum {1005/**1006* Apply the maximum possible cropping, even if it requires setting the1007* AVFrame.data[] entries to unaligned pointers. Passing unaligned data1008* to FFmpeg API is generally not allowed, and causes undefined behavior1009* (such as crashes). You can pass unaligned data only to FFmpeg APIs that1010* are explicitly documented to accept it. Use this flag only if you1011* absolutely know what you are doing.1012*/1013AV_FRAME_CROP_UNALIGNED = 1 << 0,1014};10151016/**1017* Crop the given video AVFrame according to its crop_left/crop_top/crop_right/1018* crop_bottom fields. If cropping is successful, the function will adjust the1019* data pointers and the width/height fields, and set the crop fields to 0.1020*1021* In all cases, the cropping boundaries will be rounded to the inherent1022* alignment of the pixel format. In some cases, such as for opaque hwaccel1023* formats, the left/top cropping is ignored. The crop fields are set to 0 even1024* if the cropping was rounded or ignored.1025*1026* @param frame the frame which should be cropped1027* @param flags Some combination of AV_FRAME_CROP_* flags, or 0.1028*1029* @return >= 0 on success, a negative AVERROR on error. If the cropping fields1030* were invalid, AVERROR(ERANGE) is returned, and nothing is changed.1031*/1032int av_frame_apply_cropping(AVFrame *frame, int flags);10331034/**1035* @return a string identifying the side data type1036*/1037const char *av_frame_side_data_name(enum AVFrameSideDataType type);10381039/**1040* @return side data descriptor corresponding to a given side data type, NULL1041* when not available.1042*/1043const AVSideDataDescriptor *av_frame_side_data_desc(enum AVFrameSideDataType type);10441045/**1046* Free all side data entries and their contents, then zeroes out the1047* values which the pointers are pointing to.1048*1049* @param sd pointer to array of side data to free. Will be set to NULL1050* upon return.1051* @param nb_sd pointer to an integer containing the number of entries in1052* the array. Will be set to 0 upon return.1053*/1054void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd);10551056/**1057* Remove existing entries before adding new ones.1058*/1059#define AV_FRAME_SIDE_DATA_FLAG_UNIQUE (1 << 0)1060/**1061* Don't add a new entry if another of the same type exists.1062* Applies only for side data types without the AV_SIDE_DATA_PROP_MULTI prop.1063*/1064#define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1)10651066/**1067* Add new side data entry to an array.1068*1069* @param sd pointer to array of side data to which to add another entry,1070* or to NULL in order to start a new array.1071* @param nb_sd pointer to an integer containing the number of entries in1072* the array.1073* @param type type of the added side data1074* @param size size of the side data1075* @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.1076*1077* @return newly added side data on success, NULL on error.1078* @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of1079* matching AVFrameSideDataType will be removed before the addition1080* is attempted.1081* @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an1082* entry of the same type already exists, it will be replaced instead.1083*/1084AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,1085enum AVFrameSideDataType type,1086size_t size, unsigned int flags);10871088/**1089* Add a new side data entry to an array from an existing AVBufferRef.1090*1091* @param sd pointer to array of side data to which to add another entry,1092* or to NULL in order to start a new array.1093* @param nb_sd pointer to an integer containing the number of entries in1094* the array.1095* @param type type of the added side data1096* @param buf Pointer to AVBufferRef to add to the array. On success,1097* the function takes ownership of the AVBufferRef and *buf is1098* set to NULL, unless AV_FRAME_SIDE_DATA_FLAG_NEW_REF is set1099* in which case the ownership will remain with the caller.1100* @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.1101*1102* @return newly added side data on success, NULL on error.1103* @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of1104* matching AVFrameSideDataType will be removed before the addition1105* is attempted.1106* @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an1107* entry of the same type already exists, it will be replaced instead.1108*1109*/1110AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,1111enum AVFrameSideDataType type,1112AVBufferRef **buf, unsigned int flags);11131114/**1115* Add a new side data entry to an array based on existing side data, taking1116* a reference towards the contained AVBufferRef.1117*1118* @param sd pointer to array of side data to which to add another entry,1119* or to NULL in order to start a new array.1120* @param nb_sd pointer to an integer containing the number of entries in1121* the array.1122* @param src side data to be cloned, with a new reference utilized1123* for the buffer.1124* @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.1125*1126* @return negative error code on failure, >=0 on success.1127* @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of1128* matching AVFrameSideDataType will be removed before the addition1129* is attempted.1130* @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an1131* entry of the same type already exists, it will be replaced instead.1132*/1133int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,1134const AVFrameSideData *src, unsigned int flags);11351136/**1137* Get a side data entry of a specific type from an array.1138*1139* @param sd array of side data.1140* @param nb_sd integer containing the number of entries in the array.1141* @param type type of side data to be queried1142*1143* @return a pointer to the side data of a given type on success, NULL if there1144* is no side data with such type in this set.1145*/1146const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *sd,1147const int nb_sd,1148enum AVFrameSideDataType type);11491150/**1151* Wrapper around av_frame_side_data_get_c() to workaround the limitation1152* that for any type T the conversion from T * const * to const T * const *1153* is not performed automatically in C.1154* @see av_frame_side_data_get_c()1155*/1156static inline1157const AVFrameSideData *av_frame_side_data_get(AVFrameSideData * const *sd,1158const int nb_sd,1159enum AVFrameSideDataType type)1160{1161return av_frame_side_data_get_c((const AVFrameSideData * const *)sd,1162nb_sd, type);1163}11641165/**1166* Remove and free all side data instances of the given type from an array.1167*/1168void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,1169enum AVFrameSideDataType type);1170/**1171* @}1172*/11731174#endif /* AVUTIL_FRAME_H */117511761177