我正在尝试使用ffmpeg c ++读取编码视频。当我尝试构建我的代码时出现错误,因为标识符选项未定义。但它已被定义为AVDictionary *options = NULL
。
我的代码出了什么问题?
void CFfmpegmethods::VideoRead(){
const char *url = "H:/Sanduni_projects/ad_2.mp4";
AVFormatContext *s = NULL;
int ret = avformat_open_input(&s, url, NULL, NULL);
if (ret < 0)
abort();
avformat_find_stream_info(s, &options);
AVDictionary *options = NULL;
av_dict_set(&options, "video_size", "640x480", 0);
av_dict_set(&options, "pixel_format", "rgb24", 0);
if (avformat_open_input(&s, url, NULL, &options) < 0){
abort();
}
av_dict_free(&options);
AVDictionaryEntry *e;
if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key);
abort();
}
avformat_close_input(&s);
}
答案 0 :(得分:0)
评论about()
会将options
变量的声明纳入if
的范围,因此您的代码会执行此操作:
if (ret < 0)
{
//abort();
AVDictionary *options = NULL;
}
最好在分支后开始新的{}以避免此类问题:
if (ret < 0)
{
//abort(); // now commenting this line does not make scope to change
}
AVDictionary *options = NULL;
答案 1 :(得分:0)
问题解决了。我忘了在开头添加av_register_all()。