diff mbox series

[FFmpeg-devel,4/4] fftools/ffmpeg: call av_guess_frame_rate() when opening the file

Message ID 20220818134605.12583-4-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,1/4] lavf: deprecate av_stream_get_end_pts() | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Aug. 18, 2022, 1:46 p.m. UTC
It is currently called when configuring the filter, which races with the
demuxer thread.
---
 fftools/ffmpeg.h        | 2 ++
 fftools/ffmpeg_filter.c | 2 +-
 fftools/ffmpeg_opt.c    | 2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index f67a2f1d1d..ee3ae8120e 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -343,6 +343,8 @@  typedef struct InputStream {
      */
     AVCodecContext       *parser_dec;
 
+    AVRational framerate_guessed;
+
     int64_t       prev_pkt_pts;
     int64_t       start;     /* time when read started */
     /* predicted dts of the next packet read for this stream or (when there are
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index f9ae76f76d..16622e49c1 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -738,7 +738,7 @@  static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
     }
 
     if (!fr.num)
-        fr = av_guess_frame_rate(input_files[ist->file_index]->ctx, ist->st, NULL);
+        fr = ist->framerate_guessed;
 
     if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
         ret = sub2video_prepare(ist, ifilter);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index a505c7b26f..0810bd0b9e 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1074,6 +1074,8 @@  static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
                     exit_program(1);
             }
 
+            ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL);
+
             break;
         case AVMEDIA_TYPE_AUDIO:
             ist->guess_layout_max = INT_MAX;