如何使用ffmpeg强制使用特定的编解码器?

时间:2013-09-04 07:21:09

标签: c++ video ffmpeg

我正在尝试使用ffmpeg读取某个视频文件,并且遇到了一些麻烦。

这是开始阅读它的代码:

int _tmain(int argc, _TCHAR* argv[])
{
    if (argc < 2)
    {
        fprintf( stderr, "Filename is needed as an argument\n" );  
        return 1;  
    }
    /* register all formats and codecs */
    av_register_all();
    AVFormatContext* fmt_ctx = NULL;
    /* open input file, and allocate format context */
    const char *src_filename = argv[1];
    if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) {
        fprintf(stderr, "Could not open source file %s\n", src_filename);
        abort();
    }
    /* retrieve stream information */
    AVDictionary *      options;
    int res = avformat_find_stream_info(fmt_ctx, &options);
    if (res < 0) {
        fprintf(stderr, "Could not find stream information\n");
        abort();
    }
    ...
}

我一直收到以下消息:

  

[avi @ 005f2fe0]无法找到流0的编解码器参数(视频:   无(GRAY / 0x59455247),1280x1024):未知的编解码器

     

考虑增加'analyzeuration'和'probesize'选项的值

当我在同一个文件上运行ffmpeg工具时,我收到相同的消息。

然而,我知道视频流中的内容 - 具有YUV8格式的原始视频数据。事实上,当我通过-c:v rawvideo选项将其传递给ffmpeg时,没有问题。重新编码,转换等 - ffmpeg就像它的神奇工具一样。

现在,问题是:当使用ffmpeg api时,该选项的等价物是什么?我迫切需要访问文件框架。

1 个答案:

答案 0 :(得分:0)

您可以尝试将avformat_find_stream_info中的第二个参数传递为NULL。由于流信息读取少量数据包以获取有关文件中存在的流的一些信息。此消息也不会妨碍您的解码。如果您打算稍后解码数据包,这应该没问题。 要进行解码,您需要调用avcodec_find_decoder和avcodec_open2()。