简体   繁体   中英

c++ ffmpeg access violation

What's wrong in this code? It is breaking (access violation) at av_find_stream_info. While debugging, ctx->filename is "3" instead of "1.MP3": first 4 chars are omitted, checked for other files too, same result.

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;
}

avformat_open_input is failing.

Use av_strerror to find out why avformat_open_input is failing. A negative value returned by avformat_open_input indicates an error condition.

Your code contains a bug -- it is calling av_find_stream_info even if avformat_open_input fails.

-2 is probably -ENOENT -- no such file or directory. Perhaps you're in the wrong directory. Perhaps the file's name is 1.mp3 , not 1.MP3 , and your filesystem is case-sensitive.

But you can't debug code that doesn't check for errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM