From patchwork Thu Jun 16 19:55:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36260 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1127511pzb; Thu, 16 Jun 2022 13:04:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uTtiA9bHn4RMHhdRNliM2kPZlAB+xanT7TZh1voHo9Gqz3Qh/IYObr2b9xwMAB+CkwVHEt X-Received: by 2002:a17:907:d15:b0:71c:9ef2:2440 with SMTP id gn21-20020a1709070d1500b0071c9ef22440mr2182082ejc.266.1655409848584; Thu, 16 Jun 2022 13:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655409848; cv=none; d=google.com; s=arc-20160816; b=n5wz53zfLXz3Yc9ddFRVEgbww8+vKs2xH7ie3t/sA43JnpFUTqe9sLzLX6tsqHLPJk kh5m4axkz2tjl5MWq+ESb3gtq30QfGUZhOgfwXjRoN3sHqjGlqwfeP4JqpU6I7FP+6Bz KMJDbMwnTB5dofvY3Guvb9EwlvA9ugoY40IJVhVusWDgSfR8JUGnwIQm/+uDb5vWafie 3UrjCWA+T/pj7EOHgXExSvfMOIneZycVPwR4fuQg0HG55s5rci+x94gb8BNTVXEpiWdW +sKPru/LGN8dkhPlY44NB13z1m2cS2FViB42TuBlJar57cMuHNj5OCwsnDQZt0qHpHwj FHPQ== 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=1fJ5JRfV1RqXcxA5Xk+DRNLctu8A0B8fbINKn9fETcw=; b=pI9gFTHlP5Y5zIq84jrYhoZuZznRlNTmuXBSyRljGsy4d+/wiKa4b57iH+9rJhuama hFJTC3rS+g3Ev7ynV3tv45qZ1jFwulbucpNvI92/cFOicnM5R8QCU3M2OBzyUNs615yM gz+aK29u7BFNajFaKeDtFTKTCPDJ0C6n4x9Zaa5jjbFD3PJv/m3glFqiNSrT6y3wBA6U fgS7bW3EsLQZAfYvAChoL3OWv6Y8DACk9NydMEdipQhruwypJTiFP/UK1V4QbR7JM/5G zpgTUms0egZBsNS+zb8CZ1zBqwwgwCdBL830nLzpGFuEsJ5dwPU++NorNjHck3xotdzn BuVQ== 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 qc25-20020a170906d8b900b00711d56b4ec3si2218119ejb.795.2022.06.16.13.03.45; Thu, 16 Jun 2022 13:04:08 -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 11AE668B7B3; Thu, 16 Jun 2022 23:03:42 +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 C512768B7B3 for ; Thu, 16 Jun 2022 23:03:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2DC802405F0 for ; Thu, 16 Jun 2022 22:03:34 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Mt1OZUvFCS3d for ; Thu, 16 Jun 2022 22:03:33 +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 92B582400F5 for ; Thu, 16 Jun 2022 22:03:33 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 7B8423A0398; Thu, 16 Jun 2022 22:03:30 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jun 2022 21:55:01 +0200 Message-Id: <20220616195534.5278-2-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 02/35] fftools/ffmpeg: add a helper function to access output file size 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: zPWa0iWnTbwq Stop accessing muxer internals from outside of ffmpeg_mux. --- fftools/ffmpeg.c | 10 +--------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_mux.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 09caa3e3c4..5763f231c6 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1508,8 +1508,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti { AVBPrint buf, buf_script; OutputStream *ost; - AVFormatContext *oc; - int64_t total_size; + int64_t total_size = of_filesize(output_files[0]); AVCodecContext *enc; int frame_number, vid, i; double bitrate; @@ -1538,13 +1537,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - - oc = output_files[0]->ctx; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index c6ffe9fdf6..10a51db469 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -703,5 +703,6 @@ void of_close(OutputFile **pof); void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue); +int64_t of_filesize(OutputFile *of); #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index e47a55c4e9..83558f7f7d 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -333,3 +333,17 @@ int of_muxer_init(OutputFile *of) return 0; } + +int64_t of_filesize(OutputFile *of) +{ + AVIOContext *pb = of->ctx->pb; + int64_t ret = -1; + + 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); + } + + return ret; +}