diff mbox series

[FFmpeg-devel] ffmpeg: fix usage of -shortest in codec copy scenarios

Message ID 20211127211951.60321-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] ffmpeg: fix usage of -shortest in codec copy scenarios
Related show

Checks

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

Commit Message

James Almer Nov. 27, 2021, 9:19 p.m. UTC
Don't mark all streams as finished, instead make sync_opts keep track of the
stream's duration, and set recording_time to it, same as in transcoding paths.

Fixes tickets #9512 and #9513.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 fftools/ffmpeg.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index c838e2604c..71c0460733 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1486,13 +1486,12 @@  static void do_video_stats(OutputStream *ost, int frame_size)
 static void finish_output_stream(OutputStream *ost)
 {
     OutputFile *of = output_files[ost->file_index];
-    int i;
 
     ost->finished = ENCODER_FINISHED | MUXER_FINISHED;
 
     if (of->shortest) {
-        for (i = 0; i < of->ctx->nb_streams; i++)
-            output_streams[of->ost_index + i]->finished = ENCODER_FINISHED | MUXER_FINISHED;
+        int64_t end = av_rescale_q(ost->sync_opts - ost->first_pts, ost->mux_timebase, AV_TIME_BASE_Q);
+        of->recording_time = FFMIN(of->recording_time, end);
     }
 }
 
@@ -2089,10 +2088,6 @@  static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
         }
     }
 
-    /* force the input stream PTS */
-    if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
-        ost->sync_opts++;
-
     if (av_packet_ref(opkt, pkt) < 0)
         exit_program(1);
 
@@ -2116,6 +2111,8 @@  static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
 
     opkt->duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase);
 
+    ost->sync_opts += opkt->duration;
+
     output_packet(of, opkt, ost, 0);
 }