Path: blob/master/dep/ffmpeg/include/libavutil/frame.h
7512 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* Recommends 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,245246/**247* This side data contains information about the reference display width(s)248* and reference viewing distance(s) as well as information about the249* corresponding reference stereo pair(s), i.e., the pair(s) of views to be250* displayed for the viewer's left and right eyes on the reference display251* at the reference viewing distance.252* The payload is the AV3DReferenceDisplaysInfo struct defined in253* libavutil/tdrdi.h.254*/255AV_FRAME_DATA_3D_REFERENCE_DISPLAYS,256};257258enum AVActiveFormatDescription {259AV_AFD_SAME = 8,260AV_AFD_4_3 = 9,261AV_AFD_16_9 = 10,262AV_AFD_14_9 = 11,263AV_AFD_4_3_SP_14_9 = 13,264AV_AFD_16_9_SP_14_9 = 14,265AV_AFD_SP_4_3 = 15,266};267268269/**270* Structure to hold side data for an AVFrame.271*272* sizeof(AVFrameSideData) is not a part of the public ABI, so new fields may be added273* to the end with a minor bump.274*/275typedef struct AVFrameSideData {276enum AVFrameSideDataType type;277uint8_t *data;278size_t size;279AVDictionary *metadata;280AVBufferRef *buf;281} AVFrameSideData;282283enum AVSideDataProps {284/**285* The side data type can be used in stream-global structures.286* Side data types without this property are only meaningful on per-frame287* basis.288*/289AV_SIDE_DATA_PROP_GLOBAL = (1 << 0),290291/**292* Multiple instances of this side data type can be meaningfully present in293* a single side data array.294*/295AV_SIDE_DATA_PROP_MULTI = (1 << 1),296297/**298* Side data depends on the video dimensions. Side data with this property299* loses its meaning when rescaling or cropping the image, unless300* either recomputed or adjusted to the new resolution.301*/302AV_SIDE_DATA_PROP_SIZE_DEPENDENT = (1 << 2),303304/**305* Side data depends on the video color space. Side data with this property306* loses its meaning when changing the video color encoding, e.g. by307* adapting to a different set of primaries or transfer characteristics.308*/309AV_SIDE_DATA_PROP_COLOR_DEPENDENT = (1 << 3),310311/**312* Side data depends on the channel layout. Side data with this property313* loses its meaning when downmixing or upmixing, unless either recomputed314* or adjusted to the new layout.315*/316AV_SIDE_DATA_PROP_CHANNEL_DEPENDENT = (1 << 4),317};318319/**320* This struct describes the properties of a side data type. Its instance321* corresponding to a given type can be obtained from av_frame_side_data_desc().322*/323typedef struct AVSideDataDescriptor {324/**325* Human-readable side data description.326*/327const char *name;328329/**330* Side data property flags, a combination of AVSideDataProps values.331*/332unsigned props;333} AVSideDataDescriptor;334335/**336* Structure describing a single Region Of Interest.337*338* When multiple regions are defined in a single side-data block, they339* should be ordered from most to least important - some encoders are only340* capable of supporting a limited number of distinct regions, so will have341* to truncate the list.342*343* When overlapping regions are defined, the first region containing a given344* area of the frame applies.345*/346typedef struct AVRegionOfInterest {347/**348* Must be set to the size of this data structure (that is,349* sizeof(AVRegionOfInterest)).350*/351uint32_t self_size;352/**353* Distance in pixels from the top edge of the frame to the top and354* bottom edges and from the left edge of the frame to the left and355* right edges of the rectangle defining this region of interest.356*357* The constraints on a region are encoder dependent, so the region358* actually affected may be slightly larger for alignment or other359* reasons.360*/361int top;362int bottom;363int left;364int right;365/**366* Quantisation offset.367*368* Must be in the range -1 to +1. A value of zero indicates no quality369* change. A negative value asks for better quality (less quantisation),370* while a positive value asks for worse quality (greater quantisation).371*372* The range is calibrated so that the extreme values indicate the373* largest possible offset - if the rest of the frame is encoded with the374* worst possible quality, an offset of -1 indicates that this region375* should be encoded with the best possible quality anyway. Intermediate376* values are then interpolated in some codec-dependent way.377*378* For example, in 10-bit H.264 the quantisation parameter varies between379* -12 and 51. A typical qoffset value of -1/10 therefore indicates that380* this region should be encoded with a QP around one-tenth of the full381* range better than the rest of the frame. So, if most of the frame382* were to be encoded with a QP of around 30, this region would get a QP383* of around 24 (an offset of approximately -1/10 * (51 - -12) = -6.3).384* An extreme value of -1 would indicate that this region should be385* encoded with the best possible quality regardless of the treatment of386* the rest of the frame - that is, should be encoded at a QP of -12.387*/388AVRational qoffset;389} AVRegionOfInterest;390391/**392* This structure describes decoded (raw) audio or video data.393*394* AVFrame must be allocated using av_frame_alloc(). Note that this only395* allocates the AVFrame itself, the buffers for the data must be managed396* through other means (see below).397* AVFrame must be freed with av_frame_free().398*399* AVFrame is typically allocated once and then reused multiple times to hold400* different data (e.g. a single AVFrame to hold frames received from a401* decoder). In such a case, av_frame_unref() will free any references held by402* the frame and reset it to its original clean state before it403* is reused again.404*405* The data described by an AVFrame is usually reference counted through the406* AVBuffer API. The underlying buffer references are stored in AVFrame.buf /407* AVFrame.extended_buf. An AVFrame is considered to be reference counted if at408* least one reference is set, i.e. if AVFrame.buf[0] != NULL. In such a case,409* every single data plane must be contained in one of the buffers in410* AVFrame.buf or AVFrame.extended_buf.411* There may be a single buffer for all the data, or one separate buffer for412* each plane, or anything in between.413*414* sizeof(AVFrame) is not a part of the public ABI, so new fields may be added415* to the end with a minor bump.416*417* Fields can be accessed through AVOptions, the name string used, matches the418* C structure field name for fields accessible through AVOptions.419*/420typedef struct AVFrame {421#define AV_NUM_DATA_POINTERS 8422/**423* pointer to the picture/channel planes.424* This might be different from the first allocated byte. For video,425* it could even point to the end of the image data.426*427* All pointers in data and extended_data must point into one of the428* AVBufferRef in buf or extended_buf.429*430* Some decoders access areas outside 0,0 - width,height, please431* see avcodec_align_dimensions2(). Some filters and swscale can read432* up to 16 bytes beyond the planes, if these filters are to be used,433* then 16 extra bytes must be allocated.434*435* NOTE: Pointers not needed by the format MUST be set to NULL.436*437* @attention In case of video, the data[] pointers can point to the438* end of image data in order to reverse line order, when used in439* combination with negative values in the linesize[] array.440*/441uint8_t *data[AV_NUM_DATA_POINTERS];442443/**444* For video, a positive or negative value, which is typically indicating445* the size in bytes of each picture line, but it can also be:446* - the negative byte size of lines for vertical flipping447* (with data[n] pointing to the end of the data448* - a positive or negative multiple of the byte size as for accessing449* even and odd fields of a frame (possibly flipped)450*451* For audio, only linesize[0] may be set. For planar audio, each channel452* plane must be the same size.453*454* For video the linesizes should be multiples of the CPUs alignment455* preference, this is 16 or 32 for modern desktop CPUs.456* Some code requires such alignment other code can be slower without457* correct alignment, for yet other it makes no difference.458*459* @note The linesize may be larger than the size of usable data -- there460* may be extra padding present for performance reasons.461*462* @attention In case of video, line size values can be negative to achieve463* a vertically inverted iteration over image lines.464*/465int linesize[AV_NUM_DATA_POINTERS];466467/**468* pointers to the data planes/channels.469*470* For video, this should simply point to data[].471*472* For planar audio, each channel has a separate data pointer, and473* linesize[0] contains the size of each channel buffer.474* For packed audio, there is just one data pointer, and linesize[0]475* contains the total size of the buffer for all channels.476*477* Note: Both data and extended_data should always be set in a valid frame,478* but for planar audio with more channels that can fit in data,479* extended_data must be used in order to access all channels.480*/481uint8_t **extended_data;482483/**484* @name Video dimensions485* Video frames only. The coded dimensions (in pixels) of the video frame,486* i.e. the size of the rectangle that contains some well-defined values.487*488* @note The part of the frame intended for display/presentation is further489* restricted by the @ref cropping "Cropping rectangle".490* @{491*/492int width, height;493/**494* @}495*/496497/**498* number of audio samples (per channel) described by this frame499*/500int nb_samples;501502/**503* format of the frame, -1 if unknown or unset504* Values correspond to enum AVPixelFormat for video frames,505* enum AVSampleFormat for audio)506*/507int format;508509/**510* Picture type of the frame.511*/512enum AVPictureType pict_type;513514/**515* Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.516*/517AVRational sample_aspect_ratio;518519/**520* Presentation timestamp in time_base units (time when frame should be shown to user).521*/522int64_t pts;523524/**525* DTS copied from the AVPacket that triggered returning this frame. (if frame threading isn't used)526* This is also the Presentation time of this AVFrame calculated from527* only AVPacket.dts values without pts values.528*/529int64_t pkt_dts;530531/**532* Time base for the timestamps in this frame.533* In the future, this field may be set on frames output by decoders or534* filters, but its value will be by default ignored on input to encoders535* or filters.536*/537AVRational time_base;538539/**540* quality (between 1 (good) and FF_LAMBDA_MAX (bad))541*/542int quality;543544/**545* Frame owner's private data.546*547* This field may be set by the code that allocates/owns the frame data.548* It is then not touched by any library functions, except:549* - it is copied to other references by av_frame_copy_props() (and hence by550* av_frame_ref());551* - it is set to NULL when the frame is cleared by av_frame_unref()552* - on the caller's explicit request. E.g. libavcodec encoders/decoders553* will copy this field to/from @ref AVPacket "AVPackets" if the caller sets554* @ref AV_CODEC_FLAG_COPY_OPAQUE.555*556* @see opaque_ref the reference-counted analogue557*/558void *opaque;559560/**561* Number of fields in this frame which should be repeated, i.e. the total562* duration of this frame should be repeat_pict + 2 normal field durations.563*564* For interlaced frames this field may be set to 1, which signals that this565* frame should be presented as 3 fields: beginning with the first field (as566* determined by AV_FRAME_FLAG_TOP_FIELD_FIRST being set or not), followed567* by the second field, and then the first field again.568*569* For progressive frames this field may be set to a multiple of 2, which570* signals that this frame's duration should be (repeat_pict + 2) / 2571* normal frame durations.572*573* @note This field is computed from MPEG2 repeat_first_field flag and its574* associated flags, H.264 pic_struct from picture timing SEI, and575* their analogues in other codecs. Typically it should only be used when576* higher-layer timing information is not available.577*/578int repeat_pict;579580/**581* Sample rate of the audio data.582*/583int sample_rate;584585/**586* AVBuffer references backing the data for this frame. All the pointers in587* data and extended_data must point inside one of the buffers in buf or588* extended_buf. This array must be filled contiguously -- if buf[i] is589* non-NULL then buf[j] must also be non-NULL for all j < i.590*591* There may be at most one AVBuffer per data plane, so for video this array592* always contains all the references. For planar audio with more than593* AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in594* this array. Then the extra AVBufferRef pointers are stored in the595* extended_buf array.596*/597AVBufferRef *buf[AV_NUM_DATA_POINTERS];598599/**600* For planar audio which requires more than AV_NUM_DATA_POINTERS601* AVBufferRef pointers, this array will hold all the references which602* cannot fit into AVFrame.buf.603*604* Note that this is different from AVFrame.extended_data, which always605* contains all the pointers. This array only contains the extra pointers,606* which cannot fit into AVFrame.buf.607*608* This array is always allocated using av_malloc() by whoever constructs609* the frame. It is freed in av_frame_unref().610*/611AVBufferRef **extended_buf;612/**613* Number of elements in extended_buf.614*/615int nb_extended_buf;616617AVFrameSideData **side_data;618int nb_side_data;619620/**621* @defgroup lavu_frame_flags AV_FRAME_FLAGS622* @ingroup lavu_frame623* Flags describing additional frame properties.624*625* @{626*/627628/**629* The frame data may be corrupted, e.g. due to decoding errors.630*/631#define AV_FRAME_FLAG_CORRUPT (1 << 0)632/**633* A flag to mark frames that are keyframes.634*/635#define AV_FRAME_FLAG_KEY (1 << 1)636/**637* A flag to mark the frames which need to be decoded, but shouldn't be output.638*/639#define AV_FRAME_FLAG_DISCARD (1 << 2)640/**641* A flag to mark frames whose content is interlaced.642*/643#define AV_FRAME_FLAG_INTERLACED (1 << 3)644/**645* A flag to mark frames where the top field is displayed first if the content646* is interlaced.647*/648#define AV_FRAME_FLAG_TOP_FIELD_FIRST (1 << 4)649/**650* A decoder can use this flag to mark frames which were originally encoded losslessly.651*652* For coding bitstream formats which support both lossless and lossy653* encoding, it is sometimes possible for a decoder to determine which method654* was used when the bitsream was encoded.655*/656#define AV_FRAME_FLAG_LOSSLESS (1 << 5)657/**658* @}659*/660661/**662* Frame flags, a combination of @ref lavu_frame_flags663*/664int flags;665666/**667* MPEG vs JPEG YUV range.668* - encoding: Set by user669* - decoding: Set by libavcodec670*/671enum AVColorRange color_range;672673enum AVColorPrimaries color_primaries;674675enum AVColorTransferCharacteristic color_trc;676677/**678* YUV colorspace type.679* - encoding: Set by user680* - decoding: Set by libavcodec681*/682enum AVColorSpace colorspace;683684enum AVChromaLocation chroma_location;685686/**687* frame timestamp estimated using various heuristics, in stream time base688* - encoding: unused689* - decoding: set by libavcodec, read by user.690*/691int64_t best_effort_timestamp;692693/**694* metadata.695* - encoding: Set by user.696* - decoding: Set by libavcodec.697*/698AVDictionary *metadata;699700/**701* decode error flags of the frame, set to a combination of702* FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there703* were errors during the decoding.704* - encoding: unused705* - decoding: set by libavcodec, read by user.706*/707int decode_error_flags;708#define FF_DECODE_ERROR_INVALID_BITSTREAM 1709#define FF_DECODE_ERROR_MISSING_REFERENCE 2710#define FF_DECODE_ERROR_CONCEALMENT_ACTIVE 4711#define FF_DECODE_ERROR_DECODE_SLICES 8712713/**714* For hwaccel-format frames, this should be a reference to the715* AVHWFramesContext describing the frame.716*/717AVBufferRef *hw_frames_ctx;718719/**720* Frame owner's private data.721*722* This field may be set by the code that allocates/owns the frame data.723* It is then not touched by any library functions, except:724* - a new reference to the underlying buffer is propagated by725* av_frame_copy_props() (and hence by av_frame_ref());726* - it is unreferenced in av_frame_unref();727* - on the caller's explicit request. E.g. libavcodec encoders/decoders728* will propagate a new reference to/from @ref AVPacket "AVPackets" if the729* caller sets @ref AV_CODEC_FLAG_COPY_OPAQUE.730*731* @see opaque the plain pointer analogue732*/733AVBufferRef *opaque_ref;734735/**736* @anchor cropping737* @name Cropping738* Video frames only. The number of pixels to discard from the the739* top/bottom/left/right border of the frame to obtain the sub-rectangle of740* the frame intended for presentation.741* @{742*/743size_t crop_top;744size_t crop_bottom;745size_t crop_left;746size_t crop_right;747/**748* @}749*/750751/**752* RefStruct reference for internal use by a single libav* library.753* Must not be used to transfer data between libraries.754* Has to be NULL when ownership of the frame leaves the respective library.755*756* Code outside the FFmpeg libs must never check or change private_ref.757*/758void *private_ref;759760/**761* Channel layout of the audio data.762*/763AVChannelLayout ch_layout;764765/**766* Duration of the frame, in the same units as pts. 0 if unknown.767*/768int64_t duration;769} AVFrame;770771772/**773* Allocate an AVFrame and set its fields to default values. The resulting774* struct must be freed using av_frame_free().775*776* @return An AVFrame filled with default values or NULL on failure.777*778* @note this only allocates the AVFrame itself, not the data buffers. Those779* must be allocated through other means, e.g. with av_frame_get_buffer() or780* manually.781*/782AVFrame *av_frame_alloc(void);783784/**785* Free the frame and any dynamically allocated objects in it,786* e.g. extended_data. If the frame is reference counted, it will be787* unreferenced first.788*789* @param frame frame to be freed. The pointer will be set to NULL.790*/791void av_frame_free(AVFrame **frame);792793/**794* Set up a new reference to the data described by the source frame.795*796* Copy frame properties from src to dst and create a new reference for each797* AVBufferRef from src.798*799* If src is not reference counted, new buffers are allocated and the data is800* copied.801*802* @warning: dst MUST have been either unreferenced with av_frame_unref(dst),803* or newly allocated with av_frame_alloc() before calling this804* function, or undefined behavior will occur.805*806* @return 0 on success, a negative AVERROR on error807*/808int av_frame_ref(AVFrame *dst, const AVFrame *src);809810/**811* Ensure the destination frame refers to the same data described by the source812* frame, either by creating a new reference for each AVBufferRef from src if813* they differ from those in dst, by allocating new buffers and copying data if814* src is not reference counted, or by unrefencing it if src is empty.815*816* Frame properties on dst will be replaced by those from src.817*818* @return 0 on success, a negative AVERROR on error. On error, dst is819* unreferenced.820*/821int av_frame_replace(AVFrame *dst, const AVFrame *src);822823/**824* Create a new frame that references the same data as src.825*826* This is a shortcut for av_frame_alloc()+av_frame_ref().827*828* @return newly created AVFrame on success, NULL on error.829*/830AVFrame *av_frame_clone(const AVFrame *src);831832/**833* Unreference all the buffers referenced by frame and reset the frame fields.834*/835void av_frame_unref(AVFrame *frame);836837/**838* Move everything contained in src to dst and reset src.839*840* @warning: dst is not unreferenced, but directly overwritten without reading841* or deallocating its contents. Call av_frame_unref(dst) manually842* before calling this function to ensure that no memory is leaked.843*/844void av_frame_move_ref(AVFrame *dst, AVFrame *src);845846/**847* Allocate new buffer(s) for audio or video data.848*849* The following fields must be set on frame before calling this function:850* - format (pixel format for video, sample format for audio)851* - width and height for video852* - nb_samples and ch_layout for audio853*854* This function will fill AVFrame.data and AVFrame.buf arrays and, if855* necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.856* For planar formats, one buffer will be allocated for each plane.857*858* @warning: if frame already has been allocated, calling this function will859* leak memory. In addition, undefined behavior can occur in certain860* cases.861*862* @param frame frame in which to store the new buffers.863* @param align Required buffer size and data pointer alignment. If equal to 0,864* alignment will be chosen automatically for the current CPU.865* It is highly recommended to pass 0 here unless you know what866* you are doing.867*868* @return 0 on success, a negative AVERROR on error.869*/870int av_frame_get_buffer(AVFrame *frame, int align);871872/**873* Check if the frame data is writable.874*875* @return A positive value if the frame data is writable (which is true if and876* only if each of the underlying buffers has only one reference, namely the one877* stored in this frame). Return 0 otherwise.878*879* If 1 is returned the answer is valid until av_buffer_ref() is called on any880* of the underlying AVBufferRefs (e.g. through av_frame_ref() or directly).881*882* @see av_frame_make_writable(), av_buffer_is_writable()883*/884int av_frame_is_writable(AVFrame *frame);885886/**887* Ensure that the frame data is writable, avoiding data copy if possible.888*889* Do nothing if the frame is writable, allocate new buffers and copy the data890* if it is not. Non-refcounted frames behave as non-writable, i.e. a copy891* is always made.892*893* @return 0 on success, a negative AVERROR on error.894*895* @see av_frame_is_writable(), av_buffer_is_writable(),896* av_buffer_make_writable()897*/898int av_frame_make_writable(AVFrame *frame);899900/**901* Copy the frame data from src to dst.902*903* This function does not allocate anything, dst must be already initialized and904* allocated with the same parameters as src.905*906* This function only copies the frame data (i.e. the contents of the data /907* extended data arrays), not any other properties.908*909* @return >= 0 on success, a negative AVERROR on error.910*/911int av_frame_copy(AVFrame *dst, const AVFrame *src);912913/**914* Copy only "metadata" fields from src to dst.915*916* Metadata for the purpose of this function are those fields that do not affect917* the data layout in the buffers. E.g. pts, sample rate (for audio) or sample918* aspect ratio (for video), but not width/height or channel layout.919* Side data is also copied.920*/921int av_frame_copy_props(AVFrame *dst, const AVFrame *src);922923/**924* Get the buffer reference a given data plane is stored in.925*926* @param frame the frame to get the plane's buffer from927* @param plane index of the data plane of interest in frame->extended_data.928*929* @return the buffer reference that contains the plane or NULL if the input930* frame is not valid.931*/932AVBufferRef *av_frame_get_plane_buffer(const AVFrame *frame, int plane);933934/**935* Add a new side data to a frame.936*937* @param frame a frame to which the side data should be added938* @param type type of the added side data939* @param size size of the side data940*941* @return newly added side data on success, NULL on error942*/943AVFrameSideData *av_frame_new_side_data(AVFrame *frame,944enum AVFrameSideDataType type,945size_t size);946947/**948* Add a new side data to a frame from an existing AVBufferRef949*950* @param frame a frame to which the side data should be added951* @param type the type of the added side data952* @param buf an AVBufferRef to add as side data. The ownership of953* the reference is transferred to the frame.954*955* @return newly added side data on success, NULL on error. On failure956* the frame is unchanged and the AVBufferRef remains owned by957* the caller.958*/959AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,960enum AVFrameSideDataType type,961AVBufferRef *buf);962963/**964* @return a pointer to the side data of a given type on success, NULL if there965* is no side data with such type in this frame.966*/967AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,968enum AVFrameSideDataType type);969970/**971* Remove and free all side data instances of the given type.972*/973void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);974975976/**977* Flags for frame cropping.978*/979enum {980/**981* Apply the maximum possible cropping, even if it requires setting the982* AVFrame.data[] entries to unaligned pointers. Passing unaligned data983* to FFmpeg API is generally not allowed, and causes undefined behavior984* (such as crashes). You can pass unaligned data only to FFmpeg APIs that985* are explicitly documented to accept it. Use this flag only if you986* absolutely know what you are doing.987*/988AV_FRAME_CROP_UNALIGNED = 1 << 0,989};990991/**992* Crop the given video AVFrame according to its crop_left/crop_top/crop_right/993* crop_bottom fields. If cropping is successful, the function will adjust the994* data pointers and the width/height fields, and set the crop fields to 0.995*996* In all cases, the cropping boundaries will be rounded to the inherent997* alignment of the pixel format. In some cases, such as for opaque hwaccel998* formats, the left/top cropping is ignored. The crop fields are set to 0 even999* if the cropping was rounded or ignored.1000*1001* @param frame the frame which should be cropped1002* @param flags Some combination of AV_FRAME_CROP_* flags, or 0.1003*1004* @return >= 0 on success, a negative AVERROR on error. If the cropping fields1005* were invalid, AVERROR(ERANGE) is returned, and nothing is changed.1006*/1007int av_frame_apply_cropping(AVFrame *frame, int flags);10081009/**1010* @return a string identifying the side data type1011*/1012const char *av_frame_side_data_name(enum AVFrameSideDataType type);10131014/**1015* @return side data descriptor corresponding to a given side data type, NULL1016* when not available.1017*/1018const AVSideDataDescriptor *av_frame_side_data_desc(enum AVFrameSideDataType type);10191020/**1021* Free all side data entries and their contents, then zeroes out the1022* values which the pointers are pointing to.1023*1024* @param sd pointer to array of side data to free. Will be set to NULL1025* upon return.1026* @param nb_sd pointer to an integer containing the number of entries in1027* the array. Will be set to 0 upon return.1028*/1029void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd);10301031/**1032* Remove existing entries before adding new ones.1033*/1034#define AV_FRAME_SIDE_DATA_FLAG_UNIQUE (1 << 0)1035/**1036* Don't add a new entry if another of the same type exists.1037* Applies only for side data types without the AV_SIDE_DATA_PROP_MULTI prop.1038*/1039#define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1)1040/**1041* Create a new reference to the passed in buffer instead of taking ownership1042* of it.1043*/1044#define AV_FRAME_SIDE_DATA_FLAG_NEW_REF (1 << 2)10451046/**1047* Add new side data entry to an array.1048*1049* @param sd pointer to array of side data to which to add another entry,1050* or to NULL in order to start a new array.1051* @param nb_sd pointer to an integer containing the number of entries in1052* the array.1053* @param type type of the added side data1054* @param size size of the side data1055* @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.1056*1057* @return newly added side data on success, NULL on error.1058* @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of1059* matching AVFrameSideDataType will be removed before the addition1060* is attempted.1061* @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an1062* entry of the same type already exists, it will be replaced instead.1063*/1064AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,1065enum AVFrameSideDataType type,1066size_t size, unsigned int flags);10671068/**1069* Add a new side data entry to an array from an existing AVBufferRef.1070*1071* @param sd pointer to array of side data to which to add another entry,1072* or to NULL in order to start a new array.1073* @param nb_sd pointer to an integer containing the number of entries in1074* the array.1075* @param type type of the added side data1076* @param buf Pointer to AVBufferRef to add to the array. On success,1077* the function takes ownership of the AVBufferRef and *buf is1078* set to NULL, unless AV_FRAME_SIDE_DATA_FLAG_NEW_REF is set1079* in which case the ownership will remain with the caller.1080* @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.1081*1082* @return newly added side data on success, NULL on error.1083* @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of1084* matching AVFrameSideDataType will be removed before the addition1085* is attempted.1086* @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an1087* entry of the same type already exists, it will be replaced instead.1088*1089*/1090AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,1091enum AVFrameSideDataType type,1092AVBufferRef **buf, unsigned int flags);10931094/**1095* Add a new side data entry to an array based on existing side data, taking1096* a reference towards the contained AVBufferRef.1097*1098* @param sd pointer to array of side data to which to add another entry,1099* or to NULL in order to start a new array.1100* @param nb_sd pointer to an integer containing the number of entries in1101* the array.1102* @param src side data to be cloned, with a new reference utilized1103* for the buffer.1104* @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.1105*1106* @return negative error code on failure, >=0 on success.1107* @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of1108* matching AVFrameSideDataType will be removed before the addition1109* is attempted.1110* @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an1111* entry of the same type already exists, it will be replaced instead.1112*/1113int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,1114const AVFrameSideData *src, unsigned int flags);11151116/**1117* Get a side data entry of a specific type from an array.1118*1119* @param sd array of side data.1120* @param nb_sd integer containing the number of entries in the array.1121* @param type type of side data to be queried1122*1123* @return a pointer to the side data of a given type on success, NULL if there1124* is no side data with such type in this set.1125*/1126const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *sd,1127const int nb_sd,1128enum AVFrameSideDataType type);11291130/**1131* Wrapper around av_frame_side_data_get_c() to workaround the limitation1132* that for any type T the conversion from T * const * to const T * const *1133* is not performed automatically in C.1134* @see av_frame_side_data_get_c()1135*/1136static inline1137const AVFrameSideData *av_frame_side_data_get(AVFrameSideData * const *sd,1138const int nb_sd,1139enum AVFrameSideDataType type)1140{1141return av_frame_side_data_get_c((const AVFrameSideData * const *)sd,1142nb_sd, type);1143}11441145/**1146* Remove and free all side data instances of the given type from an array.1147*/1148void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,1149enum AVFrameSideDataType type);11501151/**1152* Remove and free all side data instances that match any of the given1153* side data properties. (See enum AVSideDataProps)1154*/1155void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd,1156int props);11571158/**1159* @}1160*/11611162#endif /* AVUTIL_FRAME_H */116311641165