diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index c02df4b45f..c090e62099 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -1700,8 +1700,6 @@ static int read_interval_packets(AVTextFormatContext *tfc, InputFile *ifile, pkt->stream_index = i; if (do_read_frames) { while (process_frame(tfc, ifile, frame, pkt, &(int){1}) > 0); - if (ifile->streams[i].dec_ctx) - avcodec_flush_buffers(ifile->streams[i].dec_ctx); } } @@ -1715,6 +1713,18 @@ end: return ret; } +static void flush_buffers(InputFile *ifile) +{ + int i; + + if (!do_read_frames) + return; + for (i = 0; i < ifile->nb_streams; i++) { + if (ifile->streams[i].dec_ctx) + avcodec_flush_buffers(ifile->streams[i].dec_ctx); + } +} + static int read_packets(AVTextFormatContext *tfc, InputFile *ifile) { AVFormatContext *fmt_ctx = ifile->fmt_ctx; @@ -1726,6 +1736,10 @@ static int read_packets(AVTextFormatContext *tfc, InputFile *ifile) ret = read_interval_packets(tfc, ifile, &interval, &cur_ts); } else { for (i = 0; i < read_intervals_nb; i++) { + /* flushing buffers can reset parts of the private context which may be + * read by show_streams(), so only flush between each read_interval */ + if (i) + flush_buffers(ifile); ret = read_interval_packets(tfc, ifile, &read_intervals[i], &cur_ts); if (ret < 0) break;