[FFmpeg-devel] [PATCH] fftools/ffmpeg: allow forcing input framerate on streamcopy

Paul B Mahol onemda at gmail.com
Tue Feb 11 19:05:20 EET 2020


From: Leo Izen <leo.izen at gmail.com>

Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 fftools/ffmpeg.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index b0bffe0a54..9bfa853253 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2045,10 +2045,12 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
     if (av_packet_ref(&opkt, pkt) < 0)
         exit_program(1);
 
-    if (pkt->pts != AV_NOPTS_VALUE)
+    if (ist->framerate.num)
+        opkt.pts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->mux_timebase) - ost_tb_start_time;
+    else if (pkt->pts != AV_NOPTS_VALUE)
         opkt.pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->mux_timebase) - ost_tb_start_time;
 
-    if (pkt->dts == AV_NOPTS_VALUE)
+    if (pkt->dts == AV_NOPTS_VALUE || ist->framerate.num)
         opkt.dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase);
     else
         opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase);
@@ -2590,7 +2592,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
         avpkt = *pkt;
     }
 
-    if (pkt && pkt->dts != AV_NOPTS_VALUE) {
+    if (pkt && pkt->dts != AV_NOPTS_VALUE && !ist->framerate.num) {
         ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
         if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed)
             ist->next_pts = ist->pts = ist->dts;
@@ -3146,8 +3148,14 @@ static int init_output_stream_streamcopy(OutputStream *ost)
         else
             sar = par_src->sample_aspect_ratio;
         ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar;
-        ost->st->avg_frame_rate = ist->st->avg_frame_rate;
-        ost->st->r_frame_rate = ist->st->r_frame_rate;
+
+        if (ist->framerate.num) {
+            ost->st->avg_frame_rate = ist->framerate;
+            ost->st->r_frame_rate = ist->framerate;
+        } else {
+            ost->st->avg_frame_rate = ist->st->avg_frame_rate;
+            ost->st->r_frame_rate = ist->st->r_frame_rate;
+        }
         break;
     }
 
-- 
2.17.1



More information about the ffmpeg-devel mailing list