ffmpeg avformat

您所在的位置:网站首页 打开视频文件失败怎么回事 ffmpeg avformat

ffmpeg avformat

2024-07-16 06:29| 来源: 网络整理| 查看: 265

用ffmpeg做的第一个程序,参考网上的代码,就出现了一些问题,其中avformat_open_input返回失败。 下面是我在网上收集到的失败信息的相关解决: 很多朋友在使用新版本的ffmpeg时,都遇到了avformat_open_input返回失败的问题。 在下也遇到了此问题。在stackoverflow上搜了一下,解决方法如下。 在调用avformat_open_input之前,先调用如下接口初始化一下即可。 av_register_all(); 这算是新版本ffmpeg代码流程的一个变化了。  老版本的ffmpeg,代码流程如下: avcodec_register_all(); av_open_input_file(&pFormatCtx, "/path/to/video/file",  NULL,  0,  NULL);  而新版本中,代码流程如下: av_register_all(); avformat_open_input(&pFormatCtx, "/path/to/video/file", NULL, NULL);  最后,我们要使用ffmpeg的过程中,遇到返回值失败时,可以尝试将失败原因打印出来。 方法如下: if( err_code=avformat_open_input(&pFormatCtx, test_file, NULL, NULL) ) {     av_strerror(err_code, buf, 1024);     printf("Couldn't open file %s: %d(%s)", test_file, err_code, buf);     return -1;  } 最后再列几个变化了的接口: 老版本: avcodec_open avcodec_decode_video img_convert   新版本: avcodec_open2 avcodec_decode_video2 sws_scale   而我真正的解决方法是,打印出来的信息显示,avformat_open_input函数返回-2;然后我查看了下-2信息的错误原因是no file or directory 所以我再想,难道文件名不对?然后仔细的查看了下,不是的,但为什么按f5调试,还是会失败,后面才知道,原来是因为我需要打开的视频文件存的位置不对,test.mp4文件应该放在和.cpp一起的,而我放在了debug目录下,所以不行,打不开。 转自:http://www.cnblogs.com/lihaiping/p/return-2.html



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3