]> git.sesse.net Git - ffmpeg/commitdiff
fftools/ffmpeg: when framerate is set, prefer its inverse as output timebase
authorAnton Khirnov <anton@khirnov.net>
Mon, 5 Apr 2021 08:44:36 +0000 (10:44 +0200)
committerAnton Khirnov <anton@khirnov.net>
Thu, 8 Apr 2021 09:03:15 +0000 (11:03 +0200)
Codec timebase is not well-defined for streamcopy, so it should only be
used as the last resort.

fftools/ffmpeg.c

index 46bb014de89d8c8028e119ed888b9a2d513f7e8b..8e6206647f85ae37a97b59f3a723d7602234a4d6 100644 (file)
@@ -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)