From patchwork Tue Jan 11 09:58:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33212 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3545708iog; Tue, 11 Jan 2022 02:00:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCXXLv3Hk412WWuBLyU6qKmAFR9XhlJnatUODKoCwPIjJ0dJeC6Sw3vbZqIN36u5RZeZMX X-Received: by 2002:a17:906:9b93:: with SMTP id dd19mr3193779ejc.177.1641895239208; Tue, 11 Jan 2022 02:00:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895239; cv=none; d=google.com; s=arc-20160816; b=fSQpeG8cQwd/640ijZ80iKvN/Jh7CtL1vviHiNf3JKGKtd1V26GcNqCGwB1D8wLjF3 IyWVjAEDyhiu5VPRbjCeHOwqLpVHSRis4CD4JPbmMwtT2kxioOISQfQLBSuWLPBcKAbH 2KdmjZ2MX7vlFQnY7N/1PrU1N0wlbIAxgm0nGGX2lOyKEd/IvwZ3l8mGs0lXwS7Bm+YX gzswfRlav0SW+LmklkpNsf3j+xPd2NAKRzdldNbR3FXJMA374NCvJ0aAX3cAam32MRqb vlMMB7sC9yXOfjZktYfWZsqoi3sbPb1AU4UhD9HzwSl5upO2CCHOdNEbvaHHLqHMF52W h6XQ== 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=0w+ng549Wla06maGQSS68F3Y4JbqPXnYEYORlJVIi0o=; b=MDjps5gMp+Tmw+N5RSIgdkZ0yBA1ys6WIg60Jc7Nag/K8T9SD+0ndO/c/QVpUCsD9C RxHFlFpGlOOVFlPOwfTcBxTfHwlQEULM+6M2nn/sqXkaVoNeHw4VAYx5Gbu613fKYEYE DOCg0F3XGInwnbAek0KE1faGJAjO4T7EZPSkIek1pty57LqeVz21XNF2f02zQ6YmBO7R XZGKXDVfkee8naoc/N0FhlRHTb0uBk1TylwOeFuswVKySNZxBermXb7qn5CtaJaRC507 JWeM6JbB4N+9z+Y9XGhuwBGkL6slM7Mh3Tynviivsfh6xSUWxEyDrJafoTZ8kNxOA/5/ GV8g== 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 n10si5158153edx.634.2022.01.11.02.00.38; Tue, 11 Jan 2022 02:00:39 -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 1F72F68AF40; Tue, 11 Jan 2022 11:59:19 +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 6770468AF40 for ; Tue, 11 Jan 2022 11:59:09 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CE9C324050B for ; Tue, 11 Jan 2022 10:59:06 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 9szMtqKw8Yml for ; Tue, 11 Jan 2022 10:59:06 +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 90D48240511 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id EB7893A0804; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:10 +0100 Message-Id: <20220111095830.31542-8-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 08/28] 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: GsHjNWx13WB3 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 9360c8a475..1b5cf4d9af 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1514,8 +1514,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; @@ -1544,13 +1543,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 279a99cc48..dfcaa875d9 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -695,5 +695,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 538f153484..7c8414ac93 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -347,3 +347,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; +}