2014-10-24 8 views
3

Я пытаюсь открыть файл, используя avformat_open_input, и он сработает, даже если файл существует.Аварийная ошибка avformat_open_input

av_register_all(); 

AVFormatContext *avFormatContext; 

if (avformat_open_input(&avFormatContext, argv[1], NULL, NULL) < 0) 
{ 
    av_log(0, AV_LOG_FATAL, "Wasn't possible opening the file: %s", argv[1]); 
    return -1; 
} 
+1

[Вы читали документацию] (https://www.ffmpeg.org/doxygen/2.3/group__lavf__decoding.html#ga10a404346c646e4ab58f4ed798baca32)? В нем четко сказано, что «AVFormatContext» является «указателем на предоставленный пользователем« AVFormatContex't (выделен «avformat_alloc_context»). Может быть указателем на «NULL», и в этом случае для этой функции выделяется «AVFormatContext» записанный в 'ps'. – Cornstalks

ответ

5

Вы должны NULL переменную avFormatContext первый:

av_register_all(); 

AVFormatContext *avFormatContext = NULL; 

if (avformat_open_input(&avFormatContext, argv[1], NULL, NULL) < 0) 
{ 
    av_log(0, AV_LOG_FATAL, "Wasn't possible opening the file: %s", argv[1]); 
    return -1; 
} 
+0

Я решил это с помощью 'avformat_alloc_context'. - Я все равно соглашусь с вашим вопросом, также работает. Благодарю. – yayuj

Смежные вопросы