【FFmpeg】AVStream结构体

【FFmpeg】AVStream结构体

  • 1.AVStream结构体的定义
    • [1.1 AVCodecParameters *codecpar](#1.1 AVCodecParameters *codecpar)
      • [1.1.1 AVPacketSideData *coded_side_data](#1.1.1 AVPacketSideData *coded_side_data)
      • [1.1.2 enum AVColorRange color_range](#1.1.2 enum AVColorRange color_range)
      • [1.1.3 enum AVColorPrimaries color_primaries](#1.1.3 enum AVColorPrimaries color_primaries)
      • [1.1.4 enum AVColorTransferCharacteristic color_trc](#1.1.4 enum AVColorTransferCharacteristic color_trc)
      • [1.1.5 enum AVColorSpace color_space](#1.1.5 enum AVColorSpace color_space)
      • [1.1.6 enum AVChromaLocation chroma_location](#1.1.6 enum AVChromaLocation chroma_location)
      • [1.2.1 enum AVDiscard discard](#1.2.1 enum AVDiscard discard)

参考:
FFMPEG结构体分析:AVStream

示例工程:
【FFmpeg】调用ffmpeg库实现264软编
【FFmpeg】调用ffmpeg库实现264软解
【FFmpeg】调用ffmpeg库进行RTMP推流和拉流
【FFmpeg】调用ffmpeg库进行SDL2解码后渲染

流程分析:
【FFmpeg】编码链路上主要函数的简单分析
【FFmpeg】解码链路上主要函数的简单分析

结构体分析:
【FFmpeg】AVCodec结构体
【FFmpeg】AVCodecContext结构体

今天重读AVStream结构体,参考雷博的文章,发现主要的结构体当中的变量都有些许改变,有必要重新记录一番

1.AVStream结构体的定义

AVStream记录了视频或音频码流中的信息,定义位于libavformat\avformat.h。这里与雷博记录的内容有所不同,在早期的FFmpeg版本中,AVStream中会存储AVCodecContext结构体,但是新版本中只会存储AVCodecParameters,即编解码器的参数

c 复制代码
/**
 * Stream structure.
 * New fields can be added to the end with minor version bumps.
 * Removal, reordering and changes to existing fields require a major
 * version bump.
 * sizeof(AVStream) must not be used outside libav*.
 */
// 流结构
// 新字段可以添加到末尾,并伴有轻微的版本变化
// 删除、重新排序和更改现有字段需要一个主要的版本更新
// sizeof(AVStream)不能在libav*之外使用
typedef struct AVStream {
    /**
     * A class for @ref avoptions. Set on stream creation.
     */
    // 描述当前结构体的结构体
    const AVClass *av_class;
	// AVFormatContext中码流的索引号
    int index;    /**< stream index in AVFormatContext */
    /**
     * Format-specific stream ID.
     * decoding: set by libavformat
     * encoding: set by the user, replaced by libavformat if left unset
     */
    // 特定于格式的流ID
    int id;

    /**
     * Codec parameters associated with this stream. Allocated and freed by
     * libavformat in avformat_new_stream() and avformat_free_context()
     * respectively.
     *
     * - demuxing: filled by libavformat on stream creation or in
     *             avformat_find_stream_info()
     * - muxing: filled by the caller before avformat_write_header()
     */
    // 与此流相关的编解码器参数
    // 由libavformat分别在avformat_new_stream()和avformat_free_context()中分配和释放
    AVCodecParameters *codecpar;
	// 私有参数,常用于数据格式的强制转换
    void *priv_data;

    /**
     * This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented.
     *
     * decoding: set by libavformat
     * encoding: May be set by the caller before avformat_write_header() to
     *           provide a hint to the muxer about the desired timebase. In
     *           avformat_write_header(), the muxer will overwrite this field
     *           with the timebase that will actually be used for the timestamps
     *           written into the file (which may or may not be related to the
     *           user-provided one, depending on the format).
     */
    // 这是表示帧时间戳的基本时间单位(以秒为单位)
    /*
		encoding:
		可以由调用者在avformat_write_header()之前设置,以向复用器提供有关所需时基的提示
		在avformat_write_header()中,muxer将用实际用于写入文件的时间戳的时间基覆盖该字段
		(根据格式,它可能与用户提供的时间戳相关,也可能不相关)
	*/
    AVRational time_base;

    /**
     * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
     * Only set this if you are absolutely 100% sure that the value you set
     * it to really is the pts of the first frame.
     * This may be undefined (AV_NOPTS_VALUE).
     * @note The ASF header does NOT contain a correct start_time the ASF
     * demuxer must NOT set this.
     */
    // 流第一帧的PTS按表示顺序,以流时间为基础
    // 只有当100%确定所设置的值是第一帧的分数时才设置这个值
    // 这个值可能是未定义的
    // @note ASF报头没有包含正确的start_time, ASF demuxer不能设置这个
    int64_t start_time;

    /**
     * Decoding: duration of the stream, in stream time base.
     * If a source file does not specify a duration, but does specify
     * a bitrate, this value will be estimated from bitrate and file size.
     *
     * Encoding: May be set by the caller before avformat_write_header() to
     * provide a hint to the muxer about the estimated duration.
     */
    // Decoding: 流持续的时间,以流的时间基
    // 如果源文件没有指定持续时间,但指定了比特率,则将根据比特率和文件大小估计该值
    // Encoding: 可以由调用者在avformat_write_header()之前设置,以提供有关估计持续时间的提示
    int64_t duration;
	// 如果流当中帧数量已知,则设置;否则默认为0
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0

    /**
     * Stream disposition - a combination of AV_DISPOSITION_* flags.
     * - demuxing: set by libavformat when creating the stream or in
     *             avformat_find_stream_info().
     * - muxing: may be set by the caller before avformat_write_header().
     */
    // 流处置- AV_DISPOSITION_*标志的组合
    // demuxing: 由libavformat在创建流或avformat_find_stream_info()中设置
    // muxing: 可以在avformat_write_header()之前由调用者设置
    int disposition;
	// 选择可以随意丢弃且不需要解绑定的报文
    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.

    /**
     * sample aspect ratio (0 if unknown)
     * - encoding: Set by user.
     * - decoding: Set by libavformat.
     */
    // 样本宽高比(如果未知则为0)
    AVRational sample_aspect_ratio;
	// 字典类型的元数据 
    AVDictionary *metadata;

    /**
     * Average framerate
     *
     * - demuxing: May be set by libavformat when creating the stream or in
     *             avformat_find_stream_info().
     * - muxing: May be set by the caller before avformat_write_header().
     */
    // 平均的帧率
    AVRational avg_frame_rate;

    /**
     * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
     * will contain the attached picture.
     *
     * decoding: set by libavformat, must not be modified by the caller.
     * encoding: unused
     */
    // 对于AV_DISPOSITION_ATTACHED_PIC配置的流,该数据包将包含附加的图片
    AVPacket attached_pic;

#if FF_API_AVSTREAM_SIDE_DATA
    /**
     * An array of side data that applies to the whole stream (i.e. the
     * container does not allow it to change between packets).
     *
     * There may be no overlap between the side data in this array and side data
     * in the packets. I.e. a given side data is either exported by the muxer
     * (demuxing) / set by the caller (muxing) in this array, then it never
     * appears in the packets, or the side data is exported / sent through
     * the packets (always in the first packet where the value becomes known or
     * changes), then it does not appear in this array.
     *
     * - demuxing: Set by libavformat when the stream is created.
     * - muxing: May be set by the caller before avformat_write_header().
     *
     * Freed by libavformat in avformat_free_context().
     *
     * @deprecated use AVStream's @ref AVCodecParameters.coded_side_data
     *             "codecpar side data".
     */
    /*
		1.应用于整个流的辅助数据数组(即容器不允许它在数据包之间改变)

		2.在这个数组中的侧数据和包中的侧数据之间可能没有重叠。即,给定的侧数据要么由该数组中的
		muxer (demuxing)导出/由调用者(muxing)设置,然后它永远不会出现在数据包中,
		或者侧数据通过数据包导出/发送(总是在值已知或更改的第一个数据包中),然后它不会出现在此数组中

		demuxing: 在创建流时由libavformat设置
		muxing: 可以在avformat_write_header()之前由调用者设置

		3.在avformat_free_context()中被libavformat释放
	*/
    attribute_deprecated
    AVPacketSideData *side_data;
    /**
     * The number of elements in the AVStream.side_data array.
     *
     * @deprecated use AVStream's @ref AVCodecParameters.nb_coded_side_data
     *             "codecpar side data".
     */
    // AVStream中元素的数量.side_data数组
    attribute_deprecated
    int            nb_side_data;
#endif

    /**
     * Flags indicating events happening on the stream, a combination of
     * AVSTREAM_EVENT_FLAG_*.
     *
     * - demuxing: may be set by the demuxer in avformat_open_input(),
     *   avformat_find_stream_info() and av_read_frame(). Flags must be cleared
     *   by the user once the event has been handled.
     * - muxing: may be set by the user after avformat_write_header(). to
     *   indicate a user-triggered event.  The muxer will clear the flags for
     *   events it has handled in av_[interleaved]_write_frame().
     */
    // 指示流上发生的事件的标志,AVSTREAM_EVENT_FLAG_*的组合,使用不同的位标识
    /*
		demuxing: 可以由avformat_open_input(), avformat_find_stream_info()和av_read_frame()中的demuxer设置。
					一旦事件被处理,用户必须清除标志
		muxing: 可以在avformat_write_header()之后由用户设置。表示用户触发的事件。
					muxer将清除av_[interleaved]_write_frame()中处理的事件的标志。
	*/
    int event_flags;
/**
 * - demuxing: the demuxer read new metadata from the file and updated
 *     AVStream.metadata accordingly
 * - muxing: the user updated AVStream.metadata and wishes the muxer to write
 *     it into the file
 */
// demuxing: demuxer从文件中读取新的元数据并更新相应的AVStream.metadata
// muxing: 用户更新了AVStream.metadata,并希望编辑器将其写入文件
#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001
/**
 * - demuxing: new packets for this stream were read from the file. This
 *   event is informational only and does not guarantee that new packets
 *   for this stream will necessarily be returned from av_read_frame().
 */
// 从文件中读取了该流的新数据包。此事件仅提供信息,不保证av_read_frame()一定会返回此流的新数据包
#define AVSTREAM_EVENT_FLAG_NEW_PACKETS (1 << 1)

    /**
     * Real base framerate of the stream.
     * This is the lowest framerate with which all timestamps can be
     * represented accurately (it is the least common multiple of all
     * framerates in the stream). Note, this value is just a guess!
     * For example, if the time base is 1/90000 and all frames have either
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
     */
    // 流的真实基本帧率
    // 这是所有时间戳可以精确表示的最低帧率(它是流中所有帧率的最小公共倍数)。注意,这个值只是一个猜测
    // 例如,如果基准时间是1/90000,并且所有帧都有大约3600或1800个计时器,那么r_frame_rate将是50/1
    AVRational r_frame_rate;

    /**
     * Number of bits in timestamps. Used for wrapping control.
     *
     * - demuxing: set by libavformat
     * - muxing: set by libavformat
     *
     */
    // 时间戳中的位数。用于包装控制
    int pts_wrap_bits;
} AVStream;

在AVStream之中,存储的比较关键的信息有:

(1)index:AVFormatContext中流的索引号(从这里可见AVFormatContext是包含AVStream的)

(2)id:特定于格式的流ID

(3)AVCodecParameters *codecpar:编解码器的参数

(4)AVRational avg_frame_rate:平均帧率

(5)AVPacketSideData *side_data:附加数据

(6)int event_flags:描述这个流事件的标识符

(7)AVRational r_frame_rate:基于时间基的帧率

由于FFmpeg-7.0当中的AVStream结构体中不再包含AVCodec,换成了AVCodecParameters,下面看看AVCodecParameters之中存储了什么信息

1.1 AVCodecParameters *codecpar

AVCodecParameters中记录的是编码流的一些基本属性,定义位于libavocdec\codec_par.h之中

c 复制代码
/**
 * This struct describes the properties of an encoded stream.
 *
 * sizeof(AVCodecParameters) is not a part of the public ABI, this struct must
 * be allocated with avcodec_parameters_alloc() and freed with
 * avcodec_parameters_free().
 */
// sizeof(AVCodecParameters)不是公共ABI的一部分,这个结构体必须用avcodec_parameters_alloc()分配,
// 并用avcodec_parameters_free()释放
typedef struct AVCodecParameters {
    /**
     * General type of the encoded data.
     */
    // 编码数据的一般类型
    enum AVMediaType codec_type;
    /**
     * Specific type of the encoded data (the codec used).
     */
    // 编码数据的特定类型(使用的编解码器)
    enum AVCodecID   codec_id;
    /**
     * Additional information about the codec (corresponds to the AVI FOURCC).
     */
    // 关于编解码器的附加信息(对应于AVI FOURCC)
    uint32_t         codec_tag;

    /**
     * Extra binary data needed for initializing the decoder, codec-dependent.
     *
     * Must be allocated with av_malloc() and will be freed by
     * avcodec_parameters_free(). The allocated size of extradata must be at
     * least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
     * bytes zeroed.
     */
    // 初始化解码器所需的额外二进制数据,依赖于编解码器
    // 必须由av_malloc()分配,并将由avcodec_parameters_free()释放。
    // 额外数据的分配大小必须至少为extraata_size + AV_INPUT_BUFFER_PADDING_SIZE,填充字节为零
    uint8_t *extradata;
    /**
     * Size of the extradata content in bytes.
     */
    // 额外数据内容的大小,以字节为单位
    int      extradata_size;

    /**
     * Additional data associated with the entire stream.
     *
     * Should be allocated with av_packet_side_data_new() or
     * av_packet_side_data_add(), and will be freed by avcodec_parameters_free().
     */
    // 与整个流相关联的附加数据
    // 应该使用av_packet_side_data_new()或av_packet_side_data_add()分配,并将由avcodec_parameters_free()释放
    AVPacketSideData *coded_side_data;

    /**
     * Amount of entries in @ref coded_side_data.
     */
    // @ref coded_side_data中的条目数量
    int nb_coded_side_data;

    /**
     * - video: the pixel format, the value corresponds to enum AVPixelFormat.
     * - audio: the sample format, the value corresponds to enum AVSampleFormat.
     */
    // 【视频】pixel格式,对应于AVPixelFormat
    // 【音频】采样格式,对应于AVSampleFormat
    int format;

    /**
     * The average bitrate of the encoded data (in bits per second).
     */
    // 编码数据的平均比特率(单位为比特每秒)
    int64_t bit_rate;

    /**
     * The number of bits per sample in the codedwords.
     *
     * This is basically the bitrate per sample. It is mandatory for a bunch of
     * formats to actually decode them. It's the number of bits for one sample in
     * the actual coded bitstream.
     *
     * This could be for example 4 for ADPCM
     * For PCM formats this matches bits_per_raw_sample
     * Can be 0
     */
    // 编码字中每个样本的位数
    // 这基本上是每个样本的比特率。对一堆格式进行实际解码是强制性的。它是实际编码比特流中一个样本的位数
    // 例如,对于ADPCM,这可能是4
	// 对于PCM格式,它匹配bits_per_raw_sample
	// 可以是0
    int bits_per_coded_sample;

    /**
     * This is the number of valid bits in each output sample. If the
     * sample format has more bits, the least significant bits are additional
     * padding bits, which are always 0. Use right shifts to reduce the sample
     * to its actual size. For example, audio formats with 24 bit samples will
     * have bits_per_raw_sample set to 24, and format set to AV_SAMPLE_FMT_S32.
     * To get the original sample use "(int32_t)sample >> 8"."
     *
     * For ADPCM this might be 12 or 16 or similar
     * Can be 0
     */
    // 这是每个输出样本中的有效位数。如果样本格式有更多位,最低有效位是额外的填充位,
    // 它总是0。使用右移来减少样本到其实际大小。例如,具有24位采样的音频格式将
    // bits_per_raw_sample设置为24,并将format设置为AV_SAMPLE_FMT_S32。
    // 要获取原始样本,请使用"(int32_t)sample >> 8
    // 对于ADPCM,这可能是12或16或类似
	// 可以是0
    int bits_per_raw_sample;

    /**
     * Codec-specific bitstream restrictions that the stream conforms to.
     */
    // profile可以是baseline、main或high profile
    int profile;
    // level对应了编解码当中一些限制,例如解码时限制的mb数,解码位宽等等
    int level;

    /**
     * Video only. The dimensions of the video frame in pixels.
     */
    // 【视频】视频帧的宽度和高度
    int width;
    int height;

    /**
     * Video only. The aspect ratio (width / height) which a single pixel
     * should have when displayed.
     *
     * When the aspect ratio is unknown / undefined, the numerator should be
     * set to 0 (the denominator may have any value).
     */
    // 【视频】显示单个像素时应该具有的长宽比(宽度/高度)
    // 当宽高比未知/未定义时,分子应该设置为0(分母可以有任何值)
    AVRational sample_aspect_ratio;

    /**
     * Video only. Number of frames per second, for streams with constant frame
     * durations. Should be set to { 0, 1 } when some frames have differing
     * durations or if the value is not known.
     *
     * @note This field correponds to values that are stored in codec-level
     * headers and is typically overridden by container/transport-layer
     * timestamps, when available. It should thus be used only as a last resort,
     * when no higher-level timing information is available.
     */
    // 【视频】每秒多少帧, 对于具有恒定帧持续时间的流。当某些帧有不同的持续时间或如果值未知时,应该设置为{0,1}吗
    // @note 此字段对应于存储在编解码器级标头中的值,并且通常在可用时被容器/传输层时间戳覆盖
    // 因此,只有在没有更高级别的计时信息时,才应将其作为最后手段使用
    AVRational framerate;

    /**
     * Video only. The order of the fields in interlaced video.
     */
    //【视频】交错视频中字段的顺序
    enum AVFieldOrder                  field_order;

    /**
     * Video only. Additional colorspace characteristics.
     */
    //【视频】额外的colorspace特征
    enum AVColorRange                  color_range;
    enum AVColorPrimaries              color_primaries;
    enum AVColorTransferCharacteristic color_trc;
    enum AVColorSpace                  color_space;
    enum AVChromaLocation              chroma_location;

    /**
     * Video only. Number of delayed frames.
     */
    //【视频】延时帧数量
    int video_delay;

    /**
     * Audio only. The channel layout and number of channels.
     */
    //【音频】声道数
    AVChannelLayout ch_layout;
    /**
     * Audio only. The number of audio samples per second.
     */
    //【音频】每秒音频样本数
    int      sample_rate;
    /**
     * Audio only. The number of bytes per coded audio frame, required by some
     * formats.
     *
     * Corresponds to nBlockAlign in WAVEFORMATEX.
     */
    //【音频】某些格式要求的每个编码音频帧的字节数
    int      block_align;
    /**
     * Audio only. Audio frame size, if known. Required by some formats to be static.
     */
    //【音频】音频帧大小,需要一些格式是确定的
    int      frame_size;

    /**
     * Audio only. The amount of padding (in samples) inserted by the encoder at
     * the beginning of the audio. I.e. this number of leading decoded samples
     * must be discarded by the caller to get the original audio without leading
     * padding.
     */
    // 【音频】编码器在音频开始时插入的填充量(在样本中)
    // 这个数量的前导解码样本必须被调用者丢弃,以获得没有前导填充的原始音频
    int initial_padding;
    /**
     * Audio only. The amount of padding (in samples) appended by the encoder to
     * the end of the audio. I.e. this number of decoded samples must be
     * discarded by the caller from the end of the stream to get the original
     * audio without any trailing padding.
     */
    // 【音频】由编码器附加到音频末尾的填充量(在样本中)。
    // 这个解码样本的数量必须被调用者从流的末尾丢弃,以获得没有任何尾部填充的原始音频
    int trailing_padding;
    /**
     * Audio only. Number of samples to skip after a discontinuity.
     */
    //【音频】不连续后要跳过的样本数
    int seek_preroll;
} AVCodecParameters;

粗略来看,AVCodecParameters之中存储的信息和AVCodecContext之间的关系更像是子集关系,AVCodecParameters只包含部分的变量,例如长宽、格式和帧率等等,AVCodecContext既包含了这些变量,还包含了如qp控制、bitrate控制、硬件编解码等等一系列变量,此外AVCodecContext之中还定义了一些函数指针,如get_format和get_buffer等。在新版本中将编解码器参数和上下文信息隔离开来,应该是不希望在stream这个级别去改变codec的一些操作,关闭这个接口。我对这里的理解是,尽管封装了操作接口和部分变量,但AVStream和AVCodecContext之间的关系应该仍然是一对一的

1.1.1 AVPacketSideData *coded_side_data

c 复制代码
/**
 * This structure stores auxiliary information for decoding, presenting, or
 * otherwise processing the coded stream. It is typically exported by demuxers
 * and encoders and can be fed to decoders and muxers either in a per packet
 * basis, or as global side data (applying to the entire coded stream).
 *
 * Global side data is handled as follows:
 * - During demuxing, it may be exported through
 *   @ref AVStream.codecpar.side_data "AVStream's codec parameters", which can
 *   then be passed as input to decoders through the
 *   @ref AVCodecContext.coded_side_data "decoder context's side data", for
 *   initialization.
 * - For muxing, it can be fed through @ref AVStream.codecpar.side_data
 *   "AVStream's codec parameters", typically  the output of encoders through
 *   the @ref AVCodecContext.coded_side_data "encoder context's side data", for
 *   initialization.
 *
 * Packet specific side data is handled as follows:
 * - During demuxing, it may be exported through @ref AVPacket.side_data
 *   "AVPacket's side data", which can then be passed as input to decoders.
 * - For muxing, it can be fed through @ref AVPacket.side_data "AVPacket's
 *   side data", typically the output of encoders.
 *
 * Different modules may accept or export different types of side data
 * depending on media type and codec. Refer to @ref AVPacketSideDataType for a
 * list of defined types and where they may be found or used.
 */
/*
	1.该结构存储用于解码、表示或以其他方式处理编码流的辅助信息。它通常由解码器和编码器导出,
	可以以每个包为基础馈送到解码器和复用器,也可以作为全局侧数据(适用于整个编码流)
	
	2.全局端数据的处理方法如下:(这里感觉不是很理解?)
	(1)在解复用过程中,可以通过@ref AVStream.codecpar.side_data "AVStream's codec parameters"导出,
	然后可以通过@ref AVCodecContext作为输入传递给解码器,变量名为"decoder context's side data",用于初始化。
	(2)在复用过程中,可以通过@ref AVStream.codecpar "AVStream's codec parameters"提供,
	通常而言,是通过@ref AVCodecContext.coded_side_data "encoder context's side data"进行输入,用于初始化

	3.packet的特定的side data的处理方法如下:
	(1)在解复用过程中,能够通过@ref AVPacket.side_data "AVPacket's side data"进行输出,然后可以将其作为输入传递给解码器
	(2)在复用过程中,能够通过@ref AVPacket.side_data "AVPacket's side data"进行输入,常用于编码器的输出

	4.根据媒体类型和编解码器的不同,不同的模块可以接受或导出不同类型的侧数据
	请参阅@ref AVPacketSideDataType以获得定义类型的列表以及可以找到或使用它们的位置
*/

typedef struct AVPacketSideData {
    uint8_t *data;
    size_t   size;
    enum AVPacketSideDataType type;
} AVPacketSideData;

AVPacketSideDataType的定义如下,具体记录了side data的数据类型

c 复制代码
/**
 * @defgroup lavc_packet_side_data AVPacketSideData
 *
 * Types and functions for working with AVPacketSideData.
 * @{
 */
enum AVPacketSideDataType {
    /**
     * An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE
     * bytes worth of palette. This side data signals that a new palette is
     * present.
     */
    // AV_PKT_DATA_PALETTE端数据包包含了AVPALETTE_SIZE字节值的调色板。这个侧数据表示出现了一个新的调色板
    AV_PKT_DATA_PALETTE,

    /**
     * The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format
     * that the extradata buffer was changed and the receiving side should
     * act upon it appropriately. The new extradata is embedded in the side
     * data buffer and should be immediately used for processing the current
     * frame or packet.
     */
    // AV_PKT_DATA_NEW_EXTRADATA用于通知编解码器或格式外数据缓冲区已更改,接收端应适当地对其采取行动。
    // 新的额外数据被嵌入到侧数据缓冲区中,并应立即用于处理当前帧或包
    AV_PKT_DATA_NEW_EXTRADATA,

    /**
     * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
     * @code
     * u32le param_flags
     * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
     *     s32le channel_count
     * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
     *     u64le channel_layout
     * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
     *     s32le sample_rate
     * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
     *     s32le width
     *     s32le height
     * @endcode
     */
    AV_PKT_DATA_PARAM_CHANGE,
    // ....
}

1.1.2 enum AVColorRange color_range

c 复制代码
/**
 * Visual content value range.
 *
 * These values are based on definitions that can be found in multiple
 * specifications, such as ITU-T BT.709 (3.4 - Quantization of RGB, luminance
 * and colour-difference signals), ITU-T BT.2020 (Table 5 - Digital
 * Representation) as well as ITU-T BT.2100 (Table 9 - Digital 10- and 12-bit
 * integer representation). At the time of writing, the BT.2100 one is
 * recommended, as it also defines the full range representation.
 *
 * Common definitions:
 *   - For RGB and luma planes such as Y in YCbCr and I in ICtCp,
 *     'E' is the original value in range of 0.0 to 1.0.
 *   - For chroma planes such as Cb,Cr and Ct,Cp, 'E' is the original
 *     value in range of -0.5 to 0.5.
 *   - 'n' is the output bit depth.
 *   - For additional definitions such as rounding and clipping to valid n
 *     bit unsigned integer range, please refer to BT.2100 (Table 9).
 */
// 可视内容值范围
// 这些值基于多种规范中的定义,例如ITU-T BT.709 (3.4 - RGB、亮度和色差信号的量化)、ITU-T BT.2020
// (表5 -数字表示)以及ITU-T BT.2100(表9 -数字10位和12位整数表示)。在撰写本文时,推荐使用BT.2100,因为它也定义了全范围表示
// 常用定义:
//(1)对于RGB和亮度分量而言,E为原始值,范围从0.0到1.0
//(2)对于色度分量而言,E为原始值,范围从-0.5到0.5
// n是输出的比特深度
// 具体可参考BT.2100
enum AVColorRange {
    AVCOL_RANGE_UNSPECIFIED = 0,

    /**
     * Narrow or limited range content.
     *
     * - For luma planes:
     *
     *       (219 * E + 16) * 2^(n-8)
     *
     *   F.ex. the range of 16-235 for 8 bits
     *
     * - For chroma planes:
     *
     *       (224 * E + 128) * 2^(n-8)
     *
     *   F.ex. the range of 16-240 for 8 bits
     */
    AVCOL_RANGE_MPEG        = 1,

    /**
     * Full range content.
     *
     * - For RGB and luma planes:
     *
     *       (2^n - 1) * E
     *
     *   F.ex. the range of 0-255 for 8 bits
     *
     * - For chroma planes:
     *
     *       (2^n - 1) * E + 2^(n - 1)
     *
     *   F.ex. the range of 1-255 for 8 bits
     */
    AVCOL_RANGE_JPEG        = 2,
    AVCOL_RANGE_NB               ///< Not part of ABI
};

1.1.3 enum AVColorPrimaries color_primaries

c 复制代码
/**
  * Chromaticity coordinates of the source primaries.
  * These values match the ones defined by ISO/IEC 23091-2_2019 subclause 8.1 and ITU-T H.273.
  */
// 源原色的色度坐标
// 这些值与ISO/IEC 23091-2_2019子条款8.1和ITU-T H.273定义的值相匹配
enum AVColorPrimaries {
    AVCOL_PRI_RESERVED0   = 0,
    AVCOL_PRI_BT709       = 1,  ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
    AVCOL_PRI_UNSPECIFIED = 2,
    AVCOL_PRI_RESERVED    = 3,
    AVCOL_PRI_BT470M      = 4,  ///< also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)

    AVCOL_PRI_BT470BG     = 5,  ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
    AVCOL_PRI_SMPTE170M   = 6,  ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
    AVCOL_PRI_SMPTE240M   = 7,  ///< identical to above, also called "SMPTE C" even though it uses D65
    AVCOL_PRI_FILM        = 8,  ///< colour filters using Illuminant C
    AVCOL_PRI_BT2020      = 9,  ///< ITU-R BT2020
    AVCOL_PRI_SMPTE428    = 10, ///< SMPTE ST 428-1 (CIE 1931 XYZ)
    AVCOL_PRI_SMPTEST428_1 = AVCOL_PRI_SMPTE428,
    AVCOL_PRI_SMPTE431    = 11, ///< SMPTE ST 431-2 (2011) / DCI P3
    AVCOL_PRI_SMPTE432    = 12, ///< SMPTE ST 432-1 (2010) / P3 D65 / Display P3
    AVCOL_PRI_EBU3213     = 22, ///< EBU Tech. 3213-E (nothing there) / one of JEDEC P22 group phosphors
    AVCOL_PRI_JEDEC_P22   = AVCOL_PRI_EBU3213,
    AVCOL_PRI_NB                ///< Not part of ABI
};

1.1.4 enum AVColorTransferCharacteristic color_trc

c 复制代码
/**
 * Color Transfer Characteristic.
 * These values match the ones defined by ISO/IEC 23091-2_2019 subclause 8.2.
 */
// 色彩转移特性
// 这些值与ISO/IEC 23091-2_2019子条款8.2中定义的值相匹配
enum AVColorTransferCharacteristic {
    AVCOL_TRC_RESERVED0    = 0,
    AVCOL_TRC_BT709        = 1,  ///< also ITU-R BT1361
    AVCOL_TRC_UNSPECIFIED  = 2,
    AVCOL_TRC_RESERVED     = 3,
    AVCOL_TRC_GAMMA22      = 4,  ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
    AVCOL_TRC_GAMMA28      = 5,  ///< also ITU-R BT470BG
    AVCOL_TRC_SMPTE170M    = 6,  ///< also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
    AVCOL_TRC_SMPTE240M    = 7,
    AVCOL_TRC_LINEAR       = 8,  ///< "Linear transfer characteristics"
    AVCOL_TRC_LOG          = 9,  ///< "Logarithmic transfer characteristic (100:1 range)"
    AVCOL_TRC_LOG_SQRT     = 10, ///< "Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
    AVCOL_TRC_IEC61966_2_4 = 11, ///< IEC 61966-2-4
    AVCOL_TRC_BT1361_ECG   = 12, ///< ITU-R BT1361 Extended Colour Gamut
    AVCOL_TRC_IEC61966_2_1 = 13, ///< IEC 61966-2-1 (sRGB or sYCC)
    AVCOL_TRC_BT2020_10    = 14, ///< ITU-R BT2020 for 10-bit system
    AVCOL_TRC_BT2020_12    = 15, ///< ITU-R BT2020 for 12-bit system
    AVCOL_TRC_SMPTE2084    = 16, ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems
    AVCOL_TRC_SMPTEST2084  = AVCOL_TRC_SMPTE2084,
    AVCOL_TRC_SMPTE428     = 17, ///< SMPTE ST 428-1
    AVCOL_TRC_SMPTEST428_1 = AVCOL_TRC_SMPTE428,
    AVCOL_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma"
    AVCOL_TRC_NB                 ///< Not part of ABI
};

1.1.5 enum AVColorSpace color_space

c 复制代码
/**
 * YUV colorspace type.
 * These values match the ones defined by ISO/IEC 23091-2_2019 subclause 8.3.
 */
// YUV colorspace的类型
// 这些值与ISO/IEC 23091-2_2019子条款8.3定义的值相匹配
enum AVColorSpace {
    AVCOL_SPC_RGB         = 0,  ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
    AVCOL_SPC_BT709       = 1,  ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
    AVCOL_SPC_UNSPECIFIED = 2,
    AVCOL_SPC_RESERVED    = 3,  ///< reserved for future use by ITU-T and ISO/IEC just like 15-255 are
    AVCOL_SPC_FCC         = 4,  ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
    AVCOL_SPC_BT470BG     = 5,  ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
    AVCOL_SPC_SMPTE170M   = 6,  ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
    AVCOL_SPC_SMPTE240M   = 7,  ///< derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
    AVCOL_SPC_YCGCO       = 8,  ///< used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
    AVCOL_SPC_YCOCG       = AVCOL_SPC_YCGCO,
    AVCOL_SPC_BT2020_NCL  = 9,  ///< ITU-R BT2020 non-constant luminance system
    AVCOL_SPC_BT2020_CL   = 10, ///< ITU-R BT2020 constant luminance system
    AVCOL_SPC_SMPTE2085   = 11, ///< SMPTE 2085, Y'D'zD'x
    AVCOL_SPC_CHROMA_DERIVED_NCL = 12, ///< Chromaticity-derived non-constant luminance system
    AVCOL_SPC_CHROMA_DERIVED_CL = 13, ///< Chromaticity-derived constant luminance system
    AVCOL_SPC_ICTCP       = 14, ///< ITU-R BT.2100-0, ICtCp
    AVCOL_SPC_NB                ///< Not part of ABI
};

1.1.6 enum AVChromaLocation chroma_location

c 复制代码
/**
 * Location of chroma samples.
 *
 * Illustration showing the location of the first (top left) chroma sample of the
 * image, the left shows only luma, the right
 * shows the location of the chroma sample, the 2 could be imagined to overlay
 * each other but are drawn separately due to limitations of ASCII
 *
 *                1st 2nd       1st 2nd horizontal luma sample positions
 *                 v   v         v   v
 *                 ______        ______
 *1st luma line > |X   X ...    |3 4 X ...     X are luma samples,
 *                |             |1 2           1-6 are possible chroma positions
 *2nd luma line > |X   X ...    |5 6 X ...     0 is undefined/unknown position
 */
// 色度样本的位置
// 插图显示图像的第一个(左上)色度样本的位置,左边只显示亮度,右边显示色度样本的位置,
// 可以想象这两个是相互覆盖的,但由于ASCII的限制,它们是分开绘制的
enum AVChromaLocation {
    AVCHROMA_LOC_UNSPECIFIED = 0,
    AVCHROMA_LOC_LEFT        = 1, ///< MPEG-2/4 4:2:0, H.264 default for 4:2:0
    AVCHROMA_LOC_CENTER      = 2, ///< MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0
    AVCHROMA_LOC_TOPLEFT     = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2
    AVCHROMA_LOC_TOP         = 4,
    AVCHROMA_LOC_BOTTOMLEFT  = 5,
    AVCHROMA_LOC_BOTTOM      = 6,
    AVCHROMA_LOC_NB               ///< Not part of ABI
};

1.2.1 enum AVDiscard discard

AVDiscard结构体存在的意义是用于控制编解码过程中的数据丢弃策略,以优化性能或适应于不同的应用场景

c 复制代码
/**
 * @ingroup lavc_decoding
 */
enum AVDiscard{
    /* We leave some space between them for extensions (drop some
     * keyframes for intra-only or drop just some bidir frames). */
    AVDISCARD_NONE    =-16, ///< discard nothing
    AVDISCARD_DEFAULT =  0, ///< discard useless packets like 0 size packets in avi
    AVDISCARD_NONREF  =  8, ///< discard all non reference
    AVDISCARD_BIDIR   = 16, ///< discard all bidirectional frames
    AVDISCARD_NONINTRA= 24, ///< discard all non intra frames
    AVDISCARD_NONKEY  = 32, ///< discard all frames except keyframes
    AVDISCARD_ALL     = 48, ///< discard all
};

CSDN : https://blog.csdn.net/weixin_42877471
Github : https://github.com/DoFulangChen

相关推荐
低调包含17 分钟前
RT-Thread和freeRTOS启动流程
c语言·arm开发·rtos
2401_8582861126 分钟前
12.【C语言】创建函数
c语言·开发语言·数据结构
Star Patrick28 分钟前
*算法训练(leetcode)第二十天 | 39. 组合总和、40. 组合总和 II、131. 分割回文串
c++·算法·leetcode
小程序面包园41 分钟前
Python函数缺省参数的 “ 坑 ” (与C++对比学习)
开发语言·c++·python·学习
菜鸟赵大宝1 小时前
Visual Studio编译优化选项
c++·visual studio
北岛寒沫1 小时前
算法刷题笔记 单调栈(C++实现)
c++·笔记·算法
一条闲鱼。1 小时前
C++ 文件读写
c++·读写文件
imred1 小时前
C++:std::function的libc++实现
c++·stl·template·function·libc++
jzwalliser1 小时前
洛谷 P1035 [NOIP2002 普及组] 级数求和
c++·python·算法
汀小烟2 小时前
使用静态成员函数统计学生平均成绩
c语言·开发语言·数据结构·c++·vscode