From patchwork Sun Apr 9 14:08:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41065 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1592196pzb; Sun, 9 Apr 2023 07:12:22 -0700 (PDT) X-Google-Smtp-Source: AKy350aYpy45+wFIklPTPtcCt+/3CSW1ebZSdKxgQjp1d32unbsVrmTXWnFdjtYE4skVrpJ0W6tR X-Received: by 2002:a17:906:339b:b0:94a:6f0d:567e with SMTP id v27-20020a170906339b00b0094a6f0d567emr1290259eja.56.1681049542445; Sun, 09 Apr 2023 07:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681049542; cv=none; d=google.com; s=arc-20160816; b=ixpQcubh73aIXMmdwoAPojlLbxJCx0dJoZxAQO5PxlcrRr8DHJAVLGULpBoIHcSTS6 skepqXBlnO6ZdZfWRnOPhcsQpAvyZl5PnK0nqypXtX3aMamtxoaMmEd+eNVdTXvuMMfV LV6tivxp32+brb3hI1YptzfD+Lj+7taSAF8i5+iCnFXZaBDFrXIHb69pWKJj2hT8rYF2 DZwq3DmFvYcusZsMr9IOV0X0xZN36OcTBKIeiyq4IO6dU2OeE1vOSGN3ZkZN47RwsHj2 Ux2rVUAR1o6iDvA+rfQUTJN5PAPIMABs/rfwUY5qPD5ncKescm7gFIyV9m2GA4UrAP7a jkJQ== 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=2TX3PPAt2XBqZ+lJ0WFZpYDUqHtNR3smR5dMjaQmxvY=; b=qEag3Zv5GoVo6h4SldWpiL7BRWTp/eNVDXIH1Db3KD5l5kv3vPvQJLmbkYn6jPo812 vT0VSbEM3FJXoNRIJp3KO37GuRVn2WG6KY+IyXbJn+lQoWhB7ZuWM0PcXW+P/dE+gDqZ u8EigJsiJYvVnsbH+KQzrHmf/Ws8UJ7bECjKVw6i+UF9B4hG8Im4qvSXa3Zyzeo6zKE0 GKCmy218jX2vTEFfzONdDeHaKOGcASAxs7bsRrrG/gjs/SLdik4RYFDAFxY2hAQF3JQ/ 4SDkp/jkkZMfIdM7lO7Ps9UtAC47iVgp9a2tTuL+XcqiBjEv8DqxpeoI3UH1DZxoARLA cR2A== 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 c19-20020aa7c993000000b00504a371adf5si120708edt.433.2023.04.09.07.12.22; Sun, 09 Apr 2023 07:12:22 -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 3136868BE68; Sun, 9 Apr 2023 17:09:38 +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 431D568BD38 for ; Sun, 9 Apr 2023 17:09:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F3D4A2404EC for ; Sun, 9 Apr 2023 16:09:20 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 30xMqRupmsXF for ; Sun, 9 Apr 2023 16:09:20 +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 1211E240D22 for ; Sun, 9 Apr 2023 16:09:11 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 024023A038E for ; Sun, 9 Apr 2023 16:09:11 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Apr 2023 16:08:52 +0200 Message-Id: <20230409140853.28858-28-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230409140853.28858-1-anton@khirnov.net> References: <20230409140853.28858-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/29] fftools/ffmpeg: move checking for input -t out of do_streamcopy() 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: PQqTzbLwJVfW This check is entirely about the properties of the input stream, while do_streamcopy() should contain code specific to a given output stream. --- fftools/ffmpeg.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4d4083d474..5c80f3b65f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -944,7 +944,6 @@ int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *pa static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt) { OutputFile *of = output_files[ost->file_index]; - InputFile *f = input_files [ist->file_index]; int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase); AVPacket *opkt = ost->pkt; @@ -977,18 +976,6 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p return; } - if (f->recording_time != INT64_MAX) { - start_time = 0; - if (copy_ts) { - start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0; - start_time += start_at_zero ? 0 : f->start_time_effective; - } - if (ist->pts >= f->recording_time + start_time) { - close_output_stream(ost); - return; - } - } - if (av_packet_ref(opkt, pkt) < 0) exit_program(1); @@ -1636,10 +1623,12 @@ static int send_filter_eof(InputStream *ist) /* pkt = NULL means EOF (needed to flush decoder buffers) */ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { + InputFile *f = input_files[ist->file_index]; const AVCodecParameters *par = ist->par; int ret = 0; int repeating = 0; int eof_reached = 0; + int duration_exceeded; AVPacket *avpkt = ist->pkt; @@ -1814,11 +1803,27 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } else if (!ist->decoding_needed) eof_reached = 1; + duration_exceeded = 0; + if (f->recording_time != INT64_MAX) { + int64_t start_time = 0; + if (copy_ts) { + start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0; + start_time += start_at_zero ? 0 : f->start_time_effective; + } + if (ist->pts >= f->recording_time + start_time) + duration_exceeded = 1; + } + for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { OutputStream *ost = ist->outputs[oidx]; if (ost->enc_ctx || (!pkt && no_eof)) continue; + if (duration_exceeded) { + close_output_stream(ost); + continue; + } + do_streamcopy(ist, ost, pkt); }