From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 4/9] fftools/ffmpeg: pre-compute the streamcopy start pts before transcoding starts Date: Wed, 10 Aug 2022 18:25:40 +0200 Message-ID: <20220810162545.21382-4-anton@khirnov.net> (raw) In-Reply-To: <20220810162545.21382-1-anton@khirnov.net> InputFile.ts_offset can change during transcoding, due to discontinuity correction. This should not affect the streamcopy starting timestamp. Cf. bf2590aed3e64d44a5e2430fdbe89f91f5e55bfe --- fftools/ffmpeg.c | 17 ++++++++++++----- fftools/ffmpeg.h | 6 ++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 6f822de97d..b895f85e75 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1879,12 +1879,9 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p return; if (!ost->streamcopy_started && !ost->copy_prior_start) { - int64_t comp_start = start_time; - if (copy_ts && f->start_time != AV_NOPTS_VALUE) - comp_start = FFMAX(start_time, f->start_time + f->ts_offset); if (pkt->pts == AV_NOPTS_VALUE ? - ist->pts < comp_start : - pkt->pts < av_rescale_q(comp_start, AV_TIME_BASE_Q, ist->st->time_base)) + ist->pts < ost->ts_copy_start : + pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, ist->st->time_base)) return; } @@ -2741,6 +2738,7 @@ static int init_output_stream_streamcopy(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; InputStream *ist = get_input_stream(ost); + InputFile *ifile = input_files[ist->file_index]; AVCodecParameters *par = ost->st->codecpar; AVCodecContext *codec_ctx; AVRational sar; @@ -2805,6 +2803,15 @@ static int init_output_stream_streamcopy(OutputStream *ost) if (ost->st->duration <= 0 && ist->st->duration > 0) ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); + if (!ost->copy_prior_start) { + ost->ts_copy_start = (of->start_time == AV_NOPTS_VALUE) ? + 0 : of->start_time; + if (copy_ts && ifile->start_time != AV_NOPTS_VALUE) { + ost->ts_copy_start = FFMAX(ost->ts_copy_start, + ifile->start_time + ifile->ts_offset); + } + } + if (ist->st->nb_side_data) { for (i = 0; i < ist->st->nb_side_data; i++) { const AVPacketSideData *sd_src = &ist->st->side_data[i]; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 2ac7cbe522..8b2e73d642 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -484,6 +484,12 @@ typedef struct OutputStream { int64_t last_mux_dts; /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */ int64_t last_filter_pts; + + // timestamp from which the streamcopied streams should start, + // in AV_TIME_BASE_Q; + // everything before it should be discarded + int64_t ts_copy_start; + // the timebase of the packets sent to the muxer AVRational mux_timebase; AVRational enc_timebase; -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-08-10 16:26 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-08-10 16:25 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg: mark all encode sync queues as done before flushing encoders Anton Khirnov 2022-08-10 16:25 ` [FFmpeg-devel] [PATCH 2/9] fftools/ffmpeg_mux: avoid leaking pkt on errors Anton Khirnov 2022-08-10 16:25 ` [FFmpeg-devel] [PATCH 3/9] fftools/ffmpeg: move stream-dependent starttime correction to transcode_init() Anton Khirnov 2022-08-10 22:33 ` Michael Niedermayer 2022-08-11 7:45 ` [FFmpeg-devel] [PATCH] " Anton Khirnov 2022-08-12 15:43 ` Michael Niedermayer 2022-08-10 16:25 ` Anton Khirnov [this message] 2022-08-10 16:25 ` [FFmpeg-devel] [PATCH 5/9] fftools/ffmpeg: move timestamp discontinuity correction out of process_input() Anton Khirnov 2022-08-10 16:25 ` [FFmpeg-devel] [PATCH 6/9] fftools/ffmpeg: move inter-stream ts discontinuity handling to ts_discontinuity_process() Anton Khirnov 2022-08-10 16:25 ` [FFmpeg-devel] [PATCH 7/9] fftools/ffmpeg: simplify conditions in ts_discontinuity_process Anton Khirnov 2022-08-10 16:25 ` [FFmpeg-devel] [PATCH 8/9] fftools/ffmpeg: use a separate variable for discontinuity offset Anton Khirnov 2022-08-10 16:25 ` [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: move packet timestamp processing to demuxer thread Anton Khirnov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220810162545.21382-4-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git