FFmpeg結(jié)構(gòu)體:AVStream

1.描述

AVStream是存儲每一個視頻/音頻流信息的結(jié)構(gòu)體声邦,位于avformat.h文件中乏奥。

2.結(jié)構(gòu)體定義

typedef struct AVStream {
    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
     */
    int id;
#if FF_API_LAVF_AVCTX
    /**
     * @deprecated use the codecpar struct instead
     */
    attribute_deprecated
    AVCodecContext *codec;
#endif
    void *priv_data;

#if FF_API_LAVF_FRAC
    /**
     * @deprecated this field is unused
     */
    attribute_deprecated
    struct AVFrac pts;
#endif

    /**
     * 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).
     */
    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
     *
     * - 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
     */
    AVPacket attached_pic;

    /**
     * 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().
     *
     * @see av_format_inject_global_side_data()
     */
    AVPacketSideData *side_data;
    /**
     * The number of elements in the AVStream.side_data array.
     */
    int            nb_side_data;

    /**
     * Flags for the user to detect events happening on the stream. Flags must
     * be cleared by the user once the event has been handled.
     * A combination of AVSTREAM_EVENT_FLAG_*.
     */
    int event_flags;
#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001 ///< The call resulted in updated metadata.

    /*
     * 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()
     */
    AVCodecParameters *codecpar;

    /*****************************************************************
     * 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 (30*12+30+3+6)
    struct {
        int64_t last_dts;
        int64_t duration_gcd;
        int duration_count;
        int64_t rfps_duration_sum;
        double (*duration_error)[2][MAX_STD_TIMEBASES];
        int64_t codec_info_duration;
        int64_t codec_info_duration_fields;

        /**
         * 0  -> decoder has not been searched for yet.
         * >0 -> decoder found
         * <0 -> decoder with codec_id == -found_decoder has not been found
         */
        int found_decoder;

        int64_t last_duration;

        /**
         * Those are used for average framerate estimation.
         */
        int64_t fps_first_dts;
        int     fps_first_dts_idx;
        int64_t fps_last_dts;
        int     fps_last_dts_idx;

    } *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 first_dts;
    int64_t cur_dts;
    int64_t last_IP_pts;
    int last_IP_duration;

    /**
     * Number of packets to buffer for codec probing
     */
    int probe_packets;

    /**
     * Number of frames that have been demuxed during av_find_stream_info()
     */
    int codec_info_nb_frames;

    /* 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;

    /**
     * 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.
     *
     * Code outside avformat should access this field using:
     * av_stream_get/set_r_frame_rate(stream)
     */
    AVRational r_frame_rate;

    /**
     * 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;

    /**
     * stream probing state
     * -1   -> probing finished
     *  0   -> no probing requested
     * rest -> perform probing with request_probe being the minimum score to accept.
     * NOT PART OF PUBLIC API
     */
    int request_probe;
    /**
     * Indicates that everything up to the next keyframe
     * should be discarded.
     */
    int skip_to_keyframe;

    /**
     * Number of samples to skip at the start of the frame decoded from the next packet.
     */
    int skip_samples;

    /**
     * If not 0, the number of samples that should be skipped from the start of
     * the stream (the samples are removed from packets with pts==0, which also
     * assumes negative timestamps do not happen).
     * Intended for use with formats such as mp3 with ad-hoc gapless audio
     * support.
     */
    int64_t start_skip_samples;

    /**
     * If not 0, the first audio sample that should be discarded from the stream.
     * This is broken by design (needs global sample count), but can't be
     * avoided for broken by design formats such as mp3 with ad-hoc gapless
     * audio support.
     */
    int64_t first_discard_sample;

    /**
     * The sample after last sample that is intended to be discarded after
     * first_discard_sample. Works on frame boundaries only. Used to prevent
     * early EOF if the gapless info is broken (considered concatenated mp3s).
     */
    int64_t last_discard_sample;

    /**
     * Number of internally decoded frames, used internally in libavformat, do not access
     * its lifetime differs from info which is why it is not in that structure.
     */
    int nb_decoded_frames;

    /**
     * Timestamp offset added to timestamps before muxing
     * NOT PART OF PUBLIC API
     */
    int64_t mux_ts_offset;

    /**
     * Internal data to check for wrapping of the time stamp
     */
    int64_t pts_wrap_reference;

    /**
     * Options for behavior, when a wrap is detected.
     *
     * Defined by AV_PTS_WRAP_ values.
     *
     * If correction is enabled, there are two possibilities:
     * If the first time stamp is near the wrap point, the wrap offset
     * will be subtracted, which will create negative time stamps.
     * Otherwise the offset will be added.
     */
    int pts_wrap_behavior;

    /**
     * Internal data to prevent doing update_initial_durations() twice
     */
    int update_initial_durations_done;

    /**
     * Internal data to generate dts from pts
     */
    int64_t pts_reorder_error[MAX_REORDER_DELAY+1];
    uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1];

    /**
     * Internal data to analyze DTS and detect faulty mpeg streams
     */
    int64_t last_dts_for_order_check;
    uint8_t dts_ordered;
    uint8_t dts_misordered;

    /**
     * Internal data to inject global side data
     */
    int inject_global_side_data;

    /**
     * String containing paris of key and values describing recommended encoder configuration.
     * Paris are separated by ','.
     * Keys are separated from values by '='.
     */
    char *recommended_encoder_configuration;

    /**
     * display aspect ratio (0 if unknown)
     * - encoding: unused
     * - decoding: Set by libavformat to calculate sample_aspect_ratio internally
     */
    AVRational display_aspect_ratio;

    struct FFFrac *priv_pts;

    /**
     * An opaque field for libavformat internal usage.
     * Must not be accessed in any way by callers.
     */
    AVStreamInternal *internal;
} AVStream;

3.常見變量及其作用

int index; //在AVFormatContext中的索引,這個數(shù)字是自動生成的亥曹,可以通過這個數(shù)字從AVFormatContext::streams表中索引到該流邓了。
int id;//流的標(biāo)識,依賴于具體的容器格式媳瞪。解碼:由libavformat設(shè)置骗炉。編碼:由用戶設(shè)置,如果未設(shè)置則由libavformat替換蛇受。
AVCodecContext *codec;//指向該流對應(yīng)的AVCodecContext結(jié)構(gòu)句葵,調(diào)用avformat_open_input時生成。
AVRational time_base;//這是表示幀時間戳的基本時間單位(以秒為單位)。該流中媒體數(shù)據(jù)的pts和dts都將以這個時間基準(zhǔn)為粒度乍丈。
int64_t start_time;//流的起始時間熊响,以流的時間基準(zhǔn)為單位。如需設(shè)置诗赌,100%確保你設(shè)置它的值真的是第一幀的pts汗茄。
int64_t duration;//解碼:流的持續(xù)時間。如果源文件未指定持續(xù)時間铭若,但指定了比特率洪碳,則將根據(jù)比特率和文件大小估計該值。
int64_t nb_frames; //此流中的幀數(shù)(如果已知)或0叼屠。
enum AVDiscard discard;//選擇哪些數(shù)據(jù)包可以隨意丟棄瞳腌,不需要去demux。
AVRational sample_aspect_ratio;//樣本長寬比(如果未知镜雨,則為0)嫂侍。
AVDictionary *metadata;//元數(shù)據(jù)信息。
AVRational avg_frame_rate;//平均幀速率荚坞。解封裝:可以在創(chuàng)建流時設(shè)置為libavformat挑宠,也可以在avformat_find_stream_info()中設(shè)置。封裝:可以由調(diào)用者在avformat_write_header()之前設(shè)置颓影。
AVPacket attached_pic;//附帶的圖片各淀。比如說一些MP3,AAC音頻文件附帶的專輯封面诡挂。
int probe_packets;//編解碼器用于probe的包的個數(shù)碎浇。
int codec_info_nb_frames;//在av_find_stream_info()期間已經(jīng)解封裝的幀數(shù)。
int request_probe;//流探測狀態(tài)璃俗,1表示探測完成奴璃,0表示沒有探測請求,rest 執(zhí)行探測城豁。
int skip_to_keyframe;//表示應(yīng)丟棄直到下一個關(guān)鍵幀的所有內(nèi)容苟穆。
int skip_samples;//在從下一個數(shù)據(jù)包解碼的幀開始時要跳過的采樣數(shù)。
int64_t start_skip_samples;//如果不是0钮蛛,則應(yīng)該從流的開始跳過的采樣的數(shù)目鞭缭。
int64_t first_discard_sample;//如果不是0,則應(yīng)該從流中丟棄第一個音頻樣本魏颓。

int64_t pts_reorder_error[MAX_REORDER_DELAY+1];
uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1];//內(nèi)部數(shù)據(jù)岭辣,從pts生成dts。

int64_t last_dts_for_order_check;
uint8_t dts_ordered;
uint8_t dts_misordered;//內(nèi)部數(shù)據(jù),用于分析dts和檢測故障mpeg流。
AVRational display_aspect_ratio;//顯示寬高比琅翻。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末司忱,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子未檩,更是在濱河造成了極大的恐慌售滤,老刑警劉巖收苏,帶你破解...
    沈念sama閱讀 221,273評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件氏豌,死亡現(xiàn)場離奇詭異喉酌,居然都是意外死亡,警方通過查閱死者的電腦和手機泵喘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,349評論 3 398
  • 文/潘曉璐 我一進店門泪电,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人纪铺,你說我怎么就攤上這事相速。” “怎么了鲜锚?”我有些...
    開封第一講書人閱讀 167,709評論 0 360
  • 文/不壞的土叔 我叫張陵突诬,是天一觀的道長。 經(jīng)常有香客問我芜繁,道長旺隙,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,520評論 1 296
  • 正文 為了忘掉前任浆洗,我火速辦了婚禮催束,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘伏社。我一直安慰自己,他們只是感情好塔淤,可當(dāng)我...
    茶點故事閱讀 68,515評論 6 397
  • 文/花漫 我一把揭開白布摘昌。 她就那樣靜靜地躺著,像睡著了一般高蜂。 火紅的嫁衣襯著肌膚如雪聪黎。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,158評論 1 308
  • 那天备恤,我揣著相機與錄音稿饰,去河邊找鬼。 笑死露泊,一個胖子當(dāng)著我的面吹牛喉镰,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播惭笑,決...
    沈念sama閱讀 40,755評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼侣姆,長吁一口氣:“原來是場噩夢啊……” “哼生真!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起捺宗,我...
    開封第一講書人閱讀 39,660評論 0 276
  • 序言:老撾萬榮一對情侶失蹤柱蟀,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蚜厉,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體长已,經(jīng)...
    沈念sama閱讀 46,203評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,287評論 3 340
  • 正文 我和宋清朗相戀三年昼牛,在試婚紗的時候發(fā)現(xiàn)自己被綠了术瓮。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,427評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡匾嘱,死狀恐怖斤斧,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情霎烙,我是刑警寧澤撬讽,帶...
    沈念sama閱讀 36,122評論 5 349
  • 正文 年R本政府宣布,位于F島的核電站悬垃,受9級特大地震影響游昼,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜尝蠕,卻給世界環(huán)境...
    茶點故事閱讀 41,801評論 3 333
  • 文/蒙蒙 一烘豌、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧看彼,春花似錦廊佩、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,272評論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至茁计,卻和暖如春料皇,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背星压。 一陣腳步聲響...
    開封第一講書人閱讀 33,393評論 1 272
  • 我被黑心中介騙來泰國打工践剂, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人娜膘。 一個月前我還...
    沈念sama閱讀 48,808評論 3 376
  • 正文 我出身青樓逊脯,卻偏偏與公主長得像,于是被迫代替她去往敵國和親劲绪。 傳聞我的和親對象是個殘疾皇子男窟,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,440評論 2 359

推薦閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫盆赤、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,117評論 4 61
  • 教程一:視頻截圖(Tutorial 01: Making Screencaps) 首先我們需要了解視頻文件的一些基...
    90后的思維閱讀 4,705評論 0 3
  • 這兩天歉眷,全國各地高考分?jǐn)?shù)陸續(xù)出來了牺六,愛人侄女也是高考生,由于在老家汗捡,資訊不發(fā)達淑际,將所有考試信息早早發(fā)給愛人,讓他全...
    無憂_cee1閱讀 1,664評論 2 2
  • 小時候扇住,放學(xué)春缕,沿瑞金一路走到淮海中路,經(jīng)過三聯(lián)書店艘蹋,進去逛一圈锄贼,出店門右轉(zhuǎn),回到爺爺家女阀,寫作業(yè)宅荤,看電視,等爸爸下班...
    香皂與長帆閱讀 149評論 0 1
  • “在原由基礎(chǔ)上推進一小步浸策,是容易的冯键, 千萬別將自己推進“不可能”的深淵∮购梗” 什么是平板支撐惫确?相信大部分人都不陌...
    陳小邪a一枚幼兒教育工作者閱讀 2,733評論 0 2