AVStream(avformat.h)

不会笑的孩子發表於2024-03-09

AVStream是儲存每一個影片/音訊資訊的結構體。

/**
 * 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*.
 */
typedef struct AVStream {
    int index;    /**< stream index in AVFormatContext */
    /**
     * Format-specific stream ID.
     * decoding: set by libavformat
     * encoding: set by the user
     */
    int id;
    AVCodecContext *codec; /**< codec context */
    /**
     * 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.
     */
    AVRational r_frame_rate;
    void *priv_data;
 
    /**
     * encoding: pts generation when outputting stream
     */
    struct AVFrac pts;
 
    /**
     * This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented. For fixed-fps content,
     * time base should be 1/framerate and timestamp increments should be 1.
     * decoding: set by libavformat
     * encoding: set by libavformat in av_write_header
     */
    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.
     */
    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.
     */
    int64_t duration;
 
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
 
    int disposition; /**< AV_DISPOSITION_* bit field */
 
    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.
     */
    AVRational sample_aspect_ratio;
 
    AVDictionary *metadata;
 
    /**
     * Average framerate
     */
    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
     */
    AVPacket attached_pic;
 
    /*****************************************************************
     * All fields below this line are not part of the public API. They
     * may not be used outside of libavformat and can be changed and
     * removed at will.
     * New public fields should be added right above.
     *****************************************************************
     */
 
    /**
     * Stream information used internally by av_find_stream_info()
     */
#define MAX_STD_TIMEBASES (60*12+5)
    struct {
        int64_t last_dts;
        int64_t duration_gcd;
        int duration_count;
        double duration_error[2][2][MAX_STD_TIMEBASES];
        int64_t codec_info_duration;
        int nb_decoded_frames;
        int found_decoder;
    } *info;
 
    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
 
    // Timestamp generation support:
    /**
     * Timestamp corresponding to the last dts sync point.
     *
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
     * a DTS is received from the underlying container. Otherwise set to
     * AV_NOPTS_VALUE by default.
     */
    int64_t reference_dts;
    int64_t first_dts;
    int64_t cur_dts;
    int64_t last_IP_pts;
    int last_IP_duration;
 
    /**
     * Number of packets to buffer for codec probing
     */
#define MAX_PROBE_PACKETS 2500
    int probe_packets;
 
    /**
     * Number of frames that have been demuxed during av_find_stream_info()
     */
    int codec_info_nb_frames;
 
    /**
     * Stream Identifier
     * This is the MPEG-TS stream identifier +1
     * 0 means unknown
     */
    int stream_identifier;
 
    int64_t interleaver_chunk_size;
    int64_t interleaver_chunk_duration;
 
    /* av_read_frame() support */
    enum AVStreamParseType need_parsing;
    struct AVCodecParserContext *parser;
 
    /**
     * last packet in packet_buffer for this stream when muxing.
     */
    struct AVPacketList *last_in_packet_buffer;
    AVProbeData probe_data;
#define MAX_REORDER_DELAY 16
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
 
    AVIndexEntry *index_entries; /**< Only used if the format does not
                                    support seeking natively. */
    int nb_index_entries;
    unsigned int index_entries_allocated_size;
 
    /**
     * flag to indicate that probing is requested
     * NOT PART OF PUBLIC API
     */
    int request_probe;
} AVStream;

AVStream重要的變數如下所示:

int index:標識該影片/音訊流在AVFormatContext中的索引。
int id:表示流的格式特定ID。在解碼時由libavformat設定,在編碼時由使用者設定 
codec (ACCodecContext指標):指向編解碼器上下文的指標。
r_frame_rate(AVRational):流的實際基礎幀率。這是能夠準確表示所有時間戳的最低幀率。
priv_data(void指標):私有資料指標。
pts(AVFrac結構體):用於輸出流時的PTS生成。
time_base(AVRational):表示時間戳的基本單位(以秒為單位)。解碼時由libavformat設定,在av_write_header中由libavformat設定。
start_time(int64_t):流的第一幀在呈現順序中的PTS(演示時間基準)
duration(int64_t):流的持續時間,以流時間基準表示。
nb_frames(int64_t):如果已知,表示流中的幀數。
disposition(int):AV_DISPOSITION_*位欄位,表示流的性質。
discard(AVDiscard列舉):選擇可以隨意丟棄的資料包。
sample_aspect_ratio(AVRational):樣本寬高比。
metadata(AVDictionary指標):後設資料。
avg_frame_rate(AVRational):平均幀率
attached_pic(AVPacket):用於具有AV_DISPOSITION_ATTACHED_PIC性質的流中的附加圖片。
info(內部使用結構體):內部結構,用於av__find_stream_info()。
pts_wrap_bits(int):PTS位數。
reference_dts,first_dts,cur——dts,last——IP_pts,last_IP_duration(int64_t型別)時間戳生成支援相關。
probe_packets(int):用於編解碼器探測的資料包流量。
codec_info_nb_frames:在av_find_stream_info()期間解混的幀數。
stream_identifier:流識別符號
interleaver_chunk_size,interleaver_chunk_duration:交錯塊大小和持續時間。
need_parsing(AVStreamParseType列舉):av_read_frame()支援相關。
parser(AVCodecParserContext指標):解析器。
last_in_packet_buffer(AVPacketList指標):用於複用時流的最後一個包。
probe_data:探測資料。
pts_buffer:PTS緩衝區。
index_entries:僅在格式不支援本地定址時使用。
nb_index_entries:索引條目數。
index_entries_allocated_size(unsigned int):分配給索引條目的記憶體大小。
request_probe(int):指示是否請求探測的標誌。

以上的欄位用於描述音影片流的各種屬性和後設資料,以便在處理和解碼音影片檔案時進行有效的管理和操作。