gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 23:30:06 27 4
gpt4 key购买 nike

我正在尝试使用 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] Could not find codec parameters for stream 0 (Video: none (GREY / 0x59455247), 1280x1024): unknown codec

Consider increasing the value for the 'analyzeduration' and 'probesize' options



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

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

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

最佳答案

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

关于c++ - 如何强制使用 ffmpeg 的特定编解码器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18607737/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com