From patchwork Thu Jun 16 19:55:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36262 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1127676pzb; Thu, 16 Jun 2022 13:04:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1slHgwuLDwjIjqH9OD1q3+Ikxbcjz/XIIIU8Msx1IKrSpLpLKAOleP61ORYFdllvVBV/6DT X-Received: by 2002:a17:906:b:b0:718:d0ff:fcbf with SMTP id 11-20020a170906000b00b00718d0fffcbfmr6029156eja.717.1655409868711; Thu, 16 Jun 2022 13:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655409868; cv=none; d=google.com; s=arc-20160816; b=opmY0jIlx/TVm/i0qRpATQFWBqn8kbgl0/207+e7YHGMiCYxfaouVZ1v9vBZCtuBj1 bkyKtak5E2XuD4CSUMoByFIWrWHKfCazjgIlyrBS4DDc4UzhYMphcnklvD6n2wmmgk2H uJeMITtfylKsYlD1G0Z1PXaDxFXUdz8J31FlWp1h9WeugHpTi6DcqIXw/+XjeM/OR7xb /JvyyOAA0k+Fpza9zgQRs7cpK5ikvFSADR4Lw0z3isuL9Oz6pNir+v9ALqKlE7HpU8Vl jjlBv+rK+qfLOAm/rgoy7XbDM2YynrcRuo3dNQalkweiRcMuXMRO1Lnjh8g1JlWv5jUt l01A== 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=ZVWwZurcQuiXq9M4p0L8XyFVrvwQW1ccrqgsT8WrtP4=; b=nO256wSBfmIF/i/+fEjWqME3ixu4RIaocQGWzA7ml/AKy/jnRg+s81cFWv6yKalTGZ mRpKU7pCIIzG5T/udH36aNyOLSNefELSYKPk4axKtWOlcblpCaeVTB79yncwhIC3nvzB LVo4NUA9e4gUfnqFGujaAa1GKhCYNCukux9Tj34QQdAyBVUcJsqAxpYgpB7gOtlpCn4+ XmAjkReH411O/+UBZWHcSgHnHdZeW2VUimpUCVG7/Fm23p587R2jRKGlVugpA3Woo/mZ tUVXbA0lQ1LyZp6W6R9NDPF2Ryc/ulZBF0D9EWtePpW6045gIxB+sQlXumi8LaIbsIJl Y3Mw== 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 qf38-20020a1709077f2600b006fed9433169si2996906ejc.826.2022.06.16.13.04.28; Thu, 16 Jun 2022 13:04:28 -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 2BFBB68B7FB; Thu, 16 Jun 2022 23:03:46 +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 CB62D68B7FB for ; Thu, 16 Jun 2022 23:03:36 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6C3142404FE for ; Thu, 16 Jun 2022 22:03:36 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NwmUjtTxVq43 for ; Thu, 16 Jun 2022 22:03:35 +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 AF868240506 for ; Thu, 16 Jun 2022 22:03:33 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 938DE3A12AD; Thu, 16 Jun 2022 22:03:30 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jun 2022 21:55:06 +0200 Message-Id: <20220616195534.5278-7-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220616195534.5278-1-anton@khirnov.net> References: <20220616195534.5278-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/35] fftools/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: tGGZ9XSTrbLa 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 2463056f8f..0364948b1a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -4304,7 +4304,6 @@ static int transcode_step(void) static int transcode(void) { int ret, i; - AVFormatContext *os; OutputStream *ost; InputStream *ist; int64_t timer_start; @@ -4373,18 +4372,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 396e91184b..78395bebb4 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; }; @@ -304,6 +305,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; } @@ -360,7 +372,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);