From patchwork Tue Jan 11 09:58:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33218 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3546468iog; Tue, 11 Jan 2022 02:01:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBHDATpToRihK7tXlWio6LTG9SfYzWlKoeHuF9ct7gqhBJr6c5lCnpaSodb6yTCqi0pIDI X-Received: by 2002:a05:6402:3550:: with SMTP id f16mr3625621edd.407.1641895301366; Tue, 11 Jan 2022 02:01:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895301; cv=none; d=google.com; s=arc-20160816; b=Kb8t2yUpO2H3zeUOSCq/sO//Yp4C3LH478Z3LPiBsdzDszTnYsUXYHAqIos8GcbMv0 J5JoZta5yTyCiz9CZAw1vy0wOrJKrfrNHnQRi8KjLWnPK7d9DoXqWvZlv9wqBZy8mBtF mLFUiaWu32xwMSGfqZ5vVwbKfmvbwRa639NBhaZEUZLQ+vF1FTUsulQrhJNkxmIuXbJO 8DufoW+4GU6GHdvTWMhxHUjHhOpL6BOepXcD9fYem3BvcHW5Vfnn07wEQlNIENFVmC5A 6IcWP2LZ1aJjfgzHlHYuHAyJG/UxGrIAVfJxVjOELvaNFoYhIMDTHXk485zC4UKqcw2g aB5A== 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=+2dXoteTKNIiimzAgAVGdllhLfVQl16YnYwXuD+bwPE=; b=FrY1uqS+gKI3Uv/wUQZbDvK61RwkLvL+/YNRCUUxBJSHTGImULuyHEa9hr/UZEjxKf LFr5e53pwZS9LBXu/THlNfSxBH3LQ+mqb4a/yOfNBMVqNIfHMZ2ovtQA0YHF7B2NCF/K BDttBYzfXY+j5hyr+BKKOb+choeLt582mKx7kNhTU4oSowQrrxpWPAqvG+AzFcbI5As2 JWkXx2/0gQg6kcd5Qk4sWaoEbB5XAuhru7PHhC9+gKiUtkyM8LLXDXp3C5njrtJOvB5f OTHHBvYDaGCRmAEUj0/IWBOecVZddCofQsF85W4nUD2BZPoeILsv0JQxQ28xnUuDtH2Y YnVw== 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 i6si4231848ejr.885.2022.01.11.02.01.40; Tue, 11 Jan 2022 02:01:41 -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 7F7F968AFDB; Tue, 11 Jan 2022 11:59:24 +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 AC4FF68AF4F for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 89C8C2405F0 for ; Tue, 11 Jan 2022 10:59:11 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 6_lsEtj62zGp for ; Tue, 11 Jan 2022 10:59:11 +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 E0A38240687 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 0C4B13A0A2B; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:15 +0100 Message-Id: <20220111095830.31542-13-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220111095830.31542-1-anton@khirnov.net> References: <20220111095830.31542-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/28] 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: uiNTn5Vw7q+H 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 | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index f28cc17f51..4f5c2cc49a 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 3b322ecb71..13b5d2d220 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -35,6 +35,7 @@ struct Muxer { /* filesize limit expressed in bytes */ int64_t limit_filesize; + int64_t final_filesize; int header_written; }; @@ -318,6 +319,17 @@ int of_write_trailer(OutputFile *of) return ret; } + of->mux->final_filesize = of_filesize(of); + + if (!(of->format->flags & AVFMT_NOFILE)) { + 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; } @@ -374,7 +386,9 @@ int64_t of_filesize(OutputFile *of) AVIOContext *pb = of->ctx->pb; int64_t ret = -1; - if (pb) { + if (of->mux->final_filesize) + ret = of->mux->final_filesize; + else if (pb) { ret = avio_size(pb); if (ret <= 0) // FIXME improve avio_size() so it works with non seekable output too ret = avio_tell(pb);