2.AVFormatContext和AVInputFormat


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

 

AVFormatContext: 用來存儲視音頻封裝格式(flv,mp4,rmvb,avi)中包含的所有信息 很多函數都要用到它作為參數。

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;        //所有的總時長(如果要切進度,最好還是用AVStreams里的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等)具體結構體的指針.

該成員的AVInputFormat結構體如下所示(顯示部分成員,后續深入添加):

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM