From patchwork Mon Dec 13 15:20:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 32444 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5577962iog; Mon, 13 Dec 2021 07:26:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzg+LNYisJTJJbBqIsYF3RYoKuaD+NLQoBuCIR28aP7ukBVCoDLlWRU6uLXye7CHK8qQoYt X-Received: by 2002:a50:fb09:: with SMTP id d9mr63040616edq.283.1639409211457; Mon, 13 Dec 2021 07:26:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639409211; cv=none; d=google.com; s=arc-20160816; b=sgAa6zQNoo2GKMCTtUk5DNpDwQOTa7g1uKijDx+7/XBwSiZFrl0OtdCyHQqs7iqQFz MtUNWP4iTjsk533KQmD89nPhUN3yQgCXqUBMamJ+/9wRKR1t8qsZuXCHSM6JsGxfNc99 vpXl803Z2uYgd3D3WhZ02jVTO3ovTe/BonPltFOMv/dAn+jCrVFHQvuG18aaIJjl/Brj z0jFPfPHIiJQtw4jc6iJEgWs0vSzeIiAHcH2Fl0NmiOBBzsAkV+ENgq7kprBhXIHK5VP W96nc8XuQYy01qAqvnVFdPmJ0x0Vhi0pPN0E4o6HrrLurqEz+NYn0kwvkr29HvQX4eqK CahA== 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=ThxEN5I0GAGev/RxFP/0O5p9WChZSRxjVVkZ+BkMJqQ=; b=cmzwWsCO3vzqutJxHgeAJJvrAtqOEay9FyUtaQuBVdATcYGFmhE58mOExVYDCq3r6G 2wrf5cIxoeiUMncKod3UzN2PTvfJOVRHjpwtFYzYGFruw3klOxmBJ6lk54BB3FGxZnIR 9Fs4poPxEyk+8DyUFlI12hHBqRElen9pcjyTS0jdZkCXOKsAdScWwuZ67B2kq9y6s9vL 1YH2+gnbYbKOu/qm10f1mkZ+EAkK99cBw9I5ugbKjY8pbt9cJJ3cAz6LCwD9ZZqvmv4u MObO+jb3yRTrBmq+qr+S5xzh/Khaxv+A7E9YoUhcQ872a7LCELWOmlqlLEefivGnZ8yL aglQ== 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 hb16si19050840ejc.365.2021.12.13.07.26.48; Mon, 13 Dec 2021 07:26:51 -0800 (PST) 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 5705368B056; Mon, 13 Dec 2021 17:22:39 +0200 (EET) 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 3DCBB68AFCC for ; Mon, 13 Dec 2021 17:22:15 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9998C240592 for ; Mon, 13 Dec 2021 16:22:13 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id HOTryu1PxL-5 for ; Mon, 13 Dec 2021 16:22:13 +0100 (CET) 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 D3280240593 for ; Mon, 13 Dec 2021 16:22:07 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 419323A0A7F; Mon, 13 Dec 2021 16:22:07 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Dec 2021 16:20:32 +0100 Message-Id: <20211213152042.5900-14-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213152042.5900-1-anton@khirnov.net> References: <20211213152042.5900-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/24] ffmpeg: move closing the file into of_write_trailer() 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: Mr03CW/ikJmd The current code postpones closing the files until after printing the final report, which accesses the output file size. Deal with this by storing the final file size before closing the file. --- fftools/ffmpeg.c | 13 ------------- fftools/ffmpeg_mux.c | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index b7f26fe288..81a41fc8d1 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -4348,7 +4348,6 @@ static int transcode_step(void) static int transcode(void) { int ret, i; - AVFormatContext *os; OutputStream *ost; InputStream *ist; int64_t timer_start; @@ -4417,18 +4416,6 @@ static int transcode(void) /* dump report by using the first video and audio streams */ print_report(1, timer_start, av_gettime_relative()); - /* close the output files */ - for (i = 0; i < nb_output_files; i++) { - os = output_files[i]->ctx; - if (os && os->oformat && !(os->oformat->flags & AVFMT_NOFILE)) { - if ((ret = avio_closep(&os->pb)) < 0) { - av_log(NULL, AV_LOG_ERROR, "Error closing file %s: %s\n", os->url, av_err2str(ret)); - if (exit_on_error) - exit_program(1); - } - } - } - /* close each encoder */ for (i = 0; i < nb_output_streams; i++) { ost = output_streams[i]; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 3ae20fdeeb..3ee0fc0667 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -35,6 +35,7 @@ struct Muxer { /* filesize limit expressed in bytes */ uint64_t limit_filesize; + uint64_t final_filesize; int header_written; }; @@ -318,6 +319,17 @@ int of_write_trailer(OutputFile *of) return ret; } + if (!(of->format->flags & AVFMT_NOFILE)) { + of->mux->final_filesize = of->ctx->pb->bytes_written; + + ret = avio_closep(&of->ctx->pb); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error closing file %s: %s\n", + of->ctx->url, av_err2str(ret)); + return ret; + } + } + return 0; } @@ -375,5 +387,6 @@ int of_finished(OutputFile *of) int64_t of_bytes_written(OutputFile *of) { AVIOContext *pb = of->ctx->pb; - return pb ? pb->bytes_written : -1; + return of->mux->final_filesize ? of->mux->final_filesize : + pb ? pb->bytes_written : -1; }