From patchwork Mon Apr 4 11:30:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35157 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp1912089pzb; Mon, 4 Apr 2022 04:33:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwIWQekKOE9im28KMI+5oLl9+bRDTBGCECjM1Som8PcrFUkSW83KPLMlyQ28G5Da/Hs1A5 X-Received: by 2002:a05:6402:4402:b0:41c:d169:d8ea with SMTP id y2-20020a056402440200b0041cd169d8eamr4335736eda.303.1649072022657; Mon, 04 Apr 2022 04:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649072022; cv=none; d=google.com; s=arc-20160816; b=rBpoz6bT/pwnPEvFEZFW5pu9TDtZPywLSjduPkf+F9WG4Y41ISmB9I/6r5yJLCcMkx hhG7YOx8gpds8wjzTHfZabrKIknjoyfQXHneuftG6lkPZk8yNnWRFsiTiREC1e83TjHl VGCl4KUawDvKNBdtaPENk7nBvfyj41nvgsxNUJvCs9vTmNlf7lCyfpFA6A08AcpOCVZa Uf4/wcu5nZJYzL6Kke6j3uYb2oR3axtz54gHlCkzHAnpHI39tG4Su8K/t3HHWfdoTLZm gq0TcVDi+ZhZHE5E5COJzcqWZTR0hJgNoE0kY1VTWAOO3sLVfF/bXZyUkG140Lk+cjB6 H5gg== 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=nQt5lE8ws0x9Bdgkli1DDZis3ZfkuYkkl12vRIL7VF0=; b=YaE1RtCp2FDGmWKBoOzCK+bpEK2pBNl491zBYhYbrXW0m/3TwyIWPLSZp7E9tl42AI POX1ZV1ppAD0w+GfCwTqtIzZ+8IdzOYQgpWPLt7eLtQmDSbuRmK9kro5b4lQbs7yCtiD 7t4fVdqzhD2AW/L6S4rpXIs4kLOBKrVxvwXqv5V3QkJjA4L0RF8QbCTpTM5pvio9Rawg JohxxhzAF8G5ktG4N9dlGwVofZfmzlU/0NScHPCVWsE8T9G6aAK/bbVXrGxvJdBn0jTz wn+XvAsIDmF8G8szCpVfHYxnS3qggC3Yg74GGvP8lioYyiyi74441Rqa8+euXzmnGS5S 7DEg== 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 k4-20020a1709062a4400b006dfe65cdeefsi6125612eje.87.2022.04.04.04.33.42; Mon, 04 Apr 2022 04:33:42 -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 89C2B68B2BA; Mon, 4 Apr 2022 14:32:30 +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 5D87B68B160 for ; Mon, 4 Apr 2022 14:32:23 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BC07F240512 for ; Mon, 4 Apr 2022 13:32:20 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 13A4af6JZF1R for ; Mon, 4 Apr 2022 13:32: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 502242405F0 for ; Mon, 4 Apr 2022 13:32:15 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id D347E3A0AD1; Mon, 4 Apr 2022 13:32:11 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Apr 2022 13:30:04 +0200 Message-Id: <20220404113037.13070-17-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220404113037.13070-1-anton@khirnov.net> References: <20220404113037.13070-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/49] 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: inl5hTJOXUhF 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 e862a57215..252b14a710 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -4358,7 +4358,6 @@ static int transcode_step(void) static int transcode(void) { int ret, i; - AVFormatContext *os; OutputStream *ost; InputStream *ist; int64_t timer_start; @@ -4427,18 +4426,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 2a95b2602d..927d9228b7 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; }; @@ -317,6 +318,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; } @@ -373,7 +385,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);