mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-01-23 15:53:36 +00:00
ffmpeg: fix usage of -shortest in codec copy scenarios
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>
This commit is contained in:
parent
96caa01f13
commit
c1818cb947
@ -871,10 +871,11 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u
|
|||||||
static void close_output_stream(OutputStream *ost)
|
static void close_output_stream(OutputStream *ost)
|
||||||
{
|
{
|
||||||
OutputFile *of = output_files[ost->file_index];
|
OutputFile *of = output_files[ost->file_index];
|
||||||
|
AVRational time_base = ost->stream_copy ? ost->mux_timebase : ost->enc_ctx->time_base;
|
||||||
|
|
||||||
ost->finished |= ENCODER_FINISHED;
|
ost->finished |= ENCODER_FINISHED;
|
||||||
if (of->shortest) {
|
if (of->shortest) {
|
||||||
int64_t end = av_rescale_q(ost->sync_opts - ost->first_pts, ost->enc_ctx->time_base, AV_TIME_BASE_Q);
|
int64_t end = av_rescale_q(ost->sync_opts - ost->first_pts, time_base, AV_TIME_BASE_Q);
|
||||||
of->recording_time = FFMIN(of->recording_time, end);
|
of->recording_time = FFMIN(of->recording_time, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1483,13 +1484,13 @@ static void do_video_stats(OutputStream *ost, int frame_size)
|
|||||||
static void finish_output_stream(OutputStream *ost)
|
static void finish_output_stream(OutputStream *ost)
|
||||||
{
|
{
|
||||||
OutputFile *of = output_files[ost->file_index];
|
OutputFile *of = output_files[ost->file_index];
|
||||||
int i;
|
AVRational time_base = ost->stream_copy ? ost->mux_timebase : ost->enc_ctx->time_base;
|
||||||
|
|
||||||
ost->finished = ENCODER_FINISHED | MUXER_FINISHED;
|
ost->finished = ENCODER_FINISHED | MUXER_FINISHED;
|
||||||
|
|
||||||
if (of->shortest) {
|
if (of->shortest) {
|
||||||
for (i = 0; i < of->ctx->nb_streams; i++)
|
int64_t end = av_rescale_q(ost->sync_opts - ost->first_pts, time_base, AV_TIME_BASE_Q);
|
||||||
output_streams[of->ost_index + i]->finished = ENCODER_FINISHED | MUXER_FINISHED;
|
of->recording_time = FFMIN(of->recording_time, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2086,10 +2087,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)
|
if (av_packet_ref(opkt, pkt) < 0)
|
||||||
exit_program(1);
|
exit_program(1);
|
||||||
|
|
||||||
@ -2113,6 +2110,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);
|
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);
|
output_packet(of, opkt, ost, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user