2.AVFormatContext和AVInputFormat

參考https://blog.csdn.net/leixiaohua1020/article/details/14214705數組

 

AVFormatContext: 用來存儲視音頻封裝格式(flv,mp4,rmvb,avi)中包含的全部信息 不少函數都要用到它做爲參數。ide

AVFormatContext結構體以下所示(顯示部分紅員,後續深刻添加):函數

typedef struct AVFormatContext {
    
    const AVClass *av_class;    //包含AVCodecContext, AVFormatContext 

    /**
     * The input container format.
     *
     * Demuxing only, set by avformat_open_input().
     */
    ff_const59 struct AVInputFormat *iformat;        //AVInputFormat:封裝格式(flv、mkv、avi等),調用avformat_open_input()時,該成員就會被初始化

  
    ff_const59 struct AVOutputFormat *oformat;    //輸入的封裝格式(生成視頻),調用avformat_write_header()時,該成員就會被初始化

   
    unsigned int nb_streams;  //AVFormatContext中的流個數,通常爲2,若是要設置,則只能經過avformat_new_stream()來設置

    AVStream **streams;        //輸入視頻的AVStream流數組,經過avformat_open_input()來初始化流信息

#if FF_API_FORMAT_FILENAME
    
    attribute_deprecated
    char filename[1024];        //輸入輸出文件名路徑,經過avformat_open_input()和avformat_write_header()來設置
#endif

   
    char *url;        //輸入或輸出URL,與filename字段不一樣,此字段沒有長度限制。經過avformat_open_input()和avformat_write_header()來設置

    /**
     * Position of the first frame of the component, in
     * AV_TIME_BASE fractional seconds. NEVER set this value directly:
     * It is deduced from the AVStream values.
     *
     * Demuxing only, set by libavformat.
     */
    int64_t start_time;        //第一幀的時間位置,通常爲0


    int64_t duration;        //輸入視頻總時長,以微妙爲單位,換算以秒爲單位: duration/AV_TIME_BASE

    /**
     * Total stream bitrate in bit/s, 0 if not
     * available. Never set it directly if the file_size and the
     * duration are known as FFmpeg can compute it automatically.
     */
    int64_t bit_rate;        //輸入視頻的碼率,單位爲bit/s

    unsigned int packet_size;
    int max_delay;


    const uint8_t *key;
    int keylen;

    unsigned int nb_programs;
    AVProgram **programs;

    enum AVCodecID video_codec_id; //須要強制設置的視頻編碼id,默認爲0,自動設置

  
    enum AVCodecID audio_codec_id;        //須要強制設置的音頻編碼id,默認爲0,自動設置

  
    enum AVCodecID subtitle_codec_id;//須要強制設置的字幕編碼id,默認爲0,自動設置

    
    AVDictionary *metadata;        //整個文件的元數據,能夠經過經過av_dict_get()函數得到視頻的原數據,AVDictionary包含兩個成員key和value
    //使用循環讀出
        //(須要讀取的數據,字段名稱,前一條字段(循環時使用),參數)
    //while(m=av_dict_get(pFormatCtx->metadata,"",m,AV_DICT_IGNORE_SUFFIX)){
    //    key.Format(m->key);
    //    value.Format(m->value);
    //    qDebug()<<"key-value:"<<key<<"\t:"+value+"\r\n" ;
    //}

   
    int64_t start_time_realtime;    //流的實際啓動時間,以微秒爲單位

    int probe_score;        //格式探測得分,100是最大的分數,這意味着FFmpeg確信格式是真實的

  
    AVCodec *video_codec;        //用戶設置的強制視頻解碼器,若是用戶未設置,就爲NULL

    AVCodec *audio_codec;        //用戶設置的強制音頻解碼器

    AVCodec *subtitle_codec; //用戶設置的強制字幕解碼器

   ... ...
} AVFormatContext;

 其中iformat成員就是指向視頻/音頻流的封裝格式(flv、mkv、avi等)具體結構體的指針.ui

該成員的AVInputFormat結構體以下所示(顯示部分紅員,後續深刻添加):this

typedef struct AVInputFormat
{

const char *name; // 封裝格式的名字, 好比,「mov」 「mp4」 等。

const char *long_name;    ///封裝格式的長名字
//標示具體的format對應的Context 的size,如:MovContext。

const char *extensions;    //擴展名,若是定義了, 則不執行探測視頻格式, 一般不使用擴展格式猜想,由於不可靠
//具體的操做函數 int(*read_probe)(AVProbeData*); int(*read_header)(struct AVFormatContext *,AVFormatParameters *ap); int(*read_packet)(struct AVFormatContext *, AVPacket *pkt); int(*read_close)(struct AVFormatContext*); struct AVInputFormat *next; } AVInputFormat
相關文章
相關標籤/搜索