2012-03-29 184 views
1

这段代码有什么问题?它在av_find_stream_info处中断(访问冲突)。在调试时,ctx-> filename是“3”而不是“1.MP3”:前4个字符被忽略,也检查其他文件,结果相同。C++ ffmpeg访问冲突

av_register_all(); 
AVFormatContext *ctx=0; 
ctx=avformat_alloc_context(); 
avformat_open_input(&ctx,"1.MP3",0,0); 
av_find_stream_info(ctx); 
int istream; 
for(int i=0;i<ctx->nb_streams;i++){ 
if(ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO){ 
     istream=i; 
     break; 
} 
+1

您将永远无法调试不包含错误检查的代码。 'avformat_open_input'的返回值是什么? – 2012-03-29 09:57:02

+2

avformat_open_input返回-2。 – user1288043 2012-03-29 10:11:11

回答

4

avformat_open_input失败。使用av_strerror找出为什么avformat_open_input不合格。由avformat_open_input返回的负值表示错误情况。

+0

av_strerror正在执行访问冲突。 – user1288043 2012-03-29 10:50:17

+1

您需要显示该代码。 – JimR 2012-03-29 10:56:00

1

您的代码包含一个错误 - 即使avformat_open_input失败,它也会调用av_find_stream_info

-2可能是-ENOENT - 没有这样的文件或目录。也许你在错误的目录中。也许该文件的名称是1.mp3,而不是1.MP3,并且您的文件系统区分大小写。

但是,您不能调试不检查错误的代码。

+0

将完整路径“F:\\ 1.mp3”放入后,avformat_open_input返回0(成功),但同时ctx-> filename为“.mp3”,前4个字符被修剪。 – user1288043 2012-03-29 11:49:30

+1

你在问我调试我看不到的代码。没有办法做到这一点。 – 2012-03-29 12:05:24

+0

问题是avformatcontext有所有错误的信息(它显示了数以百万计的流)。有没有其他的方式来读取单一的流而不是使用格式,只使用avcodec?我知道这个文件有一个音频流。 – user1288043 2012-03-29 12:22:38