From patchwork Wed Aug 10 16:25:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37216 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1012641pzi; Wed, 10 Aug 2022 09:27:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR5pfXRDR+UiIubhH5zoT5BsYYC4C3dtuGZ+noYnxvwh62lcBPTaGWiE9ILXPCFmkgZutAXc X-Received: by 2002:a05:6402:4442:b0:43b:c866:21be with SMTP id o2-20020a056402444200b0043bc86621bemr27849378edb.28.1660148833860; Wed, 10 Aug 2022 09:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660148833; cv=none; d=google.com; s=arc-20160816; b=OBx9xG1ya4z8h8bDhSAo0Qrm1AbU2voCTI9TJ2BvCi0ecp4YyUX0onBVmeczEhqvGz zfhtKifBPmq5D3aSnyLlCaZ5rXLnlk5rsFKWTppeSdPTPsLO7AMclR1bpSsvk6yfEROf zaw+pg2wL+pQ+6X66QX/PHlD5MbJDi/jiME08WgX2Exumy0H7Vr5r5bcXejfcj5qbrp9 j/gW28mWBmeZ4C43K7Kg1QuIEKtBfQttLPlMXBJ/N36crp3m6WWAknpoW6FGZDjtjBl8 vORhQ4jGYHx+BmvSbthZ/Q5LZOU95uExQWuzl2O8+/AmDFo7fgEMqSAs3g8piuGB59Vh KNSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=800qE4lZ+W7OY21qDl10fgMITHJYNAhvDIcvAbRT7jE=; b=qtN4W6G27JhmW6/lZmsNiH7Ti/z2Bm+Z+tP9FfokIZIhkl6K2j/UzbC5z5rC/x4bfU 8rfLbcfvU3Zex+IN9iqHjAjYYYtEuiiwjUBg7BIb8vDlmu/8AMdthAwyBx0KmHJMIET5 T/zDAhzn/1D57DfHydIHHKqVQZD8MtTJRMQNAIz/MlicrFKKL1Cyi6K5FL/7vwB77yu8 OvkFTzADCNoRBRjp4KdvX0CHB0mJ5sfcbPyN8hv2XSbGq8BEMidl+0FdUuI5fmPg0Fd5 Fcfru1y743GU+daV4Yh9DeYehnLHEyd3+PxUt+J0JGwvGKHxIYipXLIHqnSUjA9Cg2IJ OHwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dz10-20020a0564021d4a00b00440e74ec425si6162369edb.540.2022.08.10.09.26.56; Wed, 10 Aug 2022 09:27:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7178668B895; Wed, 10 Aug 2022 19:26:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8500868B45F for ; Wed, 10 Aug 2022 19:25:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F3BA62404C7 for ; Wed, 10 Aug 2022 18:25:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id hQaIBgftm5kv for ; Wed, 10 Aug 2022 18:25:58 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 3AEC2240506 for ; Wed, 10 Aug 2022 18:25:57 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 381AA3A041D; Wed, 10 Aug 2022 18:25:57 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Aug 2022 18:25:40 +0200 Message-Id: <20220810162545.21382-4-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220810162545.21382-1-anton@khirnov.net> References: <20220810162545.21382-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/9] fftools/ffmpeg: pre-compute the streamcopy start pts before transcoding starts X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: F+RnCB8NmCof 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;