前言
ffmpeg 中 avformat_open_input 为打开文件.在很多情况我们都有可能遇到打开文件失败.如 封装MP4有可能失败. 打开h.264 or h.265 的裸码流文件有可能失败.还有打开MP4文件时.
得知 avformat_open_input return : 0 为打开成功的.那失败了呢?
我们直接用av_err2str 来查看错误原因
//[2]打开文件 avformat_open_input()
int result = avformat_open_input(&pFormatCtx, [filePath UTF8String], NULL, NULL);
if (result != 0) {
NSLog(@"无法打开文件:%d %s",result,av_err2str(result));
ifree = YES;
goto end;
}
无法打开文件:-1028739847 Invalida data found when processing input
这样子情况似乎有很多种...
最后为了解决无法打开文件的问题直接草草的用了以下代码
AVInputFormat* iformat=av_find_input_format("h264");
//[2]打开文件 avformat_open_input()
int result = avformat_open_input(&pFormatCtx, [filePath UTF8String], iformat, NULL);
if (result != 0) {
NSLog(@"无法打开文件:%d %s",result,av_err2str(result));
ifree = YES;
goto end;
}
前提是你得知道你的问题编码类型为h.264 而不是h.265
关于这个提示 Invalida data found when processing input 大神看见了希望能解答一下哈谢谢啦