diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index f8b02a8871..842ed2fa66 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -556,10 +556,9 @@ static void ffmpeg_cleanup(int ret) of_close(&output_files[i]); free_input_threads(); - for (i = 0; i < nb_input_files; i++) { - avformat_close_input(&input_files[i]->ctx); - av_freep(&input_files[i]); - } + for (i = 0; i < nb_input_files; i++) + ifile_close(&input_files[i]); + for (i = 0; i < nb_input_streams; i++) { InputStream *ist = input_streams[i]; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index ab8b9018ca..1fd29fb0db 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -758,6 +758,7 @@ AVChapter * const * of_get_chapters(OutputFile *of, unsigned int *nb_chapters); int ifile_open(OptionsContext *o, const char *filename); +void ifile_close(InputFile **f); /** * Get next input packet from the demuxer. diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 53a497da66..880e56d2e3 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -439,6 +439,18 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) return 0; } +void ifile_close(InputFile **pf) +{ + InputFile *f = *pf; + + if (!f) + return; + + avformat_close_input(&f->ctx); + + av_freep(pf); +} + static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)