diff mbox series

[FFmpeg-devel,08/17] fftools/ffmpeg: when framerate is set, prefer its inverse as output timebase

Message ID 20210405110952.17679-9-anton@khirnov.net
State Accepted
Commit 0214da22cae08615f58f9769a4e8fb47d21aa687
Headers show
Series [FFmpeg-devel,01/17] lavu: postpone child_class_next API removal
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Anton Khirnov April 5, 2021, 11:09 a.m. UTC
Codec timebase is not well-defined for streamcopy, so it should only be
used as the last resort.
---
 fftools/ffmpeg.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 46bb014de8..8e6206647f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3151,8 +3151,12 @@  static int init_output_stream_streamcopy(OutputStream *ost)
         return ret;
 
     // copy timebase while removing common factors
-    if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
-        ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
+    if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) {
+        if (ost->frame_rate.num)
+            ost->st->time_base = av_inv_q(ost->frame_rate);
+        else
+            ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
+    }
 
     // copy estimated duration as a hint to the muxer
     if (ost->st->duration <= 0 && ist->st->duration > 0)