ffmpeg分析系列之四(探測輸入的格式)

調用av_open_input_file(&pFormatCtx, is->filename, NULL, 0, NULL)函數打開輸入的文件.

1. 分析一下函數原型:
int av_open_input_file(AVFormatContext **ic_ptr, // 輸出參數: 格式上下文
                       const char *filename, // 文件名
                       AVInputFormat *fmt, // 輸入的格式, 爲NULL, 即未知
                       int buf_size, // 緩衝的大小, 爲0
                       AVFormatParameters *ap); // 格式的參數, 爲NULL


2. 初始化探測數據:
    AVProbeData probe_data, *pd = &probe_data;

    pd->filename = "";
    if (filename)
        pd->filename = filename;
    pd->buf = NULL;
    pd->buf_size = 0;

3. 探測輸入的格式:
    if (!fmt) { // fmt == NULL, 成立
        fmt = av_probe_input_format(pd, 0);
    }

    進入av_probe_input_format函數:
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened) {
    int score=0;
    return av_probe_input_format2(pd, is_opened, &score);
}

    進入av_probe_input_format2函數:
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
{
    AVInputFormat *fmt1, *fmt;
    int score;

    fmt = NULL;
    for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) {
        if (!is_opened == !(fmt1->flags & AVFMT_NOFILE)) // is_opened == 0, fmt1->flags 沒有設置 AVFMT_NOFILE 標誌時成立
            continue; 
    /* 省略部分代碼 */
}

    見libavformat/raw.c文件:
AVInputFormat h264_demuxer = {
    "h264",
    NULL_IF_CONFIG_SMALL("raw H.264 video format"),
    0,
    h264_probe,
    video_read_header,
    ff_raw_read_partial_packet,
    .flags= AVFMT_GENERIC_INDEX,
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
    .value = CODEC_ID_H264,
};
    由於 h264_demuxer.flags == AVFMT_GENERIC_INDEX, 所以上面成立, continue, 返回的 AVInputFormat 指針爲 NULL, 探測不成功.
發佈了15 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章