diff mbox series

[FFmpeg-devel,10/23] fftools/ffmpeg: handle -enc_time_base -1 during stream creation

Message ID 20230531145453.20994-10-anton@khirnov.net
State Accepted
Commit 93e26a4db7784ca1372022ce7fea4a103eaf9a47
Headers show
Series [FFmpeg-devel,01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov May 31, 2023, 2:54 p.m. UTC
There is no reason to postpone it until opening the encoder. Also, abort
when the input stream is unknown, rather than disregard an explicit
request from the user.
---
 fftools/ffmpeg_enc.c      | 11 -----------
 fftools/ffmpeg_mux_init.c |  9 +++++++++
 2 files changed, 9 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 07928b3557..04d2c3c201 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -179,7 +179,6 @@  static void set_encoder_id(OutputFile *of, OutputStream *ost)
 
 static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
 {
-    InputStream *ist = ost->ist;
     AVCodecContext *enc_ctx = ost->enc_ctx;
 
     if (ost->enc_timebase.num > 0) {
@@ -187,16 +186,6 @@  static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba
         return;
     }
 
-    if (ost->enc_timebase.num < 0) {
-        if (ist) {
-            enc_ctx->time_base = ist->st->time_base;
-            return;
-        }
-
-        av_log(ost, AV_LOG_WARNING,
-               "Input stream data not available, using default time base\n");
-    }
-
     enc_ctx->time_base = default_time_base;
 }
 
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index d0b89cd188..c49f906dc7 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1149,6 +1149,15 @@  static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
                 av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base);
                 exit_program(1);
             }
+            if (q.num < 0) {
+                if (!ost->ist) {
+                    av_log(ost, AV_LOG_FATAL,
+                           "Cannot use input stream timebase for encoding - "
+                           "no input stream available\n");
+                    exit_program(1);
+                }
+                q = ost->ist->st->time_base;
+            }
             ost->enc_timebase = q;
         }
     } else {