From patchwork Tue Jan 11 09:58:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33205 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3544811iog; Tue, 11 Jan 2022 01:59:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJztXY7ZXL/uDsV3P69pNrhMd0rIfidrjVWWkC7NXbOBusJ0r7HuiDEMo3/F0LttaXmch8Vi X-Received: by 2002:aa7:cd9a:: with SMTP id x26mr3621446edv.159.1641895166672; Tue, 11 Jan 2022 01:59:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895166; cv=none; d=google.com; s=arc-20160816; b=AH3FS1A3KOLxVRcH5td+38P+DNMH9nJe2J8zcdjDtZ/IXvhsqU+2um2z1al/yQ7sVF WRcQFKXOUUcJkDs/T4WjLttvCri6aTZNJ/sTV/Ch9mxL1hOvbKfE2k23ana0QsBNP5Rl aIcewbkpXQjUlJ6C3VrO3Y3faluBpUIrRePBSZaavLF4C04q+1ITFg7VfA7r71mh84tq gFUiwVm8LYGaSiW4OsBYhD4Gu3Fd3tRoSu4qYUlaWsmTwRallY5bhoaR2u7+D/wUeoZG 1oHj0Pa8jrqEYQYC3iq/0WaFpf5324d+fUuvDqs/bl/eCgNr1TlbE1a5gx/OpVbjGmub grNw== 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:message-id:date:to:from :delivered-to; bh=WfyYjVxM8IEVMj4PFPv469RtSzg6+mWHQ6f6JMDhS5I=; b=QHwmV7yzalIomevPQlylDNPO15KaGCV4QEd5L6WQJOxs15bF29ljnQRzhlvu9AgPB+ gHznOKcz9wdcfiMdCqUlCSk3zaebKwMyjD2ZTFoLZ36zthiB9g5NJiDnuBLHPHLb2yF6 whldwjyJAwRIub9sjxhqMwHTJqLnIM3pDsQoakpCggA4fZb3x8Ir8WiVOSYIEf5OT2AC u7HYplzJnD7YMFwVwKIutCPoqjpXBBzBvBapVbfIitd0xz05FXNv7EdxfMj9cYl4Z8GS v9qdR/gRwCYbbz50YCjQP1pCj9m9q+0PYTyFYWA54ubv1i27MW3VPI3cic4WbuunBdxt WHhA== 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 sd20si706411ejc.41.2022.01.11.01.59.24; Tue, 11 Jan 2022 01:59:26 -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 8D15668AEE9; Tue, 11 Jan 2022 11:59:11 +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 2558768ADF7 for ; Tue, 11 Jan 2022 11:59:04 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CB0A724017E for ; Tue, 11 Jan 2022 10:59:03 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id xMv7MHH7gpCJ for ; Tue, 11 Jan 2022 10:59:01 +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 EAE53240179 for ; Tue, 11 Jan 2022 10:59:01 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id CC0213A0631; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:03 +0100 Message-Id: <20220111095830.31542-1-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/28] ffmpeg: pass the muxer context explicitly to some functions 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: F2g2dfynW/an Stop accessing OutputFile.ctx. This will be useful in the following commits, where it will become hidden. --- fftools/ffmpeg_opt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 9c820ab73f..f638edace9 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2094,10 +2094,10 @@ static int opt_streamid(void *optctx, const char *opt, const char *arg) return 0; } -static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata) +static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *os, + int copy_metadata) { AVFormatContext *is = ifile->ctx; - AVFormatContext *os = ofile->ctx; AVChapter **tmp; int i; @@ -2137,14 +2137,14 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata) return 0; } -static int set_dispositions(OutputFile *of) +static int set_dispositions(OutputFile *of, AVFormatContext *ctx) { int nb_streams[AVMEDIA_TYPE_NB] = { 0 }; int have_default[AVMEDIA_TYPE_NB] = { 0 }; int have_manual = 0; // first, copy the input dispositions - for (int i = 0; i< of->ctx->nb_streams; i++) { + for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = output_streams[of->ost_index + i]; nb_streams[ost->st->codecpar->codec_type]++; @@ -2161,7 +2161,7 @@ static int set_dispositions(OutputFile *of) if (have_manual) { // process manually set dispositions - they override the above copy - for (int i = 0; i< of->ctx->nb_streams; i++) { + for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = output_streams[of->ost_index + i]; int ret; @@ -2187,7 +2187,7 @@ static int set_dispositions(OutputFile *of) // For each media type with more than one stream, find a suitable stream to // mark as default, unless one is already marked default. // "Suitable" means the first of that type, skipping attached pictures. - for (int i = 0; i< of->ctx->nb_streams; i++) { + for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = output_streams[of->ost_index + i]; enum AVMediaType type = ost->st->codecpar->codec_type; @@ -2725,7 +2725,7 @@ loop_end: } } if (o->chapters_input_file >= 0) - copy_chapters(input_files[o->chapters_input_file], of, + copy_chapters(input_files[o->chapters_input_file], of, oc, !o->metadata_chapters_manual); /* copy global metadata by default */ @@ -2878,7 +2878,7 @@ loop_end: } } - err = set_dispositions(of); + err = set_dispositions(of, oc); if (err < 0) { av_log(NULL, AV_LOG_FATAL, "Error setting output stream dispositions\n"); exit_program(1); From patchwork Tue Jan 11 09:58: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: 33210 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3545337iog; Tue, 11 Jan 2022 02:00:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzq1vE21PII+fp7nya0ePFxffv+ckQJW63+OIoUGQNVjW1XaWMLtxPLtfOxxuLNDlXC4MRX X-Received: by 2002:a05:6402:1d54:: with SMTP id dz20mr3506713edb.395.1641895217534; Tue, 11 Jan 2022 02:00:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895217; cv=none; d=google.com; s=arc-20160816; b=wKb0/almfJpY8sUCuv/iOHCAmUT+r4pm0uJJJQ9YoIDskGbG1SCGniLKz3Jkvhp/bf vYvOjYD8PZ6QVzxkO6PT9cYDQ3pC3Akzr/7hIrcZrdUhD6F9yaBqBotxuzYysyr3AstT v7ZK7bFdceHPrGjSxheSX1Vh/lCifrdx7YIYumtKLSNP1PrdWkBqKvDxkTh0SV5uZlON a2Y33OtHQGlJDsjiK7YjlWlzxnC9umB0g9CbVl0IUpo7jci5MdZWytoAknHF266k0nO8 YBVcUKwpbS50LWYKkd5jHPfzAJdT3OQIbmVt/1u9imIQUtBn1bCy/RCNNPlg3tv32UY6 SkbQ== 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=+nD6KQdNGEkek3Lv1RKEZlQuze24ZuD/evSnooQxQjQ=; b=IVQO+gepwSN86C9nW0+ZgOvhhp9FGaKiWWFIE07c8FadyWA2wfFK+5XpCQKaNgqxAs J0ayHD08y7AKbxcFswgIxQWo+9uBUw4sVYCnhyIFZhvYRIVYDZylFMHjYmiyGf3pnV9b 9HAhcHR1uyRy7haw3sbfbV4nSu0s9udrRcX44nkNpSB7nj5trFCkUtmbTKgNV8cWhmRw G4KaqAoH3l4aSi5T+JaZv9Jlwg4Ssy2Zay0ktGD7A8PYeIkGVlZShtgPyv7pPAHL2L5f UxLDBlj4tlEz6X0S+P7BpsUCb44ln34UjJRaOq+yjm3vrQxcph1EK6un5eF482dRYGEj TkPA== 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 hc17si2615550ejc.400.2022.01.11.02.00.16; Tue, 11 Jan 2022 02:00:17 -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 E38FB68AF41; Tue, 11 Jan 2022 11:59:16 +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 5BCF568AF3B for ; Tue, 11 Jan 2022 11:59:09 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D9009240506 for ; Tue, 11 Jan 2022 10:59:05 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id FduQUQHnKXnV for ; Tue, 11 Jan 2022 10:59:05 +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 874AD24050B for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id CDC3E3A038C; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:04 +0100 Message-Id: <20220111095830.31542-2-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 02/28] ffmpeg: store the output file index in OutputFile 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: TrB+MeSmRz3p Use it to simplify check_init_output_file(). Will allow further simplifications in the following commits. --- fftools/ffmpeg.c | 10 +++++----- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_opt.c | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5d134b025f..1961653dcc 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2941,7 +2941,7 @@ static int compare_int64(const void *a, const void *b) } /* open the muxer when all the streams are initialized */ -static int check_init_output_file(OutputFile *of, int file_index) +static int check_init_output_file(OutputFile *of) { int ret, i; @@ -2956,13 +2956,13 @@ static int check_init_output_file(OutputFile *of, int file_index) av_log(NULL, AV_LOG_ERROR, "Could not write header for output file #%d " "(incorrect codec parameters ?): %s\n", - file_index, av_err2str(ret)); + of->index, av_err2str(ret)); return ret; } //assert_avoptions(of->opts); of->header_written = 1; - av_dump_format(of->ctx, file_index, of->ctx->url, 1); + av_dump_format(of->ctx, of->index, of->ctx->url, 1); nb_output_dumped++; if (sdp_filename || want_sdp) { @@ -3565,7 +3565,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, ost->initialized = 1; - ret = check_init_output_file(output_files[ost->file_index], ost->file_index); + ret = check_init_output_file(output_files[ost->file_index]); if (ret < 0) return ret; @@ -3668,7 +3668,7 @@ static int transcode_init(void) for (i = 0; i < nb_output_files; i++) { oc = output_files[i]->ctx; if (oc->oformat->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) { - ret = check_init_output_file(output_files[i], i); + ret = check_init_output_file(output_files[i]); if (ret < 0) goto dump_format; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 9b200b806a..5fd5d2606b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -574,6 +574,8 @@ typedef struct OutputStream { } OutputStream; typedef struct OutputFile { + int index; + AVFormatContext *ctx; AVDictionary *opts; int ost_index; /* index of the first stream in output_streams */ diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index f638edace9..e8db515e0c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2283,6 +2283,7 @@ static int open_output_file(OptionsContext *o, const char *filename) of = ALLOC_ARRAY_ELEM(output_files, nb_output_files); + of->index = nb_output_files - 1; of->ost_index = nb_output_streams; of->recording_time = o->recording_time; of->start_time = o->start_time; From patchwork Tue Jan 11 09:58:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33207 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3544969iog; Tue, 11 Jan 2022 01:59:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5e5QiPFU8lm69F/+RS93SgSvIXi7WRTxKqlCfEQpUgxDzdXTn1F1JUEHQGNmm7IusZT21 X-Received: by 2002:a17:907:ea2:: with SMTP id ho34mr2988310ejc.168.1641895186163; Tue, 11 Jan 2022 01:59:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895186; cv=none; d=google.com; s=arc-20160816; b=Mb2L7NdAtaPfIBNbZaUk6Z2ILgpEkwjAbgSuPlrSXO0VJ3i9HckpX1+nuMka6Xn1QN /zxAIReZNmx1bqWbza0zmI7/8JqtvlbSBykVcPXAaG697Aw0/sHn040jWvAWvJndH4q1 f30mKOoEuWB4v1TCiM/mh1UsXfh69v2vNnNTrziO7u21vXNUUUWQLh2s9TUG0KVhu/32 NiJeP3wLuoH+I0jgY0rQ9kAScpsRBZJWiHGH73GSr/QaTtG3ORS6s98M6EBejOoo2B6k c6hg+fSCV7Xh7TLnkSJRwVuYaKLIuH7Eyg+an/AjdMZsYFAcYRBAraK+4N5C8COg1nDy /Kkg== 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=EyfQCw1UX4165r7YoFeRqfIMMrptr87mstQst2lZoEg=; b=b6fnLkqTMtE0pyubd6Ah7dSHEotAYrDHJk21TApxJeblwQYEeRw4Ks0oEsGlnhMD0Y 6gKYCesygAt/NzNhyvYVTR5+GArX/hO9dYh/q+uB88qO5nnLGZM44zy+eB3M5mNeiqKx zPzRcYHhRHYF0dsaP+roLt/nXYZ11ijFzkAstfef69CxOhb1Bel9gkN7kQFUoV2xxFd5 L7j1rAzI8p9f9rYOg+Hhlhjm0bKWVxNKpqDVm0Jxn2UlBwmROoIKJRqYlTMM9dD5404j jRFIfftxdK/YjQhq/v1feVpMjE+PxjK1rsr66Y2x/ianJddFvWNbQhVfaS0wGJNk80mv PO5g== 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 o10si4637060edw.363.2022.01.11.01.59.45; Tue, 11 Jan 2022 01:59:46 -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 2EC36680134; Tue, 11 Jan 2022 11:59:13 +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 5AD8068AEC1 for ; Tue, 11 Jan 2022 11:59:05 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1E12F240699 for ; Tue, 11 Jan 2022 10:59:05 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id b7twjlgVSEU2 for ; Tue, 11 Jan 2022 10:59:03 +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 3909524017C for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id D4FD83A073E; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:05 +0100 Message-Id: <20220111095830.31542-3-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 03/28] ffmpeg: move some muxing-related code into a separate file 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: YpmraN7i4Pi4 This is a first step towards making muxers more independent from the rest of the code. --- fftools/Makefile | 6 +- fftools/ffmpeg.c | 273 ++-------------------------------------- fftools/ffmpeg.h | 10 ++ fftools/ffmpeg_mux.c | 293 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 315 insertions(+), 267 deletions(-) create mode 100644 fftools/ffmpeg_mux.c diff --git a/fftools/Makefile b/fftools/Makefile index da420786eb..27a22250b3 100644 --- a/fftools/Makefile +++ b/fftools/Makefile @@ -9,7 +9,11 @@ AVBASENAMES = ffmpeg ffplay ffprobe ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF)) ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) -OBJS-ffmpeg += fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o +OBJS-ffmpeg += \ + fftools/ffmpeg_filter.o \ + fftools/ffmpeg_hw.o \ + fftools/ffmpeg_mux.o \ + fftools/ffmpeg_opt.o \ define DOFFTOOL OBJS-$(1) += fftools/cmdutils.o fftools/$(1).o $(OBJS-$(1)-yes) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1961653dcc..e0aa533dc9 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -136,9 +136,9 @@ static int nb_frames_dup = 0; static unsigned dup_warning = 1000; static int nb_frames_drop = 0; static int64_t decode_error_stat[2]; -static unsigned nb_output_dumped = 0; +unsigned nb_output_dumped = 0; -static int want_sdp = 1; +int want_sdp = 1; static BenchmarkTimeStamps current_time; AVIOContext *progress_avio = NULL; @@ -344,7 +344,7 @@ static volatile int received_sigterm = 0; static volatile int received_nb_signals = 0; static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0); static volatile int ffmpeg_exited = 0; -static int main_return_code = 0; +int main_return_code = 0; static int64_t copy_ts_first_pts = AV_NOPTS_VALUE; static void @@ -715,159 +715,6 @@ static void update_benchmark(const char *fmt, ...) } } -static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others) -{ - int i; - for (i = 0; i < nb_output_streams; i++) { - OutputStream *ost2 = output_streams[i]; - ost2->finished |= ost == ost2 ? this_stream : others; - } -} - -static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue) -{ - AVFormatContext *s = of->ctx; - AVStream *st = ost->st; - int ret; - - /* - * Audio encoders may split the packets -- #frames in != #packets out. - * But there is no reordering, so we can limit the number of output packets - * by simply dropping them here. - * Counting encoded video frames needs to be done separately because of - * reordering, see do_video_out(). - * Do not count the packet when unqueued because it has been counted when queued. - */ - if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) && !unqueue) { - if (ost->frame_number >= ost->max_frames) { - av_packet_unref(pkt); - return; - } - ost->frame_number++; - } - - if (!of->header_written) { - AVPacket *tmp_pkt; - /* the muxer is not initialized yet, buffer the packet */ - if (!av_fifo_space(ost->muxing_queue)) { - size_t cur_size = av_fifo_size(ost->muxing_queue); - unsigned int are_we_over_size = - (ost->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold; - size_t limit = are_we_over_size ? ost->max_muxing_queue_size : INT_MAX; - size_t new_size = FFMIN(2 * cur_size, limit); - - if (new_size <= cur_size) { - av_log(NULL, AV_LOG_ERROR, - "Too many packets buffered for output stream %d:%d.\n", - ost->file_index, ost->st->index); - exit_program(1); - } - ret = av_fifo_realloc2(ost->muxing_queue, new_size); - if (ret < 0) - exit_program(1); - } - ret = av_packet_make_refcounted(pkt); - if (ret < 0) - exit_program(1); - tmp_pkt = av_packet_alloc(); - if (!tmp_pkt) - exit_program(1); - av_packet_move_ref(tmp_pkt, pkt); - ost->muxing_queue_data_size += tmp_pkt->size; - av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL); - return; - } - - if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) || - (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0)) - pkt->pts = pkt->dts = AV_NOPTS_VALUE; - - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - int i; - uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, - NULL); - ost->quality = sd ? AV_RL32(sd) : -1; - ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; - - for (i = 0; ierror); i++) { - if (sd && i < sd[5]) - ost->error[i] = AV_RL64(sd + 8 + 8*i); - else - ost->error[i] = -1; - } - - if (ost->frame_rate.num && ost->is_cfr) { - if (pkt->duration > 0) - av_log(NULL, AV_LOG_WARNING, "Overriding packet duration by frame rate, this should not happen\n"); - pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate), - ost->mux_timebase); - } - } - - av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base); - - if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) { - if (pkt->dts != AV_NOPTS_VALUE && - pkt->pts != AV_NOPTS_VALUE && - pkt->dts > pkt->pts) { - av_log(s, AV_LOG_WARNING, "Invalid DTS: %"PRId64" PTS: %"PRId64" in output stream %d:%d, replacing by guess\n", - pkt->dts, pkt->pts, - ost->file_index, ost->st->index); - pkt->pts = - pkt->dts = pkt->pts + pkt->dts + ost->last_mux_dts + 1 - - FFMIN3(pkt->pts, pkt->dts, ost->last_mux_dts + 1) - - FFMAX3(pkt->pts, pkt->dts, ost->last_mux_dts + 1); - } - if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) && - pkt->dts != AV_NOPTS_VALUE && - !(st->codecpar->codec_id == AV_CODEC_ID_VP9 && ost->stream_copy) && - ost->last_mux_dts != AV_NOPTS_VALUE) { - int64_t max = ost->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT); - if (pkt->dts < max) { - int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG; - if (exit_on_error) - loglevel = AV_LOG_ERROR; - av_log(s, loglevel, "Non-monotonous DTS in output stream " - "%d:%d; previous: %"PRId64", current: %"PRId64"; ", - ost->file_index, ost->st->index, ost->last_mux_dts, pkt->dts); - if (exit_on_error) { - av_log(NULL, AV_LOG_FATAL, "aborting.\n"); - exit_program(1); - } - av_log(s, loglevel, "changing to %"PRId64". This may result " - "in incorrect timestamps in the output file.\n", - max); - if (pkt->pts >= pkt->dts) - pkt->pts = FFMAX(pkt->pts, max); - pkt->dts = max; - } - } - } - ost->last_mux_dts = pkt->dts; - - ost->data_size += pkt->size; - ost->packets_written++; - - pkt->stream_index = ost->index; - - if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "muxer <- type:%s " - "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s size:%d\n", - av_get_media_type_string(ost->enc_ctx->codec_type), - av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base), - av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base), - pkt->size - ); - } - - ret = av_interleaved_write_frame(s, pkt); - if (ret < 0) { - print_error("av_interleaved_write_frame()", ret); - main_return_code = 1; - close_all_output_streams(ost, MUXER_FINISHED | ENCODER_FINISHED, ENCODER_FINISHED); - } -} - static void close_output_stream(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; @@ -902,11 +749,11 @@ static void output_packet(OutputFile *of, AVPacket *pkt, if (ret < 0) goto finish; while ((ret = av_bsf_receive_packet(ost->bsf_ctx, pkt)) >= 0) - write_packet(of, pkt, ost, 0); + of_write_packet(of, pkt, ost, 0); if (ret == AVERROR(EAGAIN)) ret = 0; } else if (!eof) - write_packet(of, pkt, ost, 0); + of_write_packet(of, pkt, ost, 0); finish: if (ret < 0 && ret != AVERROR_EOF) { @@ -2761,59 +2608,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo return !eof_reached; } -static int print_sdp(void) -{ - char sdp[16384]; - int i; - int j, ret; - AVIOContext *sdp_pb; - AVFormatContext **avc; - - for (i = 0; i < nb_output_files; i++) { - if (!output_files[i]->header_written) - return 0; - } - - avc = av_malloc_array(nb_output_files, sizeof(*avc)); - if (!avc) - exit_program(1); - for (i = 0, j = 0; i < nb_output_files; i++) { - if (!strcmp(output_files[i]->ctx->oformat->name, "rtp")) { - avc[j] = output_files[i]->ctx; - j++; - } - } - - if (!j) { - av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n"); - ret = AVERROR(EINVAL); - goto fail; - } - - ret = av_sdp_create(avc, j, sdp, sizeof(sdp)); - if (ret < 0) - goto fail; - - if (!sdp_filename) { - printf("SDP:\n%s\n", sdp); - fflush(stdout); - } else { - ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename); - goto fail; - } - - avio_print(sdp_pb, sdp); - avio_closep(&sdp_pb); - av_freep(&sdp_filename); - } - -fail: - av_freep(&avc); - return ret; -} - static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts) { InputStream *ist = s->opaque; @@ -2940,59 +2734,6 @@ static int compare_int64(const void *a, const void *b) return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b); } -/* open the muxer when all the streams are initialized */ -static int check_init_output_file(OutputFile *of) -{ - int ret, i; - - for (i = 0; i < of->ctx->nb_streams; i++) { - OutputStream *ost = output_streams[of->ost_index + i]; - if (!ost->initialized) - return 0; - } - - ret = avformat_write_header(of->ctx, &of->opts); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, - "Could not write header for output file #%d " - "(incorrect codec parameters ?): %s\n", - of->index, av_err2str(ret)); - return ret; - } - //assert_avoptions(of->opts); - of->header_written = 1; - - av_dump_format(of->ctx, of->index, of->ctx->url, 1); - nb_output_dumped++; - - if (sdp_filename || want_sdp) { - ret = print_sdp(); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Error writing the SDP.\n"); - return ret; - } - } - - /* flush the muxing queues */ - for (i = 0; i < of->ctx->nb_streams; i++) { - OutputStream *ost = output_streams[of->ost_index + i]; - - /* try to improve muxing time_base (only possible if nothing has been written yet) */ - if (!av_fifo_size(ost->muxing_queue)) - ost->mux_timebase = ost->st->time_base; - - while (av_fifo_size(ost->muxing_queue)) { - AVPacket *pkt; - av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL); - ost->muxing_queue_data_size -= pkt->size; - write_packet(of, pkt, ost, 1); - av_packet_free(&pkt); - } - } - - return 0; -} - static int init_output_bsfs(OutputStream *ost) { AVBSFContext *ctx = ost->bsf_ctx; @@ -3565,7 +3306,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, ost->initialized = 1; - ret = check_init_output_file(output_files[ost->file_index]); + ret = of_check_init(output_files[ost->file_index]); if (ret < 0) return ret; @@ -3668,7 +3409,7 @@ static int transcode_init(void) for (i = 0; i < nb_output_files; i++) { oc = output_files[i]->ctx; if (oc->oformat->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) { - ret = check_init_output_file(output_files[i]); + ret = of_check_init(output_files[i]); if (ret < 0) goto dump_format; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 5fd5d2606b..fed34b06f8 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -644,6 +644,10 @@ extern char *qsv_device; #endif extern HWDevice *filter_hw_device; +extern int want_sdp; +extern unsigned nb_output_dumped; +extern int main_return_code; + void term_init(void); void term_exit(void); @@ -680,4 +684,10 @@ int hw_device_setup_for_filter(FilterGraph *fg); int hwaccel_decode_init(AVCodecContext *avctx); +/* open the muxer when all the streams are initialized */ +int of_check_init(OutputFile *of); + +void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, + int unqueue); + #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c new file mode 100644 index 0000000000..3c2980ba90 --- /dev/null +++ b/fftools/ffmpeg_mux.c @@ -0,0 +1,293 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "ffmpeg.h" + +#include "libavutil/fifo.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/log.h" +#include "libavutil/mem.h" +#include "libavutil/timestamp.h" + +#include "libavcodec/packet.h" + +#include "libavformat/avformat.h" +#include "libavformat/avio.h" + +static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others) +{ + int i; + for (i = 0; i < nb_output_streams; i++) { + OutputStream *ost2 = output_streams[i]; + ost2->finished |= ost == ost2 ? this_stream : others; + } +} + +void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, + int unqueue) +{ + AVFormatContext *s = of->ctx; + AVStream *st = ost->st; + int ret; + + /* + * Audio encoders may split the packets -- #frames in != #packets out. + * But there is no reordering, so we can limit the number of output packets + * by simply dropping them here. + * Counting encoded video frames needs to be done separately because of + * reordering, see do_video_out(). + * Do not count the packet when unqueued because it has been counted when queued. + */ + if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) && !unqueue) { + if (ost->frame_number >= ost->max_frames) { + av_packet_unref(pkt); + return; + } + ost->frame_number++; + } + + if (!of->header_written) { + AVPacket *tmp_pkt; + /* the muxer is not initialized yet, buffer the packet */ + if (!av_fifo_space(ost->muxing_queue)) { + size_t cur_size = av_fifo_size(ost->muxing_queue); + unsigned int are_we_over_size = + (ost->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold; + size_t limit = are_we_over_size ? ost->max_muxing_queue_size : INT_MAX; + size_t new_size = FFMIN(2 * cur_size, limit); + + if (new_size <= cur_size) { + av_log(NULL, AV_LOG_ERROR, + "Too many packets buffered for output stream %d:%d.\n", + ost->file_index, ost->st->index); + exit_program(1); + } + ret = av_fifo_realloc2(ost->muxing_queue, new_size); + if (ret < 0) + exit_program(1); + } + ret = av_packet_make_refcounted(pkt); + if (ret < 0) + exit_program(1); + tmp_pkt = av_packet_alloc(); + if (!tmp_pkt) + exit_program(1); + av_packet_move_ref(tmp_pkt, pkt); + ost->muxing_queue_data_size += tmp_pkt->size; + av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL); + return; + } + + if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) || + (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0)) + pkt->pts = pkt->dts = AV_NOPTS_VALUE; + + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + int i; + uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, + NULL); + ost->quality = sd ? AV_RL32(sd) : -1; + ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; + + for (i = 0; ierror); i++) { + if (sd && i < sd[5]) + ost->error[i] = AV_RL64(sd + 8 + 8*i); + else + ost->error[i] = -1; + } + + if (ost->frame_rate.num && ost->is_cfr) { + if (pkt->duration > 0) + av_log(NULL, AV_LOG_WARNING, "Overriding packet duration by frame rate, this should not happen\n"); + pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate), + ost->mux_timebase); + } + } + + av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base); + + if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) { + if (pkt->dts != AV_NOPTS_VALUE && + pkt->pts != AV_NOPTS_VALUE && + pkt->dts > pkt->pts) { + av_log(s, AV_LOG_WARNING, "Invalid DTS: %"PRId64" PTS: %"PRId64" in output stream %d:%d, replacing by guess\n", + pkt->dts, pkt->pts, + ost->file_index, ost->st->index); + pkt->pts = + pkt->dts = pkt->pts + pkt->dts + ost->last_mux_dts + 1 + - FFMIN3(pkt->pts, pkt->dts, ost->last_mux_dts + 1) + - FFMAX3(pkt->pts, pkt->dts, ost->last_mux_dts + 1); + } + if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) && + pkt->dts != AV_NOPTS_VALUE && + !(st->codecpar->codec_id == AV_CODEC_ID_VP9 && ost->stream_copy) && + ost->last_mux_dts != AV_NOPTS_VALUE) { + int64_t max = ost->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT); + if (pkt->dts < max) { + int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG; + if (exit_on_error) + loglevel = AV_LOG_ERROR; + av_log(s, loglevel, "Non-monotonous DTS in output stream " + "%d:%d; previous: %"PRId64", current: %"PRId64"; ", + ost->file_index, ost->st->index, ost->last_mux_dts, pkt->dts); + if (exit_on_error) { + av_log(NULL, AV_LOG_FATAL, "aborting.\n"); + exit_program(1); + } + av_log(s, loglevel, "changing to %"PRId64". This may result " + "in incorrect timestamps in the output file.\n", + max); + if (pkt->pts >= pkt->dts) + pkt->pts = FFMAX(pkt->pts, max); + pkt->dts = max; + } + } + } + ost->last_mux_dts = pkt->dts; + + ost->data_size += pkt->size; + ost->packets_written++; + + pkt->stream_index = ost->index; + + if (debug_ts) { + av_log(NULL, AV_LOG_INFO, "muxer <- type:%s " + "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s size:%d\n", + av_get_media_type_string(ost->enc_ctx->codec_type), + av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base), + av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base), + pkt->size + ); + } + + ret = av_interleaved_write_frame(s, pkt); + if (ret < 0) { + print_error("av_interleaved_write_frame()", ret); + main_return_code = 1; + close_all_output_streams(ost, MUXER_FINISHED | ENCODER_FINISHED, ENCODER_FINISHED); + } +} + +static int print_sdp(void) +{ + char sdp[16384]; + int i; + int j, ret; + AVIOContext *sdp_pb; + AVFormatContext **avc; + + for (i = 0; i < nb_output_files; i++) { + if (!output_files[i]->header_written) + return 0; + } + + avc = av_malloc_array(nb_output_files, sizeof(*avc)); + if (!avc) + exit_program(1); + for (i = 0, j = 0; i < nb_output_files; i++) { + if (!strcmp(output_files[i]->ctx->oformat->name, "rtp")) { + avc[j] = output_files[i]->ctx; + j++; + } + } + + if (!j) { + av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n"); + ret = AVERROR(EINVAL); + goto fail; + } + + ret = av_sdp_create(avc, j, sdp, sizeof(sdp)); + if (ret < 0) + goto fail; + + if (!sdp_filename) { + printf("SDP:\n%s\n", sdp); + fflush(stdout); + } else { + ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename); + goto fail; + } + + avio_print(sdp_pb, sdp); + avio_closep(&sdp_pb); + av_freep(&sdp_filename); + } + +fail: + av_freep(&avc); + return ret; +} + +/* open the muxer when all the streams are initialized */ +int of_check_init(OutputFile *of) +{ + int ret, i; + + for (i = 0; i < of->ctx->nb_streams; i++) { + OutputStream *ost = output_streams[of->ost_index + i]; + if (!ost->initialized) + return 0; + } + + ret = avformat_write_header(of->ctx, &of->opts); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, + "Could not write header for output file #%d " + "(incorrect codec parameters ?): %s\n", + of->index, av_err2str(ret)); + return ret; + } + //assert_avoptions(of->opts); + of->header_written = 1; + + av_dump_format(of->ctx, of->index, of->ctx->url, 1); + nb_output_dumped++; + + if (sdp_filename || want_sdp) { + ret = print_sdp(); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error writing the SDP.\n"); + return ret; + } + } + + /* flush the muxing queues */ + for (i = 0; i < of->ctx->nb_streams; i++) { + OutputStream *ost = output_streams[of->ost_index + i]; + + /* try to improve muxing time_base (only possible if nothing has been written yet) */ + if (!av_fifo_size(ost->muxing_queue)) + ost->mux_timebase = ost->st->time_base; + + while (av_fifo_size(ost->muxing_queue)) { + AVPacket *pkt; + av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL); + ost->muxing_queue_data_size -= pkt->size; + of_write_packet(of, pkt, ost, 1); + av_packet_free(&pkt); + } + } + + return 0; +} From patchwork Tue Jan 11 09:58: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: 33204 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3544695iog; Tue, 11 Jan 2022 01:59:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJy37RA+NP4dZXe6wcJFRyY1x8XKbqqaJ7bkBbyRTF+3wQxnxPD5hIg299dkcfB/IaSIw2JF X-Received: by 2002:a17:907:2cc2:: with SMTP id hg2mr3077537ejc.66.1641895154992; Tue, 11 Jan 2022 01:59:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895154; cv=none; d=google.com; s=arc-20160816; b=w0Oxst7qa/DjR7BfBO783gKlEo0IVjEAjxLPx/XclT4eLZCe8LMYOoCDMF/iqmVfyF kMLMrpxB/06KMYKKACGfduT9P9InuuLxHrs9VDHKt0ljuGk2Tfia9cG5jmeNJnxfrncv L7OzfPu85cPI+AM278422OYfPxlm9kcWz9sM53cMSlth5h7DMqwqxkr7luQJhVGxBH9B VPkI1JD+i9Btu8bmwcjXCyvk5xnzVPJxkOsubN+Igjab0DtBJp8HBhRMXFe3JRp0Rsoh 3LXRbp/mj0XnucSVs87J32VqwRuKBdcnSGbL5J6PBVNGjC1/SZ8pUQOppB6vcRZm+hw5 yPSw== 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=cwzHNeIIQtrlhSSwIQC0xznQha2bp88ValaXxfVE5H0=; b=so649M3VN48W59szAWSFMKPY8dZ32yNM3xlV7EqSnRoJqPyAqK+8Qv4sU7AQQ9fuCr UvA7RIZKXhPLW51VDvXDzxPTMlvguDEK1c0OerUu8sG8muzcPqd1nw27uNQmUrz7C4MP AQZ4JI7DfIGy8Q0FrpKF0sjf9CHAomCpbwTkdca6QivBX/72+Cp3fJEDSFWTgOyCRU1Z GM31KZxWJVs7P6ucyAn7VJXSZ6kBWasdG4pml3eN4vfjEJDcIonVwNDi3Mozf67MW/J8 G5LyZCHZWb7KnZLG5adhIMNXmqpOxiFQ9OqVHgst5QwMhtdgQHpSZxm5wWYiewZ144Dp QbLQ== 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 c26si5161878edy.386.2022.01.11.01.59.14; Tue, 11 Jan 2022 01:59:14 -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 A92C7680BA3; Tue, 11 Jan 2022 11:59:10 +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 23AFF680BA3 for ; Tue, 11 Jan 2022 11:59:04 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4C7BA240694 for ; Tue, 11 Jan 2022 10:59:03 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id JWcjXAE2DFeN for ; Tue, 11 Jan 2022 10:59:02 +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 3EE3F24017E for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id D9BC23A0743; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:06 +0100 Message-Id: <20220111095830.31542-4-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 04/28] ffmpeg: move writing the trailer to ffmpeg_mux.c 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: Sn1sMHtiirF9 --- fftools/ffmpeg.c | 16 +++------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_mux.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index e0aa533dc9..87e8b0be59 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -4440,19 +4440,9 @@ static int transcode(void) /* write the trailer if needed */ for (i = 0; i < nb_output_files; i++) { - os = output_files[i]->ctx; - if (!output_files[i]->header_written) { - av_log(NULL, AV_LOG_ERROR, - "Nothing was written into output file %d (%s), because " - "at least one of its streams received no packets.\n", - i, os->url); - continue; - } - if ((ret = av_write_trailer(os)) < 0) { - av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", os->url, av_err2str(ret)); - if (exit_on_error) - exit_program(1); - } + ret = of_write_trailer(output_files[i]); + if (ret < 0 && exit_on_error) + exit_program(1); } /* dump report by using the first video and audio streams */ diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index fed34b06f8..91c313d8ef 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -686,6 +686,7 @@ int hwaccel_decode_init(AVCodecContext *avctx); /* open the muxer when all the streams are initialized */ int of_check_init(OutputFile *of); +int of_write_trailer(OutputFile *of); void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 3c2980ba90..c65ed3631a 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -291,3 +291,24 @@ int of_check_init(OutputFile *of) return 0; } + +int of_write_trailer(OutputFile *of) +{ + int ret; + + if (!of->header_written) { + av_log(NULL, AV_LOG_ERROR, + "Nothing was written into output file %d (%s), because " + "at least one of its streams received no packets.\n", + of->index, of->ctx->url); + return AVERROR(EINVAL); + } + + ret = av_write_trailer(of->ctx); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", of->ctx->url, av_err2str(ret)); + return ret; + } + + return 0; +} From patchwork Tue Jan 11 09:58:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33206 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3544866iog; Tue, 11 Jan 2022 01:59:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJz92eCuXIz6hCWD8hCXMFC5cPHZko5vhXYCamN06AHveauFLohk/cxBguiuo5GnhWRR6Ojw X-Received: by 2002:a05:6402:1907:: with SMTP id e7mr3557866edz.44.1641895174645; Tue, 11 Jan 2022 01:59:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895174; cv=none; d=google.com; s=arc-20160816; b=ITnDZEr/PrHx2GlX9yxNZe8a2mtUEyBYfQrszJk+PBWzgE+Zy/F1wDJCKE7sU5CHtJ kZ/mwT9/7BEQBUUhM+fYaXwopNOqWrlV6KT6G/ysuSclVLnctQ/I+T0TxkcyNBOcf3y2 xNQQYh6sZHQJyIK+Cx6xtGBK2o32xsdrDfhWelgpyS7TcJ9I4ge4BD4r0lgPJT8CuPbc VVwYaM54pOq8+Jw9OD4uTW714Cv4bIWdTjdcnqQXiPdEQ2WskW1EKt67EEAFhzQRMPqC seoJ/2SZWeQGrhVrxadXoWYSzkuElobCGks9tLmmmt3sZP1ftBfN29cPGXoHmMA2G+yE 3rCw== 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=rdZb+jeMPRdhb92sqUDGNKVcAXUeHFlzJ+xy3FFBaBM=; b=D08zXildAhMbs27Wpf5cC1dJd1BsFJI4UKLvwXhTZrAcv7057tl2NXOCUQSh0xHu8d dV+Dz1N3QGGQSp/gmzdwQOYLlDApgqbOyzy0Q2xxvWuRcKnDEbPSJ40Zq85mfsISP+wZ SJfHVxEZLh4twrAff0Jj3V2E866zSThgn3/j3KYBHTqE/ddr+54NS0Zh3TNi9L8qX7v1 7bH1WV7es9FfPRVK0zPOtcH3LkmZvfWQ88mioS+PioO2x3lOQlCm+rKiXBRo3PmHnsCK G2YATH+skK5R8JSxOOqWOUcCcEvquDSFBL0x6o/8p4Qelia6Hvy2aPmvvmpHkNBvC3Jn Tiag== 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 z7si4858582edb.528.2022.01.11.01.59.34; Tue, 11 Jan 2022 01:59:34 -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 5FB8868AEB1; Tue, 11 Jan 2022 11:59:12 +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 543E5680134 for ; Tue, 11 Jan 2022 11:59:05 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 163C0240179 for ; Tue, 11 Jan 2022 10:59:05 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QOUrbO3uRqM7 for ; Tue, 11 Jan 2022 10:59:03 +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 448D92404FE for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id DE3F93A0746; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:07 +0100 Message-Id: <20220111095830.31542-5-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 05/28] ffmpeg: move freeing the output file to ffmpeg_mux.c 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: ZQJJtlRCJe12 --- fftools/ffmpeg.c | 14 ++------------ fftools/ffmpeg.h | 1 + fftools/ffmpeg_mux.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 87e8b0be59..320ab8e0ca 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -567,19 +567,9 @@ static void ffmpeg_cleanup(int ret) av_freep(&subtitle_out); /* close files */ - for (i = 0; i < nb_output_files; i++) { - OutputFile *of = output_files[i]; - AVFormatContext *s; - if (!of) - continue; - s = of->ctx; - if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE)) - avio_closep(&s->pb); - avformat_free_context(s); - av_dict_free(&of->opts); + for (i = 0; i < nb_output_files; i++) + of_close(&output_files[i]); - av_freep(&output_files[i]); - } for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 91c313d8ef..288e0f2981 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -687,6 +687,7 @@ int hwaccel_decode_init(AVCodecContext *avctx); /* open the muxer when all the streams are initialized */ int of_check_init(OutputFile *of); int of_write_trailer(OutputFile *of); +void of_close(OutputFile **pof); void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index c65ed3631a..12ee3c2357 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -312,3 +312,20 @@ int of_write_trailer(OutputFile *of) return 0; } + +void of_close(OutputFile **pof) +{ + OutputFile *of = *pof; + AVFormatContext *s; + + if (!of) + return; + + s = of->ctx; + if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE)) + avio_closep(&s->pb); + avformat_free_context(s); + av_dict_free(&of->opts); + + av_freep(pof); +} From patchwork Tue Jan 11 09:58:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33209 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3545179iog; Tue, 11 Jan 2022 02:00:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpIJowALfYqVfcROGhUwRfGB1jN02NEgbuFGoT3jKJLJoCJAVOAJaI5fn/07RSmMYfJoDf X-Received: by 2002:a17:906:9746:: with SMTP id o6mr2961541ejy.112.1641895206845; Tue, 11 Jan 2022 02:00:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895206; cv=none; d=google.com; s=arc-20160816; b=p30eFic+SWhoh9xkWVJ726rZ//lTeWhtzXDRTZrv9UGn1C+LZ9iubWlDVBfvj7Ervy vpIqluAt91xJWGpL6kuCAhNYThHVOehyHerpR+FwRD8+nHLTGm7FSlrW3NOTrGKZ6lIf vRJ0w55y2zLOMOZi6Fcu7n+7KEQgqQk0ystFa2wxrCz8KE9w47nCkJslcJd3TzcmATl+ OfmI2YNkfNGD5kv28vfQdZSI9QD2bk08mnE54EI5Pwhukz3tN7l1ozELaLUCZ9pn5Mqg xJt+/H7y96HMGlB13pQAnKJVK7cec3SCXcwY2N+Zx5M9lFvQO5jNw6nULis8JjsWjBll CJeQ== 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=X4fvtv8nradEpXVpRtjLf7yweYavpYfvXabkxtERNbI=; b=rKj8ZZiHguuDxc7J/3S+nxE8wCXGVvQbM3MJKWMd3GQ3YE28m+5K4AOqQ1pbsy7tan BZ3BWbxaI3Z92ZPB4mfIQbAvmzTxWqztH8Z4mdad1UP4GNMVj90G2VBlScLOO1akOKp+ UzY2xiVmiItfwkafTk5urzXMrFYR8mvnCPIWZpWCKy5/4BIOX+qcSwotB/7ZT2BQF9YW YlYCIaeqOUzu3PrDVRR79E3Av2Z2nME42tYC0BArjbndB6oT1rxMu7QCgqxoY3B8jtP+ 1cnpd02OZj85yGYpahGAzWNMKNB1Drtj9yrxLd48nBQLpGtwE4WYD+qRD5hSntWB8JjZ wENw== 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 l14si1919155edb.393.2022.01.11.02.00.06; Tue, 11 Jan 2022 02:00:06 -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 0CA5C68AF82; Tue, 11 Jan 2022 11:59:16 +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 59FA268AF3A for ; Tue, 11 Jan 2022 11:59:09 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id ACEEA2404FE for ; Tue, 11 Jan 2022 10:59:05 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id o-nXkRfQVZvj for ; Tue, 11 Jan 2022 10:59:05 +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 4D3A2240506 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id E29873A0769; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:08 +0100 Message-Id: <20220111095830.31542-6-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 06/28] ffmpeg: store output format separately from the muxer context 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: duxieiID4S/2 Allows accessing it without going through the muxer context. This will be useful in the following commits, where the muxer context will be hidden. --- fftools/ffmpeg.c | 18 ++++++++++-------- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_opt.c | 1 + 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 320ab8e0ca..9360c8a475 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2783,9 +2783,9 @@ static int init_output_stream_streamcopy(OutputStream *ost) if (!codec_tag) { unsigned int codec_tag_tmp; - if (!of->ctx->oformat->codec_tag || - av_codec_get_id (of->ctx->oformat->codec_tag, par_src->codec_tag) == par_src->codec_id || - !av_codec_get_tag2(of->ctx->oformat->codec_tag, par_src->codec_id, &codec_tag_tmp)) + if (!of->format->codec_tag || + av_codec_get_id (of->format->codec_tag, par_src->codec_tag) == par_src->codec_id || + !av_codec_get_tag2(of->format->codec_tag, par_src->codec_id, &codec_tag_tmp)) codec_tag = par_src->codec_tag; } @@ -2803,7 +2803,7 @@ static int init_output_stream_streamcopy(OutputStream *ost) else ost->st->avg_frame_rate = ist->st->avg_frame_rate; - ret = avformat_transfer_internal_stream_timing_info(of->ctx->oformat, ost->st, ist->st, copy_tb); + ret = avformat_transfer_internal_stream_timing_info(of->format, ost->st, ist->st, copy_tb); if (ret < 0) return ret; @@ -3005,7 +3005,8 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) InputStream *ist = get_input_stream(ost); AVCodecContext *enc_ctx = ost->enc_ctx; AVCodecContext *dec_ctx = NULL; - AVFormatContext *oc = output_files[ost->file_index]->ctx; + OutputFile *of = output_files[ost->file_index]; + AVFormatContext *oc = of->ctx; int ret; set_encoder_id(output_files[ost->file_index], ost); @@ -3065,7 +3066,8 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) if (!(enc_ctx->time_base.num && enc_ctx->time_base.den)) enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter); if ( av_q2d(enc_ctx->time_base) < 0.001 && video_sync_method != VSYNC_PASSTHROUGH - && (video_sync_method == VSYNC_CFR || video_sync_method == VSYNC_VSCFR || (video_sync_method == VSYNC_AUTO && !(oc->oformat->flags & AVFMT_VARIABLE_FPS)))){ + && (video_sync_method == VSYNC_CFR || video_sync_method == VSYNC_VSCFR || + (video_sync_method == VSYNC_AUTO && !(of->format->flags & AVFMT_VARIABLE_FPS)))){ av_log(oc, AV_LOG_WARNING, "Frame rate very high for a muxer not efficiently supporting it.\n" "Please consider specifying a lower framerate, a different muxer or -vsync 2\n"); } @@ -3398,7 +3400,7 @@ static int transcode_init(void) /* write headers for files with no streams */ for (i = 0; i < nb_output_files; i++) { oc = output_files[i]->ctx; - if (oc->oformat->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) { + if (output_files[i]->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) { ret = of_check_init(output_files[i]); if (ret < 0) goto dump_format; @@ -4605,7 +4607,7 @@ int main(int argc, char **argv) } for (i = 0; i < nb_output_files; i++) { - if (strcmp(output_files[i]->ctx->oformat->name, "rtp")) + if (strcmp(output_files[i]->format->name, "rtp")) want_sdp = 0; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 288e0f2981..c28acad4f1 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -576,6 +576,8 @@ typedef struct OutputStream { typedef struct OutputFile { int index; + const AVOutputFormat *format; + AVFormatContext *ctx; AVDictionary *opts; int ost_index; /* index of the first stream in output_streams */ diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index e8db515e0c..433102bb49 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2301,6 +2301,7 @@ static int open_output_file(OptionsContext *o, const char *filename) } of->ctx = oc; + of->format = oc->oformat; if (o->recording_time != INT64_MAX) oc->duration = o->recording_time; From patchwork Tue Jan 11 09:58:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33208 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3545062iog; Tue, 11 Jan 2022 01:59:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyrnYHT96rMRxATQdgPXCpc8y+oWn6zcWmABB1e48vRoklwZL23MvUBwcfSQLnsi6pAbsTP X-Received: by 2002:a17:906:1ccc:: with SMTP id i12mr2974078ejh.154.1641895196713; Tue, 11 Jan 2022 01:59:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895196; cv=none; d=google.com; s=arc-20160816; b=NoI8N1np4VMrz38zabkYaUWvQtM5FUJamX5bQjYmHP7if3NU+XH3lrYmTNPenaN18a 8XPleoqvZ5L0btXfjAWeaP5SbEngJcta7OsdEKV4Zxb8S1WUxHo2Fx41yUTm08APOy3Z e2WeLAqx7nHgEX5eFi9ASKLUh6MaIY0VPeCrG8q8X8KNdwAmNXyf8+KBq1Wuj/SvKzKA PlB7lGdkkpAl2iDsfgOSQ9bOif7zmfG/LQRJc9n/28PtNwG56qOqNYKLeqMp4OuzmvHx Foh733FyNagTuHsSZPEJGDvAvOf/QHJegcI7+1tqEFyWfmqUG8gZMziHSeJqyqCVEpyK i17g== 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=etUP6NlYjWDlWWKP7ruvbZiwKWHf2f4PJHQFoLcwFJ8=; b=a7h9VYBaFMSTz1q1ZVdltKNxeaAozmTwoMr/+dIbY8Lg7M/Y6rN4WiKSbDWjBjUMca jS3T7nBCYcjoLcKKKIV0W55PEnyRzIgSTEDyQn/xKdnn2CfBTL4ic8BERSaF+esAu0zG BeDKCqJULUhQY8hGitq2TQPk39kQUNB0GQTP295WUc7I/Tv+1emm0GBQtScYqIECdaSJ QGheIaO6dEuUNTN6JqkbnVwer09y+G4yGoNIDYxPDlXDmECuE/zM6gWm0ng8iKjWz5aY M0Awa7Vl6+gTP9NR8S62zmHX+eWV9wXFds/rVG1nE9O/lNIgsNGW2XqO+47dmqYTY/+5 9mXw== 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 q6si4643998edt.543.2022.01.11.01.59.56; Tue, 11 Jan 2022 01:59:56 -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 1A0E968AF36; Tue, 11 Jan 2022 11:59:14 +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 AFC7368AEAF for ; Tue, 11 Jan 2022 11:59:05 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 759B024017C for ; Tue, 11 Jan 2022 10:59:05 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 5tn4B4BPIyMl for ; Tue, 11 Jan 2022 10:59:05 +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 6C58C240507 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id E75523A078F; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:09 +0100 Message-Id: <20220111095830.31542-7-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 07/28] ffmpeg_mux: add private muxer context 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: Dm7j2Q5dRHVz Move header_written into it, which is not (and should not be) used by any code outside of ffmpeg_mux. In the future this context will contain more muxer-private state that should not be visible to other code. --- fftools/ffmpeg.h | 6 ++++-- fftools/ffmpeg_mux.c | 26 ++++++++++++++++++++++---- fftools/ffmpeg_opt.c | 6 ++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index c28acad4f1..279a99cc48 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -573,9 +573,12 @@ typedef struct OutputStream { int64_t error[4]; } OutputStream; +typedef struct Muxer Muxer; + typedef struct OutputFile { int index; + Muxer *mux; const AVOutputFormat *format; AVFormatContext *ctx; @@ -586,8 +589,6 @@ typedef struct OutputFile { uint64_t limit_filesize; /* filesize limit expressed in bytes */ int shortest; - - int header_written; } OutputFile; extern InputStream **input_streams; @@ -686,6 +687,7 @@ int hw_device_setup_for_filter(FilterGraph *fg); int hwaccel_decode_init(AVCodecContext *avctx); +int of_muxer_init(OutputFile *of); /* open the muxer when all the streams are initialized */ int of_check_init(OutputFile *of); int of_write_trailer(OutputFile *of); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 12ee3c2357..538f153484 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -32,6 +32,10 @@ #include "libavformat/avformat.h" #include "libavformat/avio.h" +struct Muxer { + int header_written; +}; + static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others) { int i; @@ -64,7 +68,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, ost->frame_number++; } - if (!of->header_written) { + if (!of->mux->header_written) { AVPacket *tmp_pkt; /* the muxer is not initialized yet, buffer the packet */ if (!av_fifo_space(ost->muxing_queue)) { @@ -195,7 +199,7 @@ static int print_sdp(void) AVFormatContext **avc; for (i = 0; i < nb_output_files; i++) { - if (!output_files[i]->header_written) + if (!output_files[i]->mux->header_written) return 0; } @@ -259,7 +263,7 @@ int of_check_init(OutputFile *of) return ret; } //assert_avoptions(of->opts); - of->header_written = 1; + of->mux->header_written = 1; av_dump_format(of->ctx, of->index, of->ctx->url, 1); nb_output_dumped++; @@ -296,7 +300,7 @@ int of_write_trailer(OutputFile *of) { int ret; - if (!of->header_written) { + if (!of->mux->header_written) { av_log(NULL, AV_LOG_ERROR, "Nothing was written into output file %d (%s), because " "at least one of its streams received no packets.\n", @@ -327,5 +331,19 @@ void of_close(OutputFile **pof) avformat_free_context(s); av_dict_free(&of->opts); + av_freep(&of->mux); + av_freep(pof); } + +int of_muxer_init(OutputFile *of) +{ + Muxer *mux = av_mallocz(sizeof(*mux)); + + if (!mux) + return AVERROR(ENOMEM); + + of->mux = mux; + + return 0; +} diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 433102bb49..2ed09d4a7a 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2886,6 +2886,12 @@ loop_end: exit_program(1); } + err = of_muxer_init(of); + if (err < 0) { + av_log(NULL, AV_LOG_FATAL, "Error initializing internal muxing state\n"); + exit_program(1); + } + return 0; } 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; +} From patchwork Tue Jan 11 09:58:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33226 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547558iog; Tue, 11 Jan 2022 02:03:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzd40lcYJzGHZn4fFAIViT+9unByUex5dI8f48DrVoYAjBTM27jPllhyxvkueFgRRX5MVpA X-Received: by 2002:a17:906:608:: with SMTP id s8mr3217005ejb.754.1641895391446; Tue, 11 Jan 2022 02:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895391; cv=none; d=google.com; s=arc-20160816; b=lelzLO0udrJyIIwaKeAbJL1VA0/RzlXZtfeerK661z3tzP0ofqXYsN/ISwTtp/KSKY 4g/k4qEiOQ5auZbA/4J1rn0BUR9EQ3zQE2kDtdVbxThF9iwr5ruNDtlfs3tr8OajG9Y/ ylvkxhVMO191s1iEiS0GPXBqeXfrf3zzh74FvQ8V1D7h9F0337ZGSTw14/LZBTMTTDTX rxufg9XSRhzdnbMHbOEJ5v7yABxAgmBE8oAm3juqgICWVB7edB33PD7p/jvQy2360ikP VO6ohtd+fl/rxiO5n+iQTKNHj5iSzW2mCwzxrxNGZFOn4317E4gwLXqOB0MzhZc6hZKC 8Jjw== 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=UMLgllH6Xuzd3kCNZDTMeKhHlEZDnnRAjJ5bbMUYlu8=; b=dBaRaAwxm1A140bU5du3sjQgj6xV0a1A3Z9c9JG9NcFpWTW2o5HvkjAiZgTUtRy1gO 6XRmdD0ZCisHMJGvLWwMm/Xoy5IM+tLFkgnN9RetcvhEduo+TZm/jNVVLhnCGyH36iVf Xdh0V1qdU7e8gXgvQgSKusjkEgHaGquxy6vV5SCEngEN0DyZtI0coBtY/V+JLOoN4w/H aAnd49zUBuTGyU8o9ksmgTGZ/yLc3ZzWffL8KNtQJDNphJWw7Fnl6/yRNCH8S6xDuo0y XuqjiFuhI9GIQ7o5veJGQBzx/F7cDtXNk6kp2IG8DBch+2J9DaNS2lAT2zae+IvNoPDc hyyQ== 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 o17si4691406ejy.466.2022.01.11.02.03.11; Tue, 11 Jan 2022 02:03:11 -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 5E8FB68B009; Tue, 11 Jan 2022 11:59:32 +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 90B1E68AF45 for ; Tue, 11 Jan 2022 11:59:10 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CEA0024052D for ; Tue, 11 Jan 2022 10:59:07 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id mHdeKMZPG3Eq for ; Tue, 11 Jan 2022 10:59:07 +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 94D86240555 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id EFB6C3A09CE; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:11 +0100 Message-Id: <20220111095830.31542-9-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 09/28] ffmpeg: fix the type of limit_filesize 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: FTCEaNklTC+/ The option is parsed as INT64 (signed). It is also compared to the output of avio_tell(), which is also int64_t. --- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_opt.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index dfcaa875d9..80b90e372d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -145,7 +145,7 @@ typedef struct OptionsContext { int64_t recording_time; int64_t stop_time; - uint64_t limit_filesize; + int64_t limit_filesize; float mux_preload; float mux_max_delay; int shortest; @@ -586,7 +586,7 @@ typedef struct OutputFile { int ost_index; /* index of the first stream in output_streams */ int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units - uint64_t limit_filesize; /* filesize limit expressed in bytes */ + int64_t limit_filesize; /* filesize limit expressed in bytes */ int shortest; } OutputFile; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 2ed09d4a7a..4d2b80683e 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -220,7 +220,7 @@ static void init_options(OptionsContext *o) o->start_time = AV_NOPTS_VALUE; o->start_time_eof = AV_NOPTS_VALUE; o->recording_time = INT64_MAX; - o->limit_filesize = UINT64_MAX; + o->limit_filesize = INT64_MAX; o->chapters_input_file = INT_MAX; o->accurate_seek = 1; o->thread_queue_size = -1; From patchwork Tue Jan 11 09:58:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33211 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3545507iog; Tue, 11 Jan 2022 02:00:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1CL+X90jesMPYuvcU/PIAlfJz1agswTx3MBivNx/c3CQ96QfFqr0MJBuB0dBVlLPhtCoZ X-Received: by 2002:a17:907:3fa0:: with SMTP id hr32mr3145229ejc.196.1641895229168; Tue, 11 Jan 2022 02:00:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895229; cv=none; d=google.com; s=arc-20160816; b=Ed7B77rG5HQFnQDVVOaeKQpym6W6xYro90fk5cVXdrsx7AvNxuCyEFB9JaWx0HUsuF 4Q921xJeP8rDN1lamGbBa2fpdoN57THus8GsBn/Ym6DT6txgVmAGbB6RKV5AT7t8AEax uoqS19SDpPIFyZl02DNvwHRuOcbWWZWgYj8DZc+9x65ZHOSQbsfbr60LNmPIDfRpLPO5 pOAAsGW2XgV/t5BblA8q7bMTntmwPfjIqY+Zfz4quS2sFYMZ23rJXplVt3LV438CYkUY Re6KSp5Gr94ugzkpsYVj3VpeCKFmY7auwOBdyqlI5mRD9JkxkCCwe8MYuUrZl0WNzFne /tzA== 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=u0QGZ+MpkSAc/rGLhxXI/KJGTInvm3s0ZJbgpFVljGs=; b=YP5qwWEAWEOuODzF9anuCsfr50g23T2y2UmROWjxffa+szUB9vFPjRw42g/jHSFzas EYYZO/fvnLUGqr8XlTVBVnWaCx0R9phlEtPRDOX8RwxUUgnPcLakh5hYBh8RoFCMifiG cvyM7+bv0pmfSnOAiOLXQsfletDIB48UsiK0OCpkkbnByOLu8tB/XNQ0serYOVF7gF41 /sCzrWwmy2E0+svNWwdWpyc0IBfE/U4gEZdQzeMNuuVRWf/YC+nEG0eWRAyoP/u/zHa/ 86Tew28fDJF9pn53nWkIBaRGLUkuLNoWd7JkisfTXwoirBJRrbimx3+//k0L2hCXXJsU xxZQ== 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 x12si33848edd.118.2022.01.11.02.00.28; Tue, 11 Jan 2022 02:00:29 -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 0FD2968AF96; Tue, 11 Jan 2022 11:59:18 +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 640B068AF3E for ; Tue, 11 Jan 2022 11:59:09 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 51A15240507 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 rO1yYBrt-Ilu for ; Tue, 11 Jan 2022 10:59:05 +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 9282624052D for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id F3F883A09DE; Tue, 11 Jan 2022 10:59:01 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:12 +0100 Message-Id: <20220111095830.31542-10-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 10/28] ffmpeg: refactor limiting output file size with -fs 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: lPWk6X8f2b15 Move the file size checking code to ffmpeg_mux. Use the recently introduced of_filesize(), making this code consistent with the size shown by print_report(). --- fftools/ffmpeg.c | 4 +--- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_mux.c | 11 ++++++++++- fftools/ffmpeg_opt.c | 3 +-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1b5cf4d9af..37c4a0d285 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3501,10 +3501,8 @@ static int need_output(void) for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; OutputFile *of = output_files[ost->file_index]; - AVFormatContext *os = output_files[ost->file_index]->ctx; - if (ost->finished || - (os->pb && avio_tell(os->pb) >= of->limit_filesize)) + if (ost->finished || of_finished(of)) continue; if (ost->frame_number >= ost->max_frames) { int j; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 80b90e372d..cae9800da3 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -586,7 +586,6 @@ typedef struct OutputFile { int ost_index; /* index of the first stream in output_streams */ int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units - int64_t limit_filesize; /* filesize limit expressed in bytes */ int shortest; } OutputFile; @@ -687,7 +686,7 @@ int hw_device_setup_for_filter(FilterGraph *fg); int hwaccel_decode_init(AVCodecContext *avctx); -int of_muxer_init(OutputFile *of); +int of_muxer_init(OutputFile *of, int64_t limit_filesize); /* open the muxer when all the streams are initialized */ int of_check_init(OutputFile *of); int of_write_trailer(OutputFile *of); @@ -695,6 +694,7 @@ void of_close(OutputFile **pof); void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue); +int of_finished(OutputFile *of); int64_t of_filesize(OutputFile *of); #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 7c8414ac93..aff40776f6 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -33,6 +33,8 @@ #include "libavformat/avio.h" struct Muxer { + /* filesize limit expressed in bytes */ + int64_t limit_filesize; int header_written; }; @@ -336,7 +338,7 @@ void of_close(OutputFile **pof) av_freep(pof); } -int of_muxer_init(OutputFile *of) +int of_muxer_init(OutputFile *of, int64_t limit_filesize) { Muxer *mux = av_mallocz(sizeof(*mux)); @@ -345,9 +347,16 @@ int of_muxer_init(OutputFile *of) of->mux = mux; + mux->limit_filesize = limit_filesize; + return 0; } +int of_finished(OutputFile *of) +{ + return of_filesize(of) >= of->mux->limit_filesize; +} + int64_t of_filesize(OutputFile *of) { AVIOContext *pb = of->ctx->pb; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 4d2b80683e..0b4f437912 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2287,7 +2287,6 @@ static int open_output_file(OptionsContext *o, const char *filename) of->ost_index = nb_output_streams; of->recording_time = o->recording_time; of->start_time = o->start_time; - of->limit_filesize = o->limit_filesize; of->shortest = o->shortest; av_dict_copy(&of->opts, o->g->format_opts, 0); @@ -2886,7 +2885,7 @@ loop_end: exit_program(1); } - err = of_muxer_init(of); + err = of_muxer_init(of, o->limit_filesize); if (err < 0) { av_log(NULL, AV_LOG_FATAL, "Error initializing internal muxing state\n"); exit_program(1); From patchwork Tue Jan 11 09:58:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33228 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547832iog; Tue, 11 Jan 2022 02:03:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkuUGUn0opS8kTxwZbfgDjDCPpQtbDGElvztDdFlTksady8qaqK/uSJ2WwYWmAkml4pVTU X-Received: by 2002:a05:6402:100e:: with SMTP id c14mr3464342edu.196.1641895413015; Tue, 11 Jan 2022 02:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895413; cv=none; d=google.com; s=arc-20160816; b=bGTj4qog81W9tzDO9WrqJ+uiW4vrKrqae5/PxjRHkTzsp5L1MQSukpwkP1A47xLnWI gwO85/wQ4LdfMnbuXMHNJkhdXzU1X6Xubq/G4x3tvAa19AdR8xCqctHews5/XbJdb7Hb b1Zj+QeeRkL3zAwx03N+7EIrSFRubCWN4BX7ogGoPgMsb5Y8opEOWE7PVog34fyQbXEb JTFhVsjha/aI5Hj12DTFtAfHedHfbj45Guuey4KrFLBZ9DYoqg9nSi82eMEQNk9FRpB7 q2WCBfP4JTj6cbj+VLpA9pzumsS6sE1jVIELCxfcgqK1g9PcpihO2bVRoa8pFNH/3KGu lFhg== 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=UuH+y04YQHAHq1/J8/2IaCeo83vehhNTcX3YdL2Z4X0=; b=UNeMzqDlTMK6iaIJ4smADUy61jpyxMgm0l36kUp5rxc9lxDttPQEajqTgAQGf/Wi0I 10z9Q5y+kw4EYtsvON91vRYZKAjc62PW0zC0n1JSOih0g2r7Iv7LCTDP3o8lozxdtErC 8hvp+aClpsZbCLPceB/KGGtOichhn0jh/JRsz0tg/H7HEOmJEIEkFd9IxtNeCyncKDft NOS6KXGwnC+o7YNpI0RfISWEaatquZ7z6PlSw6jOIwAeXysdRbXsVDmVRf8ydcgbGnP7 kjIyv2hdj5A3J52C8uDEMbdhIXdEH5B9IWjylyQquJOu3e3T0vKOBcQkm8NwO+cqvxNM Vqtw== 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 nb41si3675184ejc.104.2022.01.11.02.03.32; Tue, 11 Jan 2022 02:03:33 -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 3FD4368B017; Tue, 11 Jan 2022 11:59:34 +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 9D1AA68AF4F for ; Tue, 11 Jan 2022 11:59:10 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 34BF5240555 for ; Tue, 11 Jan 2022 10:59:08 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Rq1GBd5Cf53R for ; Tue, 11 Jan 2022 10:59:05 +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 90E58240512 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 045D53A067C; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:13 +0100 Message-Id: <20220111095830.31542-11-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 11/28] ffmpeg: set want_sdp when initializing the muxer 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: Cfim+367HGrK Allows making the variable local to ffmpeg_mux. --- fftools/ffmpeg.c | 9 +-------- fftools/ffmpeg.h | 1 - fftools/ffmpeg_mux.c | 5 +++++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 37c4a0d285..d856b5b38f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -138,8 +138,6 @@ static int nb_frames_drop = 0; static int64_t decode_error_stat[2]; unsigned nb_output_dumped = 0; -int want_sdp = 1; - static BenchmarkTimeStamps current_time; AVIOContext *progress_avio = NULL; @@ -4553,7 +4551,7 @@ static void log_callback_null(void *ptr, int level, const char *fmt, va_list vl) int main(int argc, char **argv) { - int i, ret; + int ret; BenchmarkTimeStamps ti; init_dynload(); @@ -4596,11 +4594,6 @@ int main(int argc, char **argv) exit_program(1); } - for (i = 0; i < nb_output_files; i++) { - if (strcmp(output_files[i]->format->name, "rtp")) - want_sdp = 0; - } - current_time = ti = get_benchmark_time_stamps(); if (transcode() < 0) exit_program(1); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index cae9800da3..d926254a73 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -646,7 +646,6 @@ extern char *qsv_device; #endif extern HWDevice *filter_hw_device; -extern int want_sdp; extern unsigned nb_output_dumped; extern int main_return_code; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index aff40776f6..6c3052ebe1 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -38,6 +38,8 @@ struct Muxer { int header_written; }; +static int want_sdp = 1; + static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others) { int i; @@ -349,6 +351,9 @@ int of_muxer_init(OutputFile *of, int64_t limit_filesize) mux->limit_filesize = limit_filesize; + if (strcmp(of->format->name, "rtp")) + want_sdp = 0; + return 0; } From patchwork Tue Jan 11 09:58:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33225 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547424iog; Tue, 11 Jan 2022 02:03:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaP6LjW8bNCBFGqymTNnK+6Hynq8pWROwSqofGc5wE2mDcSFQv3cvtuqUIQaeBcM6AQsKD X-Received: by 2002:a17:907:1c8c:: with SMTP id nb12mr2922051ejc.433.1641895380080; Tue, 11 Jan 2022 02:03:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895380; cv=none; d=google.com; s=arc-20160816; b=sK21j2YMHxNbgmZPbWb1Gk0rsNyRfme0hwOvXwvFaK+EI53CVP4M9eKYaSt9m3N3Oq 4gxPcIwP83yCTj8XSkZoww8j07go3+oEY0giRoDIZ0uCdu69/WNutB8EEhKqzOKvkgG4 1zk56Xwaehvp/roIJi5GlBfDwu6VxCKfpLII8IcblLlW+lxLKOYFrA9OOjZLA9s9vAyu 3owxIOVPBkp3Qw/rvX2rBMwf1e33VppBjvhUCDmBdNXn9Hbsq2gyngpMB6RmUbTWM6Cu cND95bE7cLcuj24ATI6svofptzt+MDTLj+gkYcEBLwa5/IRxzocM4flVe7H5U1Kt64UF U3ng== 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=gBZDlCxx8O4CWYyszZnsCtAWOzG5tTwCFeRZEGJFL0Q=; b=W5/DuIgp9JQi2xlhxC31w2b3GmqZtTziRbqp5mtDRUxto6TALfBaYNn/1MukS9p+VP iPj407/SPLg9b8R0dDi8Nzdz7SC/VSupyte1f3a7Lx1XX1Jdd7yVeY124xKXUPnZEbHR fjVgVnTxWdgGT4f+HOpQ51SeCc1McZFHEiBEV5zIMUaPFgsD6h7DftUHSE97n07AJnWF qSb4wkihEIO+PFvxvNLF/8hZ3iPwIyO0vSk6dntkIOOxrFefOB60Vd92JS+wSdeG7AYC VZWbKMS9Ri0JdxOkpw+VCtiHXiAmDBpCCPrz3LSGC2YZFBV9PZqZQ5dekWdtSZExZPP6 AmXg== 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 n10si5638559edx.397.2022.01.11.02.02.59; Tue, 11 Jan 2022 02:03:00 -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 7ABCF68B002; Tue, 11 Jan 2022 11:59:31 +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 8AF0F68AF56 for ; Tue, 11 Jan 2022 11:59:10 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5DBE6240511 for ; Tue, 11 Jan 2022 10:59:07 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ylKaZ1XFEcu4 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 9546B24055A for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 0814C3A09E6; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:14 +0100 Message-Id: <20220111095830.31542-12-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 12/28] ffmpeg: write the header for stream-less outputs when initializing the muxer 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: tliv2xMLrzqa There is no reason to delay this. --- fftools/ffmpeg.c | 11 ----------- fftools/ffmpeg_mux.c | 7 +++++++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d856b5b38f..f28cc17f51 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3313,7 +3313,6 @@ static void report_new_stream(int input_index, AVPacket *pkt) static int transcode_init(void) { int ret = 0, i, j, k; - AVFormatContext *oc; OutputStream *ost; InputStream *ist; char error[1024] = {0}; @@ -3387,16 +3386,6 @@ static int transcode_init(void) } } - /* write headers for files with no streams */ - for (i = 0; i < nb_output_files; i++) { - oc = output_files[i]->ctx; - if (output_files[i]->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) { - ret = of_check_init(output_files[i]); - if (ret < 0) - goto dump_format; - } - } - dump_format: /* dump the stream mapping */ av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 6c3052ebe1..3b322ecb71 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -354,6 +354,13 @@ int of_muxer_init(OutputFile *of, int64_t limit_filesize) if (strcmp(of->format->name, "rtp")) want_sdp = 0; + /* write the header for files with no streams */ + if (of->format->flags & AVFMT_NOSTREAMS && of->ctx->nb_streams == 0) { + int ret = of_check_init(of); + if (ret < 0) + return ret; + } + return 0; } 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); From patchwork Tue Jan 11 09:58:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33229 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547966iog; Tue, 11 Jan 2022 02:03:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfhagQw9E2+yjzJJECzTDOsYPzMvNotYMa5IThf3DXRVQekIaIuXqfmMkOzMuzm/+MouZ1 X-Received: by 2002:a05:6402:27ca:: with SMTP id c10mr3603117ede.67.1641895424745; Tue, 11 Jan 2022 02:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895424; cv=none; d=google.com; s=arc-20160816; b=tU1dzgNqxctS+u6sFYkOjBV5HNA2iKB3ATX2mRXscyVtTcZLr6VFiSn393y8RulFkh OtGO56sBuMPwbeEOJFTExqh207tff7k1GepnoVigVHmljz97hlEYkUEA82edfHOkM2B8 X+G26jekubuA7U5tY1unhWWI1I4vF+fRTQ0oW5pDNtzSdgdyMvpFSb8tqsV2i1dNeohx ijyjtgDTXmuYVahQRhW5oKUOrO1RbPmTr/dBdfu3CzXVHrwgxLCMyjCPF+xFJLXOeLPI f/pjOU1aQZml7vtedAcBeLQzjO/4gVcC1sVDwUpip4RtRsq8HzEoOLWBiIaxRtHDNph7 lcMw== 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=xPwDlqvJkSthqCEB/aNc8heJVA2IEU7ibpcR15luT80=; b=STC5SLxgQJ69P6LLdFk6isEAzX8O4xom07tKnYStzYasaPcQZOv+wqZUIFsP1iPTw7 /6vL5DQnieEvLA2d9bln/Xpjlc/LbTWUhSt0cwl/vePtNDSZhElKdm5uQZ/jS1B5j+XX 8yF3WxaOo8RiZBMbSwwgIHgsDSObd9uol/bAm+J5417THaRRsUK3mUYIwFmVLHdVr3Wi XJP5pKR1gh5HRlain2Cb/hEwY5VDz0dPrn9eRXAhTs6vGMw1pZd4QJCnrpaEn1d0zjZX 0rggfjiRls8e8kiqCihrNF2fP9YaxzvyghvybJmJlfSFrQ1kYQdE6WjGH5gjFr4ca4dz hZRQ== 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 su24si4326236ejb.574.2022.01.11.02.03.44; Tue, 11 Jan 2022 02:03:44 -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 2A57268B022; Tue, 11 Jan 2022 11:59:35 +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 E73B868AF55 for ; Tue, 11 Jan 2022 11:59:10 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C403124055A for ; Tue, 11 Jan 2022 10:59:08 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id EqHV9zozDWkS for ; Tue, 11 Jan 2022 10:59:08 +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 A9A94240590 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1040D3A0A44; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:16 +0100 Message-Id: <20220111095830.31542-14-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 14/28] ffmpeg: refactor the code checking for bitexact output 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: 5lK00O0DUFk9 Figure out earlier whether the output stream/file should be bitexact and store this information in a flag in OutputFile/OutputStream. Stop accessing the muxer in set_encoder_id(), which will become forbidden in future commits. --- fftools/ffmpeg.c | 21 +-------------------- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_opt.c | 27 ++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4f5c2cc49a..5165573674 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2864,37 +2864,18 @@ static int init_output_stream_streamcopy(OutputStream *ost) static void set_encoder_id(OutputFile *of, OutputStream *ost) { - const AVDictionaryEntry *e; - uint8_t *encoder_string; int encoder_string_len; - int format_flags = 0; - int codec_flags = ost->enc_ctx->flags; if (av_dict_get(ost->st->metadata, "encoder", NULL, 0)) return; - e = av_dict_get(of->opts, "fflags", NULL, 0); - if (e) { - const AVOption *o = av_opt_find(of->ctx, "fflags", NULL, 0, 0); - if (!o) - return; - av_opt_eval_flags(of->ctx, o, e->value, &format_flags); - } - e = av_dict_get(ost->encoder_opts, "flags", NULL, 0); - if (e) { - const AVOption *o = av_opt_find(ost->enc_ctx, "flags", NULL, 0, 0); - if (!o) - return; - av_opt_eval_flags(ost->enc_ctx, o, e->value, &codec_flags); - } - encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(ost->enc->name) + 2; encoder_string = av_mallocz(encoder_string_len); if (!encoder_string) exit_program(1); - if (!(format_flags & AVFMT_FLAG_BITEXACT) && !(codec_flags & AV_CODEC_FLAG_BITEXACT)) + if (!of->bitexact && !ost->bitexact) av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len); else av_strlcpy(encoder_string, "Lavc ", encoder_string_len); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d926254a73..66062f0072 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -491,6 +491,7 @@ typedef struct OutputStream { int top_field_first; int rotate_overridden; int autoscale; + int bitexact; int bits_per_raw_sample; double rotate_override_value; @@ -588,6 +589,7 @@ typedef struct OutputFile { int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units int shortest; + int bitexact; } OutputFile; extern InputStream **input_streams; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 0b4f437912..ed3fd818d0 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1427,6 +1427,22 @@ static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *o return 0; } +static int check_opt_bitexact(void *ctx, const AVDictionary *opts, + const char *opt_name, int flag) +{ + const AVDictionaryEntry *e = av_dict_get(opts, opt_name, NULL, 0); + + if (e) { + const AVOption *o = av_opt_find(ctx, opt_name, NULL, 0, 0); + int val = 0; + if (!o) + return 0; + av_opt_eval_flags(ctx, o, e->value, &val); + return !!(val & flag); + } + return 0; +} + static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index) { OutputStream *ost; @@ -1522,8 +1538,13 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e } - if (o->bitexact) + if (o->bitexact) { ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT; + ost->bitexact = 1; + } else { + ost->bitexact = check_opt_bitexact(ost->enc_ctx, ost->encoder_opts, "flags", + AV_CODEC_FLAG_BITEXACT); + } MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st); if (time_base) { @@ -2308,6 +2329,10 @@ static int open_output_file(OptionsContext *o, const char *filename) if (o->bitexact) { oc->flags |= AVFMT_FLAG_BITEXACT; + of->bitexact = 1; + } else { + of->bitexact = check_opt_bitexact(oc, of->opts, "fflags", + AVFMT_FLAG_BITEXACT); } /* create streams for all unlabeled output pads */ From patchwork Tue Jan 11 09:58:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33227 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547707iog; Tue, 11 Jan 2022 02:03:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkgRoGoW5BezQsh/DltARIgOpP9UxT3zYt1k0utyj9zhbtdj0+kN8hqAco621vbnlT8Udu X-Received: by 2002:a05:6402:4387:: with SMTP id o7mr1675983edc.23.1641895402665; Tue, 11 Jan 2022 02:03:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895402; cv=none; d=google.com; s=arc-20160816; b=dtegyat6SwRaWDL3JmCNmoHr/JhykSiBKRUMEV3aK/rQC4mZ0M+sjiv9+figi3ONsd WWOAF0s4eluo8RwOPNE0ENndClEEo+C5tDWT4gmOJrVLy8Ub13LV0So885sawPNC1W7x IZ6pzXx78XwjjvjSCT2gLShJoIeI8+1CDOQbZG8i5kpCB1RMHcu5sRCly7mdvKokRP95 uHm/jOtlZjyhAcoM2JsawWKlmb3FG55Zr+al7IG1MNqIlCnvJXfHd/jH0DYOUNtqruKc iny0G4RJh3aYLnp7InFABlZ0B9jEuWIz15BdcIhR9Sgv7XrSqUANakJm/17YPEnHpxhd +0gQ== 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=kwuf24x8suS6wvX8faApfRJ79oCxDW6izWqRNG5n0SA=; b=LS1AHbGHxsMOeW/9J1vergx4QkjXZ7W6GzU70sGGbpZYigtAMu1RlhJaIPpl1DHbLd VHhxYc0p6HWFsJ9AwI/BvHbwPVgJTE6S4/RUC+rgUrlovLLqFXMB6DbYIVrWhhiyavLW FuuxTCru6lNldsbUQ8vU5SDi5Qk/PcJaCrfXVWW32ODE6PAlkHLNssdnb/YY855rqdg6 8ysWZMGov+xe9cicjadEEBfc4RAfIa0iGlldsAkTP2NqRAAJiQNVVLSJuPZ95jHkAsJu skD0JWPAJ904eeMWNWAH92KHCMHfRBqx75EQHLUHMZ10YDGWeybBCWibKElAyf5mpiiw VIsA== 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 hp40si2761292ejc.415.2022.01.11.02.03.21; Tue, 11 Jan 2022 02:03:22 -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 5656268B012; Tue, 11 Jan 2022 11:59:33 +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 A088468AF7E for ; Tue, 11 Jan 2022 11:59:10 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6BB5A240512 for ; Tue, 11 Jan 2022 10:59:08 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XKEqVKltHBIB for ; Tue, 11 Jan 2022 10:59:07 +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 A9A2424056A for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 146323A0A7F; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:17 +0100 Message-Id: <20220111095830.31542-15-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 15/28] ffmpeg: access output file chapters through a wrapper 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: pP0vbNJ5fLyO Avoid accessing the muxer context directly, as this will become forbidden in future commits. --- fftools/ffmpeg.c | 15 +++++++++------ fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_mux.c | 7 +++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5165573674..2637b25526 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2909,12 +2909,15 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, *next++ = 0; if (!memcmp(p, "chapters", 8)) { - - AVFormatContext *avf = output_files[ost->file_index]->ctx; + OutputFile *of = output_files[ost->file_index]; + AVChapter * const *ch; + unsigned int nb_ch; int j; - if (avf->nb_chapters > INT_MAX - size || - !(pts = av_realloc_f(pts, size += avf->nb_chapters - 1, + ch = of_get_chapters(of, &nb_ch); + + if (nb_ch > INT_MAX - size || + !(pts = av_realloc_f(pts, size += nb_ch - 1, sizeof(*pts)))) { av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n"); @@ -2923,8 +2926,8 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0; t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); - for (j = 0; j < avf->nb_chapters; j++) { - AVChapter *c = avf->chapters[j]; + for (j = 0; j < nb_ch; j++) { + const AVChapter *c = ch[j]; av_assert1(index < size); pts[index++] = av_rescale_q(c->start, c->time_base, avctx->time_base) + t; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 66062f0072..e828f71dc0 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -697,5 +697,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue); int of_finished(OutputFile *of); int64_t of_filesize(OutputFile *of); +AVChapter * const * +of_get_chapters(OutputFile *of, unsigned int *nb_chapters); #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 13b5d2d220..f4d76e1533 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -396,3 +396,10 @@ int64_t of_filesize(OutputFile *of) return ret; } + +AVChapter * const * +of_get_chapters(OutputFile *of, unsigned int *nb_chapters) +{ + *nb_chapters = of->ctx->nb_chapters; + return of->ctx->chapters; +} From patchwork Tue Jan 11 09:58:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33213 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3545854iog; Tue, 11 Jan 2022 02:00:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3wC+yoVKYhZlqVXnjja9Xf9tcncA1G3loiHwdd/TY0kSXDBUJ1iC7qbypBrFGHFlrmAdF X-Received: by 2002:a50:ec90:: with SMTP id e16mr3548770edr.355.1641895249190; Tue, 11 Jan 2022 02:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895249; cv=none; d=google.com; s=arc-20160816; b=VxbzITcn+k15Ry7lybuSd1ImlI/4s71vdngRkMo0ERzdec5VWR3DztndooSxMlObvb Rb8CLjMxPMa37+Rnz7As4gCyMlWL9N4lGwWVRIpLzPvmlR68YSXiIhzuUCQQ4JTiUnHX B7iU/0EHv2OnJ2cvDHVlYN/g581eGHNGB2ejjW/MpmVyym8eRikLTGg+lzV+AAduFCfI RP6kUdcYFCsag+9T/mwIuq5WoWdhejjDFj7wgRG9mNKlOvsM5n5MEOv36bY9xT0xZgCS CapoKKEJMYnYgu9Ua77PvOzxZANCgV3rBiBqOeec1GiMAjwKY8Ul+7hOI+QxtOCNPAZQ fAIA== 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=xmOa7nCUY91jgfXwTipHz0NK6TjmIPD7UatN8y2ba6Y=; b=RFxhM3g6ybohfEZwuF0qtsoB2ec+FfKeqUlvM1TAQjCe425SI09Qy8yiYDng91MsTr NHtjdtb1WPQo5ciI7eMHDQ35mnWABHmOXxn/sQ63Zhfi2VWL81qAPLaWn9CLZ2FW4m2a JO/XuXUFqvCnHmnnW1JPZ3plNFH/+SuCkYeXcgC4RLvAB2wY2fBx8mMdfyIa1FRw+L+r RIuT6sZXATw4/Zp/NmPDb4M2Zl0HXiaC6xVDXNGGcq8K2wSi6QwYcEVtJAjNvLM8JMLr 4R3lb58oWCdSF+ltkb3WlE2/r6zCEFzljeFsSIiks/jTKTMljAyb5d5CWOE5ExQzYezs TVPw== 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 y14si317973eda.568.2022.01.11.02.00.48; Tue, 11 Jan 2022 02:00:49 -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 236E668AF71; Tue, 11 Jan 2022 11:59:20 +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 A531668AF3E for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2D8F0240593 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 oCf9AVaEnpNe for ; Tue, 11 Jan 2022 10:59:10 +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 D08092405F5 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 189CF3A0AB5; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:18 +0100 Message-Id: <20220111095830.31542-16-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 16/28] ffmpeg: do not log to the muxer context 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: ThTVoNB/xnRx All other logging goes to NULL context. --- fftools/ffmpeg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2637b25526..6c774e9615 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2954,7 +2954,6 @@ static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba { InputStream *ist = get_input_stream(ost); AVCodecContext *enc_ctx = ost->enc_ctx; - AVFormatContext *oc; if (ost->enc_timebase.num > 0) { enc_ctx->time_base = ost->enc_timebase; @@ -2967,8 +2966,9 @@ static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba return; } - oc = output_files[ost->file_index]->ctx; - av_log(oc, AV_LOG_WARNING, "Input stream data not available, using default time base\n"); + av_log(NULL, AV_LOG_WARNING, + "Input stream data for output stream #%d:%d not available, " + "using default time base\n", ost->file_index, ost->index); } enc_ctx->time_base = default_time_base; From patchwork Tue Jan 11 09:58:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33219 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3546609iog; Tue, 11 Jan 2022 02:01:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJynFXOn6qCoayk1FGxXL8KMniqrkUCrH3f9L73LuTT2JWg83n8KUzeW5ow/Agw8ebcCJ6hP X-Received: by 2002:a05:6402:b88:: with SMTP id cf8mr3650265edb.284.1641895312588; Tue, 11 Jan 2022 02:01:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895312; cv=none; d=google.com; s=arc-20160816; b=Yxir/L2eM7MWw71tDW5hyao5MvRXcqeywfVifQIzv8TtWhaXC8V0nKMvYCwrg8k1Vq 8VwOPd9LtdkBTKjSlfqfQSr4jy9ylqP1iaPLj4pdjYxc4WAu8X2CzeXXq122E1+rzm+3 uJz3Ld5wgoOo1S/f0dZwu90T6v4vbi0pCnY2NhuV+ZRnObDhtMDiZQo1/hdOXE2eKT0y RlT7YJWZci6FNuVigaCxMBN0fnpwjrImC8UtA6l9j57Uc13LjwLBdqt6wJtgqRietEgs RJbOtA/JCaZPXsREuMAC2gr3X0mkiE2k1QiEiurXxhubY+J7dZvpYPuogio4jWOdAJV9 4MOA== 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=9SC7+pGTWFx+PyjGJcZAb3VBA2eHcol1JcNKz7cfiP8=; b=e60UjTanR995yH5uIBbUjWhUTexYdKSPaRJWaS5X0tA0hy5MK/7ALd96zdKopFcLRx svwrux07rehRXQpkynGFW68H8LFKyT2ezKz1ylqyrtV2Vv6Oil9N+afOljFVLAqKXl6d rKj9p9snYcQVQXcHBnrA3tGXXJivBHS6ccmf6I2trfz+t5ONT4bJuZe8ywOofEfEq30L +ga+iUnnaq85ky+2YA8msnCmFwOIq5C2VNtdM4iFCWPMQo7YIIR3bq4DLVQnBXa0Bg3r ObJsz3Kx8zVcjONipuR3US6p6wtVPDPXvbnG+us2KqxJRy2fOw+P8y1T4pge//a2OeA1 rHHw== 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 gs13si4760488ejc.512.2022.01.11.02.01.51; Tue, 11 Jan 2022 02:01:52 -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 93D7168AF7B; Tue, 11 Jan 2022 11:59:25 +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 ACD1568AF50 for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EAE302405F5 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 1x2h9bqDdSrV 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 E97D5240688 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1D04F3A0B4A; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:19 +0100 Message-Id: <20220111095830.31542-17-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 17/28] ffmpeg: move the mux queue into muxer private data 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: /oriDo5SzKnE The muxing queue currently lives in OutputStream, which is a very large struct storing the state for both encoding and muxing. The muxing queue is only used by the code in ffmpeg_mux, so it makes sense to restrict it to that file. This makes the first step towards reducing the scope of OutputStream. --- fftools/ffmpeg.c | 9 ----- fftools/ffmpeg.h | 9 ----- fftools/ffmpeg_mux.c | 91 ++++++++++++++++++++++++++++++++++++-------- fftools/ffmpeg_opt.c | 6 --- 4 files changed, 76 insertions(+), 39 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 6c774e9615..c1bb3926c4 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -595,15 +595,6 @@ static void ffmpeg_cleanup(int ret) avcodec_free_context(&ost->enc_ctx); avcodec_parameters_free(&ost->ref_par); - if (ost->muxing_queue) { - while (av_fifo_size(ost->muxing_queue)) { - AVPacket *pkt; - av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL); - av_packet_free(&pkt); - } - av_fifo_freep(&ost->muxing_queue); - } - av_freep(&output_streams[i]); } #if HAVE_THREADS diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index e828f71dc0..28df1b179f 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -555,15 +555,6 @@ typedef struct OutputStream { int max_muxing_queue_size; - /* the packets are buffered here until the muxer is ready to be initialized */ - AVFifoBuffer *muxing_queue; - - /* - * The size of the AVPackets' buffers in queue. - * Updated when a packet is either pushed or pulled from the queue. - */ - size_t muxing_queue_data_size; - /* Threshold after which max_muxing_queue_size will be in effect */ size_t muxing_queue_data_threshold; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index f4d76e1533..f03202bbb7 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -32,7 +32,20 @@ #include "libavformat/avformat.h" #include "libavformat/avio.h" +typedef struct MuxStream { + /* the packets are buffered here until the muxer is ready to be initialized */ + AVFifoBuffer *muxing_queue; + + /* + * The size of the AVPackets' buffers in queue. + * Updated when a packet is either pushed or pulled from the queue. + */ + size_t muxing_queue_data_size; +} MuxStream; + struct Muxer { + MuxStream *streams; + /* filesize limit expressed in bytes */ int64_t limit_filesize; int64_t final_filesize; @@ -55,6 +68,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, { AVFormatContext *s = of->ctx; AVStream *st = ost->st; + MuxStream *ms = &of->mux->streams[st->index]; int ret; /* @@ -76,10 +90,10 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, if (!of->mux->header_written) { AVPacket *tmp_pkt; /* the muxer is not initialized yet, buffer the packet */ - if (!av_fifo_space(ost->muxing_queue)) { - size_t cur_size = av_fifo_size(ost->muxing_queue); + if (!av_fifo_space(ms->muxing_queue)) { + size_t cur_size = av_fifo_size(ms->muxing_queue); unsigned int are_we_over_size = - (ost->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold; + (ms->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold; size_t limit = are_we_over_size ? ost->max_muxing_queue_size : INT_MAX; size_t new_size = FFMIN(2 * cur_size, limit); @@ -89,7 +103,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, ost->file_index, ost->st->index); exit_program(1); } - ret = av_fifo_realloc2(ost->muxing_queue, new_size); + ret = av_fifo_realloc2(ms->muxing_queue, new_size); if (ret < 0) exit_program(1); } @@ -100,8 +114,8 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, if (!tmp_pkt) exit_program(1); av_packet_move_ref(tmp_pkt, pkt); - ost->muxing_queue_data_size += tmp_pkt->size; - av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL); + ms->muxing_queue_data_size += tmp_pkt->size; + av_fifo_generic_write(ms->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL); return; } @@ -283,16 +297,17 @@ int of_check_init(OutputFile *of) /* flush the muxing queues */ for (i = 0; i < of->ctx->nb_streams; i++) { + MuxStream *ms = &of->mux->streams[i]; OutputStream *ost = output_streams[of->ost_index + i]; /* try to improve muxing time_base (only possible if nothing has been written yet) */ - if (!av_fifo_size(ost->muxing_queue)) + if (!av_fifo_size(ms->muxing_queue)) ost->mux_timebase = ost->st->time_base; - while (av_fifo_size(ost->muxing_queue)) { + while (av_fifo_size(ms->muxing_queue)) { AVPacket *pkt; - av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL); - ost->muxing_queue_data_size -= pkt->size; + av_fifo_generic_read(ms->muxing_queue, &pkt, sizeof(pkt), NULL); + ms->muxing_queue_data_size -= pkt->size; of_write_packet(of, pkt, ost, 1); av_packet_free(&pkt); } @@ -333,6 +348,31 @@ int of_write_trailer(OutputFile *of) return 0; } +static void mux_free(Muxer **pmux, int nb_streams) +{ + Muxer *mux = *pmux; + + if (!mux) + return; + + for (int i = 0; i < nb_streams; i++) { + MuxStream *ms = &mux->streams[i]; + + if (!ms->muxing_queue) + continue; + + while (av_fifo_size(ms->muxing_queue)) { + AVPacket *pkt; + av_fifo_generic_read(ms->muxing_queue, &pkt, sizeof(pkt), NULL); + av_packet_free(&pkt); + } + av_fifo_freep(&ms->muxing_queue); + } + av_freep(&mux->streams); + + av_freep(pmux); +} + void of_close(OutputFile **pof) { OutputFile *of = *pof; @@ -342,25 +382,42 @@ void of_close(OutputFile **pof) return; s = of->ctx; + + mux_free(&of->mux, s ? s->nb_streams : 0); + if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE)) avio_closep(&s->pb); avformat_free_context(s); av_dict_free(&of->opts); - av_freep(&of->mux); - av_freep(pof); } int of_muxer_init(OutputFile *of, int64_t limit_filesize) { Muxer *mux = av_mallocz(sizeof(*mux)); + int ret = 0; if (!mux) return AVERROR(ENOMEM); + mux->streams = av_calloc(of->ctx->nb_streams, sizeof(*mux->streams)); + if (!mux->streams) { + av_freep(&mux); + return AVERROR(ENOMEM); + } + of->mux = mux; + for (int i = 0; i < of->ctx->nb_streams; i++) { + MuxStream *ms = &mux->streams[i]; + ms->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket)); + if (!ms->muxing_queue) { + ret = AVERROR(ENOMEM); + goto fail; + } + } + mux->limit_filesize = limit_filesize; if (strcmp(of->format->name, "rtp")) @@ -368,12 +425,16 @@ int of_muxer_init(OutputFile *of, int64_t limit_filesize) /* write the header for files with no streams */ if (of->format->flags & AVFMT_NOSTREAMS && of->ctx->nb_streams == 0) { - int ret = of_check_init(of); + ret = of_check_init(of); if (ret < 0) - return ret; + goto fail; } - return 0; +fail: + if (ret < 0) + mux_free(&of->mux, of->ctx->nb_streams); + + return ret; } int of_finished(OutputFile *of) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index ed3fd818d0..c7d1d21a37 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1613,8 +1613,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->max_muxing_queue_size = FFMIN(ost->max_muxing_queue_size, INT_MAX / sizeof(ost->pkt)); ost->max_muxing_queue_size *= sizeof(ost->pkt); - ost->muxing_queue_data_size = 0; - ost->muxing_queue_data_threshold = 50*1024*1024; MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ost->muxing_queue_data_threshold, oc, st); @@ -1638,10 +1636,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e } ost->last_mux_dts = AV_NOPTS_VALUE; - ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket)); - if (!ost->muxing_queue) - exit_program(1); - return ost; } From patchwork Tue Jan 11 09:58:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33214 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3545977iog; Tue, 11 Jan 2022 02:00:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEMPpLGH8EMxI4MmzqEEVGxNMYI+JLxprAn8gMSceTYV6aJzSkGLMvB3ChK+DOavcBtBag X-Received: by 2002:aa7:c1c1:: with SMTP id d1mr3535928edp.416.1641895258989; Tue, 11 Jan 2022 02:00:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895258; cv=none; d=google.com; s=arc-20160816; b=fIhJlXHc7Rhw2o4/FPA/myEqgE8+6nHMxHPT5nNOC/tLqAmWCmFFxZZVO0nCMqDTEW m2CzV7eMAWxDXar0puZBNRwwzb/JGfCADiLvadBqnOBPzOtSWPyq7BAzJ5MKNxg1ZzTe eQDZp2i7lDlyRtV/K4nYpe5Fv6mTjSC2BPDDBUENUtaxIy502IsbbpEvsVpnlm1XUhPH ZFMd7BI6HWIi1QhLnbk1POMQ57/F2VC9IzZaXCUxRl46rxtxjkfK2mLeW6eOhZ5S2aSo si1KkmHafMPJpAYdMEcHzK8xt/qMW5gBHg01GEeYHPnUdEqfr+cGfBD199cmQIJs6rd/ 9+2g== 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=r4bY3BBm1aggg8pLbnq4WvILFtD2MCETZnvuAIhVpwU=; b=wfRXlip8yCjTZoIuWB95iFu+OTD9ALoRktKg7ihn6FZEdXuFBuy4qtdPpu69hzvmCQ c2Abo4eFu6deqrLAPgL2Kc0fMFNNX37rhTGl4umUEmO3+zPfI+8AUCoe1Nmvv5GSsHYK 69bEUCJ6llIC9drg1xOjxCGBjsg/+lP7KbfzaYcCHVarIb9tIsZmNMVx619W8j9bpbw4 w5xykywuF67fVX+/6ZTKeLPto0MG5aQXzb4OyDOY+s+cwVfxE6BLlBxDE57qdfRdxhLK SHajtQgL9M2Hl4lGLUYsPYnIYUZF5Xv4WT1IPj/ykImGtt7FI6lAInE3i8XHK3Xx6Y3l SZKA== 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 r18si3799150edd.454.2022.01.11.02.00.58; Tue, 11 Jan 2022 02:00:58 -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 E3C9468AFB1; Tue, 11 Jan 2022 11:59:20 +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 A56FB68AF40 for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F0A7F24017C for ; Tue, 11 Jan 2022 10:59:10 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id YaTqRUgPQxjT for ; Tue, 11 Jan 2022 10:59:10 +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 D8527240685 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 211C73A0BC7; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:20 +0100 Message-Id: <20220111095830.31542-18-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 18/28] ffmpeg: fix initial muxing queue 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: PiSoubSXZ7ok It stores pointers to AVPacket, not AVPackets themselves. --- fftools/ffmpeg_mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index f03202bbb7..f48031096d 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -411,7 +411,7 @@ int of_muxer_init(OutputFile *of, int64_t limit_filesize) for (int i = 0; i < of->ctx->nb_streams; i++) { MuxStream *ms = &mux->streams[i]; - ms->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket)); + ms->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket*)); if (!ms->muxing_queue) { ret = AVERROR(ENOMEM); goto fail; From patchwork Tue Jan 11 09:58:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33230 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3548071iog; Tue, 11 Jan 2022 02:03:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxrN54eNO3jUrytKMAuQAsvOPOhtkKY43RfvKrLDsME7QNv1SdeVq1Q/UCPpkVZQUq7A8nq X-Received: by 2002:a17:907:72d2:: with SMTP id du18mr341158ejc.208.1641895436504; Tue, 11 Jan 2022 02:03:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895436; cv=none; d=google.com; s=arc-20160816; b=yeT1LXp9c9SmT39d7TGDVvljvH7b7pBnua4/7rjCDxIZLYMMlQ1abamz6NLLJNxBnu 1gG774LSKYVisJXhOmzKZntgYk59y7a04hH7apqiYuNEQLrh+fhXTH9+WOMm61QpVbie Y/6TtyYlWKDtCcgluYD621e+CGppyCRz1GjkWjuxeZxHgwKrNMMpU89bkv0rDq5CduAH +ei6f32NfX7p2rlQoaChM6S7gfaGpOnQ2dlERxxTEpDR3WysLEUrUUbzi7KzZ50sEKaJ Zn2yxSJVSl8At+9eCWYjCngNDMz5qTl7uBtJfGsQB74SfBcSOEOnpkQ7dA/0bEAwW+yp cddg== 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=CbAdEmGA+++Oehtq7ZsfrV7u5b7sznC5iaJgbMa2lhc=; b=lpwSuteHKJl+vkd6/N8s3lDqAbGBid7yiTGteGhuBT12Bq+76DcHdnI37YxsaMvbB3 /wqmaXMPWQep7eCAOyAQgW3lOcNRvRH8MjaFZpXs4rhQ/0qZMCeNm1ARMfI7+bIzGBtF yH5C691f5anwkG8LdDLE+HHTb0guMIVwpGGSjaWZKYh2YQ8qs1CdHaoXt+mOVKsxq09h x6MSlHp83TjAy8azsv9kuzut/B2sCgESj9KgipURuOnBpESEhwgcmGB5/gCxgMJRx4JW tpoEw/C+NJZxeunSmcmZuLKou4KIk8o+DuAycKPyRzy12XOw9xCVMIzwKHPe4GyzkdVB ZMIA== 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 nb23si5170448ejc.489.2022.01.11.02.03.55; Tue, 11 Jan 2022 02:03:56 -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 1AAD968B027; Tue, 11 Jan 2022 11:59:36 +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 EC69B68AF8F for ; Tue, 11 Jan 2022 11:59:10 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E80A224056A for ; Tue, 11 Jan 2022 10:59:08 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 4I8rCXl9jv3m for ; Tue, 11 Jan 2022 10:59:08 +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 C955A240592 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2579F3A0BE6; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:21 +0100 Message-Id: <20220111095830.31542-19-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 19/28] ffmpeg_mux: split queuing packets into a separate function 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: fXN29+oh4TuH --- fftools/ffmpeg_mux.c | 72 +++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index f48031096d..4ab2279739 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -63,12 +63,50 @@ static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, } } +static int queue_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) +{ + MuxStream *ms = &of->mux->streams[ost->index]; + AVPacket *tmp_pkt; + int ret; + + if (!av_fifo_space(ms->muxing_queue)) { + size_t cur_size = av_fifo_size(ms->muxing_queue); + unsigned int are_we_over_size = + (ms->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold; + size_t limit = are_we_over_size ? ost->max_muxing_queue_size : INT_MAX; + size_t new_size = FFMIN(2 * cur_size, limit); + + if (new_size <= cur_size) { + av_log(NULL, AV_LOG_ERROR, + "Too many packets buffered for output stream %d:%d.\n", + ost->file_index, ost->st->index); + return AVERROR(ENOSPC); + } + ret = av_fifo_realloc2(ms->muxing_queue, new_size); + if (ret < 0) + return ret; + } + + ret = av_packet_make_refcounted(pkt); + if (ret < 0) + return ret; + + tmp_pkt = av_packet_alloc(); + if (!tmp_pkt) + return AVERROR(ENOMEM); + + av_packet_move_ref(tmp_pkt, pkt); + ms->muxing_queue_data_size += tmp_pkt->size; + av_fifo_generic_write(ms->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL); + + return 0; +} + void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue) { AVFormatContext *s = of->ctx; AVStream *st = ost->st; - MuxStream *ms = &of->mux->streams[st->index]; int ret; /* @@ -87,35 +125,13 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, ost->frame_number++; } + /* the muxer is not initialized yet, buffer the packet */ if (!of->mux->header_written) { - AVPacket *tmp_pkt; - /* the muxer is not initialized yet, buffer the packet */ - if (!av_fifo_space(ms->muxing_queue)) { - size_t cur_size = av_fifo_size(ms->muxing_queue); - unsigned int are_we_over_size = - (ms->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold; - size_t limit = are_we_over_size ? ost->max_muxing_queue_size : INT_MAX; - size_t new_size = FFMIN(2 * cur_size, limit); - - if (new_size <= cur_size) { - av_log(NULL, AV_LOG_ERROR, - "Too many packets buffered for output stream %d:%d.\n", - ost->file_index, ost->st->index); - exit_program(1); - } - ret = av_fifo_realloc2(ms->muxing_queue, new_size); - if (ret < 0) - exit_program(1); - } - ret = av_packet_make_refcounted(pkt); - if (ret < 0) - exit_program(1); - tmp_pkt = av_packet_alloc(); - if (!tmp_pkt) + ret = queue_packet(of, ost, pkt); + if (ret < 0) { + av_packet_unref(pkt); exit_program(1); - av_packet_move_ref(tmp_pkt, pkt); - ms->muxing_queue_data_size += tmp_pkt->size; - av_fifo_generic_write(ms->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL); + } return; } From patchwork Tue Jan 11 09:58:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33216 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3546259iog; Tue, 11 Jan 2022 02:01:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxD3hW48W2adD2Q1bivUt99Bn9VmMIS0jG28bjIUTrb5eSQuxNb9yHx4TDzvOmEuyTopFRT X-Received: by 2002:a05:6402:b07:: with SMTP id bm7mr3442843edb.195.1641895280229; Tue, 11 Jan 2022 02:01:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895280; cv=none; d=google.com; s=arc-20160816; b=QS5n71l3F9+eti6mFcTQ/yfUERirJ3cRzSQeDcDpbcERY/CQ8JHx1URCJ1vD9AOxyG 8fttAdC0HAytn2CHbshfrke91De1ddkpuAuUup0qaT5uqhr799VSbnmq8340Wbl5nLNJ tQxrifNgIwZzfB4lputL7Uh+NSqtoo96p+nXT/gjuzA5MbDIxoS7EX/LQthhakxfWol6 V/icuFgSc2EJzry3zaQ5d/J9BToQoGzxYuNegTvQ2cfolMp5jDO5MuRDHroPdTTbK9q8 u/5jaVbQN7M9EvNBZmtbgEKPszcemRKLvE4jhWj93kocHao7xUCzkJqJC9MOfODBaJ5Q xpaw== 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=cJZKx/7T7SkQcEz/8+noESW6LaVHkEJwGaA+H1LYw3w=; b=mA8aVE4Hv0VVMLoWiRQ4jDNvoqPMxcOgjzuGlgvPm3/dV2I5jlv0n7Pzso+qWie++8 nCYgUr585zzno129vIvudGqFKgw4jFa/tj9SU0TfjQpe4sxs9ZJtznXMAtoFp4c3q+tx u2t6IFdE/PJgN7LddGSeH8ikwo7UdUShXRlTQVlkfHCRjosJvgr3xvqcAukMkmYpNT2r MrkBifNsR7I4fcVKmz4fi3hX9shEfYci7BZ7dLYpEtseDviVh0S5sRk47Bx0y8nkAUcn EyRmfD6CgBVIvrhwhtOryATjmFnbSpK11IUII2wbHiAPqzBMMsk2qKQxLkNgUuBWmLz2 0roA== 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 zh8si1687581ejb.751.2022.01.11.02.01.19; Tue, 11 Jan 2022 02:01:20 -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 8F57B68AF4F; Tue, 11 Jan 2022 11:59:22 +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 A823968AF43 for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 85C2F240179 for ; Tue, 11 Jan 2022 10:59:10 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id rVKgZ_7CDTBz for ; Tue, 11 Jan 2022 10:59:08 +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 C9DBA240593 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 29DF93A0BF3; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:22 +0100 Message-Id: <20220111095830.31542-20-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 20/28] ffmpeg_mux: split of_write_packet() 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: 4iOdUe+FEiSn It is currently called from two places: - output_packet() in ffmpeg.c, which submits the newly available output packet to the muxer - from of_check_init() in ffmpeg_mux.c after the header has been written, to flush the muxing queue Some packets will thus be processed by this function twice, so it requires an extra parameter to indicate the place it is called from and avoid modifying some state twice. This is fragile and hard to follow, so split this function into two. Also rename of_write_packet() to of_submit_packet() to better reflect its new purpose. --- fftools/ffmpeg.c | 4 +-- fftools/ffmpeg.h | 3 +-- fftools/ffmpeg_mux.c | 63 ++++++++++++++++++++++++-------------------- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c1bb3926c4..4215be0098 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -728,11 +728,11 @@ static void output_packet(OutputFile *of, AVPacket *pkt, if (ret < 0) goto finish; while ((ret = av_bsf_receive_packet(ost->bsf_ctx, pkt)) >= 0) - of_write_packet(of, pkt, ost, 0); + of_submit_packet(of, pkt, ost); if (ret == AVERROR(EAGAIN)) ret = 0; } else if (!eof) - of_write_packet(of, pkt, ost, 0); + of_submit_packet(of, pkt, ost); finish: if (ret < 0 && ret != AVERROR_EOF) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 28df1b179f..374dca9189 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -684,8 +684,7 @@ int of_check_init(OutputFile *of); int of_write_trailer(OutputFile *of); void of_close(OutputFile **pof); -void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, - int unqueue); +void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost); int of_finished(OutputFile *of); int64_t of_filesize(OutputFile *of); AVChapter * const * diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 4ab2279739..36f781ae11 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -102,39 +102,12 @@ static int queue_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) return 0; } -void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, - int unqueue) +static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) { AVFormatContext *s = of->ctx; AVStream *st = ost->st; int ret; - /* - * Audio encoders may split the packets -- #frames in != #packets out. - * But there is no reordering, so we can limit the number of output packets - * by simply dropping them here. - * Counting encoded video frames needs to be done separately because of - * reordering, see do_video_out(). - * Do not count the packet when unqueued because it has been counted when queued. - */ - if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) && !unqueue) { - if (ost->frame_number >= ost->max_frames) { - av_packet_unref(pkt); - return; - } - ost->frame_number++; - } - - /* the muxer is not initialized yet, buffer the packet */ - if (!of->mux->header_written) { - ret = queue_packet(of, ost, pkt); - if (ret < 0) { - av_packet_unref(pkt); - exit_program(1); - } - return; - } - if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) || (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0)) pkt->pts = pkt->dts = AV_NOPTS_VALUE; @@ -225,6 +198,38 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, } } +void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) +{ + AVStream *st = ost->st; + int ret; + + /* + * Audio encoders may split the packets -- #frames in != #packets out. + * But there is no reordering, so we can limit the number of output packets + * by simply dropping them here. + * Counting encoded video frames needs to be done separately because of + * reordering, see do_video_out(). + */ + if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) { + if (ost->frame_number >= ost->max_frames) { + av_packet_unref(pkt); + return; + } + ost->frame_number++; + } + + if (of->mux->header_written) { + write_packet(of, ost, pkt); + } else { + /* the muxer is not initialized yet, buffer the packet */ + ret = queue_packet(of, ost, pkt); + if (ret < 0) { + av_packet_unref(pkt); + exit_program(1); + } + } +} + static int print_sdp(void) { char sdp[16384]; @@ -324,7 +329,7 @@ int of_check_init(OutputFile *of) AVPacket *pkt; av_fifo_generic_read(ms->muxing_queue, &pkt, sizeof(pkt), NULL); ms->muxing_queue_data_size -= pkt->size; - of_write_packet(of, pkt, ost, 1); + write_packet(of, ost, pkt); av_packet_free(&pkt); } } From patchwork Tue Jan 11 09:58:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33215 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3546117iog; Tue, 11 Jan 2022 02:01:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdgd/P8XwDRbfQZAu5aOYUGHZLt0wAIAHzv7z9U/KqsXrZId4hnhxio8b2PWSDbQyeqjhq X-Received: by 2002:a17:907:9804:: with SMTP id ji4mr2923259ejc.417.1641895270584; Tue, 11 Jan 2022 02:01:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895270; cv=none; d=google.com; s=arc-20160816; b=kiFrHPYt4noYyjpNrpRlm4Lv26E28q3Vioh7K2+nLDbK636pDvpMIRoRhV84btPS+Y zgcgT1v5HvjrGNaFWmjie8TQqeSwsYHsR4k+XG8USVKQYEM+3I+yhOeVGocIa9M+RglX iF+KSpnSp1USldD/dIk85u8X8xNelY465hGDwKAgEpgBzYxVBUK6efYWcfY2CoBG3B0L 6uscBNH9HxfUo/pv6rcmRPTdx32q+IrClse376NXEW+32goTtxBs2LgHxEQSH1w33eb5 +lXsWFT77gB++0f/QkMRdLcdyVwsRB3qFvba8Rkd1YWREQHhLch2yshL6arZuZwkXovz Qoxw== 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=C3WLt7Ql/uwq6v0RwgGifdWtJxUsn9ttNDNOSosEr48=; b=P9UW674Vd2SHQnOT36q+2zD0ZnnBJtmJIAamGxXjWQtK7pMv5MDgShgbnVVIgOcZb3 JcJn2E9L7RmYXduksdC6n1lp9O/bRUkU5ARczQAQ26pz7NMrhYSG4b5P9SrqpjyIensA 2NROdT7+hLcat5wDA/fzIX2vRQo9eS6/f/80JKmq6aUgmnDP7t3+8x6/58dftI8zqgbe CcDnr7y3Z8gpFSUbhBgO7kRyMpkJjQS5EhmNIN3jaKVaJe4y4+HN04HpBHsdIqXbzqxG 038a3iY6aQeNuumIFbE+HjEMeSs24JJZ3gclaMOLOiTMJe9h2vtkNVJAN6oYD2ShJ8o5 7VnQ== 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 sc11si407123ejc.65.2022.01.11.02.01.09; Tue, 11 Jan 2022 02:01:10 -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 B963F68AF2A; Tue, 11 Jan 2022 11:59:21 +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 ABC1A68AF4C for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5F3A824017E for ; Tue, 11 Jan 2022 10:59:09 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ls2i_bQSgNNc for ; Tue, 11 Jan 2022 10:59:08 +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 CAFF12405F0 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2E7303A0C0A; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:23 +0100 Message-Id: <20220111095830.31542-21-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 21/28] ffmpeg: move a comment to a more appropriate place 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: IQLvkKIxdYaT --- fftools/ffmpeg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4215be0098..f39b1b9375 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1064,6 +1064,11 @@ static void do_video_out(OutputFile *of, } } + /* + * For video, number of frames in == number of packets out. + * But there may be reordering, so we can't throw away frames on encoder + * flush, we need to limit them here, before they go into encoder. + */ nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number); nb0_frames = FFMIN(nb0_frames, nb_frames); @@ -1217,11 +1222,6 @@ static void do_video_out(OutputFile *of, } } ost->sync_opts++; - /* - * For video, number of frames in == number of packets out. - * But there may be reordering, so we can't throw away frames on encoder - * flush, we need to limit them here, before they go into encoder. - */ ost->frame_number++; if (vstats_filename && frame_size) From patchwork Tue Jan 11 09:58:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33217 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3546352iog; Tue, 11 Jan 2022 02:01:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9otXBez9E3FH8fuLZT4RPU2Al5z2+W/AMypW4DlidDa/RzIR8x6OfhdYfBZt+HEWt1TOj X-Received: by 2002:a17:906:794c:: with SMTP id l12mr2971752ejo.474.1641895290815; Tue, 11 Jan 2022 02:01:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895290; cv=none; d=google.com; s=arc-20160816; b=eEefXFeghgey+s/2ZqbpkCXc6aGeKz5o6YSptZtAdAdDaOm4QXnrxLyKi16h4SV5CQ nm0aBHblB5+rkuEsIL05Eh3d+PY28IvjnThCd7F9IkZfDl3VLF6YEchYvPDWP0lBq6gx 4SdVwErhB8IFHlSrB3S+0MMUA8xZlRxwvzrCRSeK09OCzamBrbaLD/RvOb3UOmChsnkU QrZkzt+mUV5wsUxfcN4IGeNTfkMQhr/qD7dl6NlzYNfJLdbceJ2d4dSqsYM2ohDl7YRo C7DLvpqzUaNvi4P9c2H9VW7KFyaPp8Pc+EwOv7rxD6bvfKHT8nao1EpWxYI6bfi+6Za3 aXyA== 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=kDxY5FJuxTrIqYmGi/kMMWMRwOMNnsZNdjMhOLvuIJU=; b=yHKEqMHxSPM02LJInGvm7aLwOCu6uQoGJPKiFFTBmWaSm3BYeH0I85OVsEMKsB1YRy A1t5hK1F3kZ6HYJCK8HRfbTpJpz1MvPEdBt9CaQgsySIaatReU3IcrB+qa8IksOr8+f7 MSE2zru3HDrYLPR5HnXvDflOSG/vkpT18VwvuROT5i6Rkn0H5efWiP7BoTzvz+IG+RYj 0SyzuylyaW0RyQ2MO0//SbnnxACoLCUiHAqsvMjpn3bkeOLL2b3tqlmNcMpw3WrV5Xjy 7FZ/9hJCiP0NUN4GsrTIgLUhv+7z9dHzZndIDSiLzJy447yJnBu5nuDem88rZPZ6+H5x 8g3Q== 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 dp4si684754ejc.487.2022.01.11.02.01.30; Tue, 11 Jan 2022 02:01:30 -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 8D9E068AFD0; Tue, 11 Jan 2022 11:59:23 +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 A9AAA68AF45 for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 13DE2240590 for ; Tue, 11 Jan 2022 10:59:10 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id htG4dIRvmOMJ for ; Tue, 11 Jan 2022 10:59:09 +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 D11AF24062A for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 32F083A0C43; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:24 +0100 Message-Id: <20220111095830.31542-22-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 22/28] ffmpeg: move output file opts into private context 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: lpdiPAEaGzC6 It is private to the muxer, no reason to access it from outside. --- fftools/ffmpeg.h | 3 +-- fftools/ffmpeg_mux.c | 9 ++++++--- fftools/ffmpeg_opt.c | 12 ++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 374dca9189..d9f997bf7a 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -574,7 +574,6 @@ typedef struct OutputFile { const AVOutputFormat *format; AVFormatContext *ctx; - AVDictionary *opts; int ost_index; /* index of the first stream in output_streams */ int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units @@ -678,7 +677,7 @@ int hw_device_setup_for_filter(FilterGraph *fg); int hwaccel_decode_init(AVCodecContext *avctx); -int of_muxer_init(OutputFile *of, int64_t limit_filesize); +int of_muxer_init(OutputFile *of, AVDictionary *opts, int64_t limit_filesize); /* open the muxer when all the streams are initialized */ int of_check_init(OutputFile *of); int of_write_trailer(OutputFile *of); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 36f781ae11..729cc1a7d8 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -46,6 +46,8 @@ typedef struct MuxStream { struct Muxer { MuxStream *streams; + AVDictionary *opts; + /* filesize limit expressed in bytes */ int64_t limit_filesize; int64_t final_filesize; @@ -294,7 +296,7 @@ int of_check_init(OutputFile *of) return 0; } - ret = avformat_write_header(of->ctx, &of->opts); + ret = avformat_write_header(of->ctx, &of->mux->opts); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Could not write header for output file #%d " @@ -390,6 +392,7 @@ static void mux_free(Muxer **pmux, int nb_streams) av_fifo_freep(&ms->muxing_queue); } av_freep(&mux->streams); + av_dict_free(&mux->opts); av_freep(pmux); } @@ -409,12 +412,11 @@ void of_close(OutputFile **pof) if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE)) avio_closep(&s->pb); avformat_free_context(s); - av_dict_free(&of->opts); av_freep(pof); } -int of_muxer_init(OutputFile *of, int64_t limit_filesize) +int of_muxer_init(OutputFile *of, AVDictionary *opts, int64_t limit_filesize) { Muxer *mux = av_mallocz(sizeof(*mux)); int ret = 0; @@ -440,6 +442,7 @@ int of_muxer_init(OutputFile *of, int64_t limit_filesize) } mux->limit_filesize = limit_filesize; + mux->opts = opts; if (strcmp(of->format->name, "rtp")) want_sdp = 0; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index c7d1d21a37..cb21a6a42c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2278,7 +2278,7 @@ static int open_output_file(OptionsContext *o, const char *filename) OutputFile *of; OutputStream *ost; InputStream *ist; - AVDictionary *unused_opts = NULL; + AVDictionary *unused_opts = NULL, *format_opts = NULL; const AVDictionaryEntry *e = NULL; if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { @@ -2303,7 +2303,7 @@ static int open_output_file(OptionsContext *o, const char *filename) of->recording_time = o->recording_time; of->start_time = o->start_time; of->shortest = o->shortest; - av_dict_copy(&of->opts, o->g->format_opts, 0); + av_dict_copy(&format_opts, o->g->format_opts, 0); if (!strcmp(filename, "-")) filename = "pipe:"; @@ -2325,7 +2325,7 @@ static int open_output_file(OptionsContext *o, const char *filename) oc->flags |= AVFMT_FLAG_BITEXACT; of->bitexact = 1; } else { - of->bitexact = check_opt_bitexact(oc, of->opts, "fflags", + of->bitexact = check_opt_bitexact(oc, format_opts, "fflags", AVFMT_FLAG_BITEXACT); } @@ -2702,7 +2702,7 @@ loop_end: /* open the file */ if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE, &oc->interrupt_callback, - &of->opts)) < 0) { + &format_opts)) < 0) { print_error(filename, err); exit_program(1); } @@ -2710,7 +2710,7 @@ loop_end: assert_file_overwrite(filename); if (o->mux_preload) { - av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0); + av_dict_set_int(&format_opts, "preload", o->mux_preload*AV_TIME_BASE, 0); } oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE); @@ -2904,7 +2904,7 @@ loop_end: exit_program(1); } - err = of_muxer_init(of, o->limit_filesize); + err = of_muxer_init(of, format_opts, o->limit_filesize); if (err < 0) { av_log(NULL, AV_LOG_FATAL, "Error initializing internal muxing state\n"); exit_program(1); From patchwork Tue Jan 11 09:58:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33220 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3546807iog; Tue, 11 Jan 2022 02:02:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDrsOdYvM+TXlpVYYMitK3AWN3PYGh5ntflP88Imq6M3Xvl8WXty78uFWhCG+vgqScuoDm X-Received: by 2002:a05:6402:180d:: with SMTP id g13mr3537096edy.187.1641895327242; Tue, 11 Jan 2022 02:02:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895327; cv=none; d=google.com; s=arc-20160816; b=CEnG4kZvmggNFl74MOJfwemPxiIRPstXqu2CZCMVZIkBYT8IoDeeTuGJUJ8LfrQrXF CxoagkYnlD4KUeBeAjkTDADhBqPCO2t+HWiFh0o8/OFRot34t1W5p38KJO/vtVHe9EAb 9WGImIWsw9kucLedY92mqeHkz3ManF1hWI7uIqNPTYTQt8A4YjoBsmGQmUFhUTREDM3l HW8XLOqq7Sw6uXfWKSAYjBwszKpIE9ZA61P5fkHVJhnz4EdH/POcsD8jQS2p8UJa2Cvb zOdWoEn+3N0PCaVIYjotJmwd4oVHyqLeAGQb5Nb+C/3XZXVjEJ6vPk8gsxmLoHkWFD+v /Dvw== 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=3FZkbtVnL/hLBx88gOa+6uHbaLmuEACpxasuszG7mrc=; b=kdoqUswO1Is2LBVrTpKWgPv0DOuDI57t7kRdbG0TPYJfLYkXHAPKGB3IKNq/aUlwCq WUYotK2CNTzi4WZrlNx1qL+iHY7ZA0VQQPGZA+Odw9yQVMOW4AGZqni+P2tfdylafHJq zd2lWm9tlVjNILq2IZg6z/VwAZPzqOtD+IfvLxmp9ZMaFwZ30gfePLBeMCRBhPeR7ZMR pyI3nXng3YLNB/h7+hpk9UlfU5fA2v5OZsATKGMb8rJqkg9/EcdIAfjq+p+EHv+cVWcN bnU2Rx113LTcT634NmmzppPG4FsF60Z/RUJjaepZti3Q7NtlRD2dE6DZjRkGQLTyE0Mr p5Xw== 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 bm12si4527119ejb.245.2022.01.11.02.02.02; Tue, 11 Jan 2022 02:02:07 -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 BC4E468AFDF; Tue, 11 Jan 2022 11:59:26 +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 AE58C68AF51 for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CCBEC24062A for ; Tue, 11 Jan 2022 10:59:12 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id LKaC2hQRxZYd for ; Tue, 11 Jan 2022 10:59:12 +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 EC80924068C for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 378A83A0C80; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:25 +0100 Message-Id: <20220111095830.31542-23-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 23/28] ffmpeg: move processing video stats to ffmpeg_mux 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: Aj0i2C+URXnF Currently it is called from - do_video_out(), at the end of each encode loop iteration - from flush_encoders(), after muxing each packet Since this function processes the data from the last encoded packet, neither of the above is fully correct, because - an encoder can in principle produce multiple packets per one submitted frame - bitstream filters may modify the number of encoded packets or their properties. It thus makes most sense to call this function right before sending the packet to the muxer. --- fftools/ffmpeg.c | 61 +------------------------------------------- fftools/ffmpeg.h | 5 ++++ fftools/ffmpeg_mux.c | 47 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 60 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index f39b1b9375..c89a95937e 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -109,7 +109,7 @@ const char program_name[] = "ffmpeg"; const int program_birth_year = 2000; -static FILE *vstats_file; +FILE *vstats_file; const char *const forced_keyframes_const_names[] = { "n", @@ -126,7 +126,6 @@ typedef struct BenchmarkTimeStamps { int64_t sys_usec; } BenchmarkTimeStamps; -static void do_video_stats(OutputStream *ost, int frame_size); static BenchmarkTimeStamps get_benchmark_time_stamps(void); static int64_t getmaxrss(void); static int ifilter_has_all_input_formats(FilterGraph *fg); @@ -977,7 +976,6 @@ static void do_video_out(OutputFile *of, double delta, delta0; double duration = 0; double sync_ipts = AV_NOPTS_VALUE; - int frame_size = 0; InputStream *ist = NULL; AVFilterContext *filter = ost->filter->filter; @@ -1213,7 +1211,6 @@ static void do_video_out(OutputFile *of, av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->mux_timebase)); } - frame_size = pkt->size; output_packet(of, pkt, ost, 0); /* if two pass, output log */ @@ -1223,9 +1220,6 @@ static void do_video_out(OutputFile *of, } ost->sync_opts++; ost->frame_number++; - - if (vstats_filename && frame_size) - do_video_stats(ost, frame_size); } av_frame_unref(ost->last_frame); @@ -1238,54 +1232,6 @@ error: exit_program(1); } -static double psnr(double d) -{ - return -10.0 * log10(d); -} - -static void do_video_stats(OutputStream *ost, int frame_size) -{ - AVCodecContext *enc; - int frame_number; - double ti1, bitrate, avg_bitrate; - - /* this is executed just the first time do_video_stats is called */ - if (!vstats_file) { - vstats_file = fopen(vstats_filename, "w"); - if (!vstats_file) { - perror("fopen"); - exit_program(1); - } - } - - enc = ost->enc_ctx; - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { - frame_number = ost->st->nb_frames; - if (vstats_version <= 1) { - fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, - ost->quality / (float)FF_QP2LAMBDA); - } else { - fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number, - ost->quality / (float)FF_QP2LAMBDA); - } - - if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) - fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); - - fprintf(vstats_file,"f_size= %6d ", frame_size); - /* compute pts value */ - ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); - if (ti1 < 0.01) - ti1 = 0.01; - - bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; - avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; - fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", - (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); - fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); - } -} - static void finish_output_stream(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; @@ -1764,7 +1710,6 @@ static void flush_encoders(void) for (;;) { const char *desc = NULL; AVPacket *pkt = ost->pkt; - int pkt_size; switch (enc->codec_type) { case AVMEDIA_TYPE_AUDIO: @@ -1808,11 +1753,7 @@ static void flush_encoders(void) continue; } av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase); - pkt_size = pkt->size; output_packet(of, pkt, ost, 0); - if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) { - do_video_stats(ost, pkt_size); - } } } } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d9f997bf7a..908dc2eb38 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -624,6 +624,7 @@ extern int stdin_interaction; extern int frame_bits_per_raw_sample; extern AVIOContext *progress_avio; extern float max_error_rate; +extern FILE *vstats_file; extern char *filter_nbthreads; extern int filter_complex_nbthreads; @@ -641,6 +642,10 @@ extern HWDevice *filter_hw_device; extern unsigned nb_output_dumped; extern int main_return_code; +static inline double psnr(double d) +{ + return -10.0 * log10(d); +} void term_init(void); void term_exit(void); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 729cc1a7d8..76d9d4b9c4 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -56,6 +56,49 @@ struct Muxer { static int want_sdp = 1; +static void do_video_stats(OutputStream *ost, int frame_size) +{ + AVCodecContext *enc; + int frame_number; + double ti1, bitrate, avg_bitrate; + + /* this is executed just the first time do_video_stats is called */ + if (!vstats_file) { + vstats_file = fopen(vstats_filename, "w"); + if (!vstats_file) { + perror("fopen"); + exit_program(1); + } + } + + enc = ost->enc_ctx; + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { + frame_number = ost->st->nb_frames; + if (vstats_version <= 1) { + fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, + ost->quality / (float)FF_QP2LAMBDA); + } else { + fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number, + ost->quality / (float)FF_QP2LAMBDA); + } + + if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) + fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); + + fprintf(vstats_file,"f_size= %6d ", frame_size); + /* compute pts value */ + ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); + if (ti1 < 0.01) + ti1 = 0.01; + + bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; + avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; + fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", + (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); + fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); + } +} + static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others) { int i; @@ -180,6 +223,10 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) ost->data_size += pkt->size; ost->packets_written++; + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + ost->encoding_needed && vstats_filename) + do_video_stats(ost, pkt->size); + pkt->stream_index = ost->index; if (debug_ts) { From patchwork Tue Jan 11 09:58:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33221 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3546884iog; Tue, 11 Jan 2022 02:02:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfPvW1N3+L60nlC79XQ1dzEJuLgrJ021jBd05qiKs4eI7GRFPzdGAJXYqxbw8EO6okCETJ X-Received: by 2002:aa7:c7d1:: with SMTP id o17mr3548901eds.412.1641895334188; Tue, 11 Jan 2022 02:02:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895334; cv=none; d=google.com; s=arc-20160816; b=y0cDVMhWswXwFHZPTl+IoQLZLxrKcAiCQlN/eBv7BZwS+2QQVETfBdYxA/ty40XCHV WywjMTa6aKjrxZIrYAYxFFPtUZm4MZRL2scc+to3lnFIo+xXUK57IpuILKrmm7n1wioW rqiFIb9aHx+0u3ZmCehxkpWtvD2FYYUeYBiM3gofD9E13LTG9vL/NGS3v3RSnmPAD1T4 ogqxgATz0LiB+CyEnvJ1iawrT5z2QeG9RzM4ZXlQi1TSFj9ZE92ua8qyvPehsy9/O4Ig EQB4xACsyJFDO1g3hxf4bJhnU0Md+3vmvCdVY4vs4eS9e6HOH5n5c6EXeLmbil06Ja9R I76A== 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=43WGgL1KydcKcI7fn2XZYvG48+xb5HqAZ58kMg3/sCs=; b=CO/zQyLRbAzsN/de4nG6uHAnSrbbXAMpJYbu2khfI8gYZWRUwqz4CKp6bXYJGNPb6w qJ+y+ijyczNsxew2+KsgbuE4QcFfZR735hWA9y3FqT00oUv7RjMDVechgd6iKpitf5uk JBG/7LtcbBIevQJNkX0mPGCGY+IUdIvYWw7DoYY9NKsvXgdWyL0PLvlAWtRY51rsztfH 7F2ZWBKa0Hg1AsduRYYcij/H/Eumdw57IovSWNQLcUALJcDHgX20Se+vAQzHUpk+n32o 7ayI7/TU2g88pvHQOjca0NAlZOT8eirjB/kNY8mwLwsGn0zYrHGbLTyEg7JzNTO4gBq7 DnPw== 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 eb11si5431764edb.546.2022.01.11.02.02.13; Tue, 11 Jan 2022 02:02:14 -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 C2AA568AF73; Tue, 11 Jan 2022 11:59:27 +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 DAE7C68AF43 for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 58A20240685 for ; Tue, 11 Jan 2022 10:59:13 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id UV1kKDa4EY6K for ; Tue, 11 Jan 2022 10:59:12 +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 ECD7F24068D for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 3BA093A0D18; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:26 +0100 Message-Id: <20220111095830.31542-24-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 24/28] ffmpeg_mux: drop a useless check and reduce indentation 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: PAxBopsCwAww do_video_stats() is only ever called for video. --- fftools/ffmpeg_mux.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 76d9d4b9c4..8a64661c9c 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -72,31 +72,29 @@ static void do_video_stats(OutputStream *ost, int frame_size) } enc = ost->enc_ctx; - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { - frame_number = ost->st->nb_frames; - if (vstats_version <= 1) { - fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, - ost->quality / (float)FF_QP2LAMBDA); - } else { - fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number, - ost->quality / (float)FF_QP2LAMBDA); - } + frame_number = ost->st->nb_frames; + if (vstats_version <= 1) { + fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, + ost->quality / (float)FF_QP2LAMBDA); + } else { + fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number, + ost->quality / (float)FF_QP2LAMBDA); + } - if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) - fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); + if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) + fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); - fprintf(vstats_file,"f_size= %6d ", frame_size); - /* compute pts value */ - ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); - if (ti1 < 0.01) - ti1 = 0.01; + fprintf(vstats_file,"f_size= %6d ", frame_size); + /* compute pts value */ + ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); + if (ti1 < 0.01) + ti1 = 0.01; - bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; - avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; - fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", - (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); - fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); - } + bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; + avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; + fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", + (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); + fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type)); } static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others) From patchwork Tue Jan 11 09:58:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33223 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547139iog; Tue, 11 Jan 2022 02:02:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOIdvybQ7/+2THRsPWSmuKQklWOeZOQk2fx3GNCzXOXF/+XJeesSDYFRqjmRIrdTrFTRNT X-Received: by 2002:a17:906:8a72:: with SMTP id hy18mr2884664ejc.614.1641895357023; Tue, 11 Jan 2022 02:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895357; cv=none; d=google.com; s=arc-20160816; b=sJsh2a8Nnjj+RVzok+lpLyqn56qlw5fe8kEOZx9PRuE5sdtQI26MnmqtwBQLTqa2eo iWbz/Or31IJw6t5zcC/virCVWHWwz8YucZ0RC1s9DzijClZbGy0x5KmLa+pY3xBteZTw Wgv9A6FmMtuuL64gR2i8TLXcN3MEl7gOCOqfLvu54TuNvM0+tiebB5fuND0QYDQEOheQ hLajarnvFXmmCFVAXBtX+lemsnR0zmG0G/1B4dnXkrDj0I+ytQHc0M+MnJjahVumu1qc Q55x0BbLUAAQcPNkj3NAHmszhGQ64L2samqn3f/74F8vP6VgP+unZzFEc/4Zm7kUl9Hz GTEA== 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=nqq9hL0HTziw8GJUEePcMP/78inNb8CC/vew3STmVNI=; b=kVBZbr6ChOC+1etbGb8tVW4Ryb4qLbMutprg40FOtfvptfZEmwA+oaEerriNNbfpQW MxbtWwvL+d2OJX/zgR1eq7ROoRApecwl872ra7rRV5Zc7MCENJwcLpMc2rhtTWB9MHJd AfYMguWiLwBFWPWXlkw9ZgrBFYFnhQSzHOC90Y6f0CZ/yhwT7qqclqC+Fm6SXywmbfzm z5sjHQYdPxPqUeHMpBsskR2KFcfe1d7mSGmflH6qZgZ1Z/hVtshB4BeFLnQSXnTcj1JR fNz7dyj7YKClu4cAmOm+/SWPRvhvGwhtMK0HXLph2lJo5gYlCFLVDXk8cpue/8mLjcmz xKYg== 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 nb41si3674166ejc.104.2022.01.11.02.02.36; Tue, 11 Jan 2022 02:02:37 -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 B9E3F68AFF3; Tue, 11 Jan 2022 11:59:29 +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 E1B5868AF57 for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 48EC1240688 for ; Tue, 11 Jan 2022 10:59:14 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id dtB90v8bq9jR for ; Tue, 11 Jan 2022 10:59:13 +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 F1AC7240692 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 3F9083A0D2E; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:27 +0100 Message-Id: <20220111095830.31542-25-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 25/28] ffmpeg_mux: stop using AVStream.nb_frames in do_video_stats() 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: qyVC6/Ayde1G Its use for muxing is not documented, in practice it is incremented per each packet successfully passed to the muxer's write_packet(). Since there is a lot of indirection between ffmpeg submitting a packet to the muxer and it actually being written (e.g. the interleaving queue), using nb_frames to count packets sent to the muxer is incorrect. Use OutputStream.packets_written instead. --- fftools/ffmpeg_mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 8a64661c9c..ef6b7ddd97 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -72,7 +72,7 @@ static void do_video_stats(OutputStream *ost, int frame_size) } enc = ost->enc_ctx; - frame_number = ost->st->nb_frames; + frame_number = ost->packets_written - 1; if (vstats_version <= 1) { fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, ost->quality / (float)FF_QP2LAMBDA); From patchwork Tue Jan 11 09:58:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33224 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547282iog; Tue, 11 Jan 2022 02:02:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJydXe6Kk740nrV7nNCHm8wn0q96a5kqbVEBaVh6Sde2ZNCRMSf+u+UV2x7iN0C/HgqmEfP5 X-Received: by 2002:aa7:d988:: with SMTP id u8mr3569679eds.287.1641895368389; Tue, 11 Jan 2022 02:02:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895368; cv=none; d=google.com; s=arc-20160816; b=lC+gof7fKhWgNV7nEPgIeZfZnIfMjHyE/eMiTY9iardVX8ngSvQfLYikyikb3pq/GL /6+jwUIjl+sBg2d1kds3fp+g9kuIfcHnoydJ4avMG4SBlqv7wW1+2M9EmMClhECGUUdM 0wqrg+HDRyhD053FcDk7P/HLwziJVc3doN6xx/fVO8vFdbh9YURgE/L5ues1Nf5fUYgB WHQoACra5PtZ/IP7deEmy/3OO51n+xvjvDbxu+KqzAXaKX1m7SK+Tq75tKPXMq2IshPC ew0HV7n+GGtpHDW9y2kWgFfPXbIQFTPF2m8XE/5GuEVoyeb3+xho5Z+5nKO4n35Q2viY vyag== 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=FF/wPh4AWN72TE3Ax47GLegqXULWKPrDNenFzEpOARE=; b=bdw/5ftww/WaQNmuDXkmqoqyV4yilEl0cPG/sEc8HgqhFSwt1nZhGxRbJWZpLmZpnN A8S+p8dBHxRkGfI4CIkesK2wRJqBzBMH+YXZuIJpxk+cFYBZWA9K4L42TRykjNAGC5uP 4TVFZ9NrZXfiZRQCm9s3gNz2vpkn9BeXBTEYfsQSgv+CuMC7WzziYtmZLUxujbOe6imA OuNRFZ4vB0k9PJZlTATblyuykg/z8+IJGos+EgLBkp9/J2qXyoUQGvBeAv4b1hLVZzNO 7w76aTdOg8pRsunVxA+IJ06A1/rxTzShspREZ6XodYB2wxh3dN7e4leBmMSme2dl+Tnh bwIg== 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 l26si4195085edr.30.2022.01.11.02.02.48; Tue, 11 Jan 2022 02:02:48 -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 9870468AFFB; Tue, 11 Jan 2022 11:59:30 +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 2ACC268AF5C for ; Tue, 11 Jan 2022 11:59:15 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D1A0E240179 for ; Tue, 11 Jan 2022 10:59:14 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id hcn_AbhfF5Ue for ; Tue, 11 Jan 2022 10:59:14 +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 F0BFB240691 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 43E763A0D4A; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:28 +0100 Message-Id: <20220111095830.31542-26-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 26/28] ffmpeg_mux: stop using av_stream_get_end_pts() in do_video_stats() 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: EoRBRwyueu0O It retrieves libavformat's internal dts value (contrary to the function's name), which is not necessary here because we can access the packet directly. --- fftools/ffmpeg_mux.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index ef6b7ddd97..54020880eb 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -56,7 +56,7 @@ struct Muxer { static int want_sdp = 1; -static void do_video_stats(OutputStream *ost, int frame_size) +static void do_video_stats(OutputStream *ost, const AVPacket *pkt) { AVCodecContext *enc; int frame_number; @@ -84,13 +84,13 @@ static void do_video_stats(OutputStream *ost, int frame_size) if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR)) fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0))); - fprintf(vstats_file,"f_size= %6d ", frame_size); + fprintf(vstats_file,"f_size= %6d ", pkt->size); /* compute pts value */ - ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base); + ti1 = pkt->dts * av_q2d(ost->st->time_base); if (ti1 < 0.01) ti1 = 0.01; - bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; + bitrate = (pkt->size * 8) / av_q2d(enc->time_base) / 1000.0; avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0; fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate); @@ -223,7 +223,7 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed && vstats_filename) - do_video_stats(ost, pkt->size); + do_video_stats(ost, pkt); pkt->stream_index = ost->index; From patchwork Tue Jan 11 09:58:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33222 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547013iog; Tue, 11 Jan 2022 02:02:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1dNfwyyzd43rBTAwnvsqr4I8Dtod8FT5M2yRjkiGJlD9aQzrIDYqFYYNTX8MJFQiRtNch X-Received: by 2002:a17:907:6d9f:: with SMTP id sb31mr3057595ejc.56.1641895345308; Tue, 11 Jan 2022 02:02:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895345; cv=none; d=google.com; s=arc-20160816; b=T6Wzn9rOPKY5KFubO3ryQg7l884ng/9BnDFbZgcU4RobPftJCvmjASWD0DQSh3w+D4 Br3hiHRvSJYJfRGXiopncS6kWBIrm4jel1FxRA3StmAqZ4BmaVZcJOQZ9z6hCTfOpG++ V9dR6xwMVoarVa1uOYYJ63G0m92kmEZSSoZg6cGkqdLWJpZJ/UxwngNdNFGAbeS1F2eO gzgY+U6rUmem5JDbdOxpTmgwATE9m7tcGGH9lIyfRWsGog8xDUyMmMrm229UutJ2IKIR cGTMhB0eGyli85FFotyV5nZ1eNE4AzpRWEWXWAlL+IaKqNRo/Mv1hizTnl03tI2JN+/q 5wuQ== 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=BbBaChJqTbIfTaIPgLq5av/Yn+JrIrbzKsUcZM5ckG0=; b=N0HC/geE+iSP2F7fVeRin8g974puHx531xugV76wIBnTMKIrUAm+OXgfWZ/Y3g4Lhq mYob4ZgePlcHNwRrWHvvplelxwYCBchQKYDnfgT1PnBnbDL0+nLTkmiQPgrxZcbUlUz4 wCK9W904wF2/X998Vzw1DzKH7LNRvR6Hl3B5YDjZGSm0/OOQjZGwKe0RJZuFxgoSelyW T4VG5g55I778FOAnBgg7yAX0Gzvn5t9/J/QwAGfXGm636nvFysQ83kTi1IF4syng8ueW 8mScwgFRxUsN1vYVgr0Y/4boDfu71Pz5NMKKyyz+KiDzpzWl0CTsz2L8yeaTRwQq4RFt qhqg== 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 i22si5449641ejw.616.2022.01.11.02.02.25; Tue, 11 Jan 2022 02:02:25 -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 B618568AFEF; Tue, 11 Jan 2022 11:59:28 +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 E096B68AF55 for ; Tue, 11 Jan 2022 11:59:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CD706240687 for ; Tue, 11 Jan 2022 10:59:13 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 7LTEqBfH1Tmr for ; Tue, 11 Jan 2022 10:59:13 +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 EE3E3240690 for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 483CA3A0DA3; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:29 +0100 Message-Id: <20220111095830.31542-27-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 27/28] ffmpeg_mux: merge variable declaration and initialization 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: +QTz0vKfc+Px --- fftools/ffmpeg_mux.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 54020880eb..21771b3ae6 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -58,7 +58,7 @@ static int want_sdp = 1; static void do_video_stats(OutputStream *ost, const AVPacket *pkt) { - AVCodecContext *enc; + AVCodecContext *enc = ost->enc_ctx; int frame_number; double ti1, bitrate, avg_bitrate; @@ -71,7 +71,6 @@ static void do_video_stats(OutputStream *ost, const AVPacket *pkt) } } - enc = ost->enc_ctx; frame_number = ost->packets_written - 1; if (vstats_version <= 1) { fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, From patchwork Tue Jan 11 09:58:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33231 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3548212iog; Tue, 11 Jan 2022 02:04:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwG5xmKV4nBDzeXZOXgCfTh2z0nJuaHjTh1VLtvoB1qOfJrXTiZl0HLlUnc5Xx/nTYZ8kqD X-Received: by 2002:a05:6402:1a38:: with SMTP id be24mr3593881edb.201.1641895448163; Tue, 11 Jan 2022 02:04:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895448; cv=none; d=google.com; s=arc-20160816; b=YCLvnsQfPGHwtyxJsyzOkETrxAxUSSQJF2O6r2FfkGfuZcc1Zhofv5zy1LbhOhrEej Zyob0URI0ZyRkbFRndG/PxuJ27L8jdLVCU/lLKjC9QFcm8VJRvCYhspB88y4VSEQK1U8 MJF0wUPKu9Bz0Kov5MHAZI23qKgqWfstnsiWLwST+2FULGD7Ps5XLxE0JG4OY2mxUAKD XlS+hyAfPi6rbwhIDahJAS8b8gpJLUuD1Man27nLzRJYVYHIqXmpJ3rPGpQJ/YI/b90c qVv6/sakJygcPhhtCVu61u2LiCm67dD/tCzJDKthSUy9fWZFO019vzGRuzh6oWXVIIYy oZ2w== 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=cxg9cJLoYpRsBzpB3yS23yDz2RdWf/oY2cXjpe1hhqQ=; b=KD9y+64ZGpXkc5rbXWRXTyK0oZHNydkT8vPAgBz4vzzoim3PFZapH6yAmKpftHQmQ3 2mPcjNmMmtyDeDWpGESI2tZLuuLAV4HBww+QiqIRsmT1ra1vL0v+IKUJlZdsFlKqXNWX ds+q4NoCYGGw/imfNwUWJlgQ8cvYN0PbIWaCQ1zeIainbKT45SWWopzyD0yGIBoqKWEg XMON9f+YJYGPzh/fKgtCXrO932UxaRUy9xaN0EliGdPHB/wk5TA/mFoJPih2s4h+3pBX 0fRpnFyU5qEURTv42sCPbpVjtAB51baJpx10t/E5qChUMyXdBmmeRLKvgCs2TTZpB+f/ BasQ== 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 f17si4792235edq.103.2022.01.11.02.04.07; Tue, 11 Jan 2022 02:04:08 -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 3F75668A320; Tue, 11 Jan 2022 11:59:37 +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 F06C568AF7E for ; Tue, 11 Jan 2022 11:59:15 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B3A4E240179 for ; Tue, 11 Jan 2022 10:59:15 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QZXB9Fgkby5g 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 ED47824068F for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 4C8003A0E05; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:30 +0100 Message-Id: <20220111095830.31542-28-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 28/28] ffmpeg_mux: move processing AV_PKT_DATA_QUALITY_STATS to do_video_stats() 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: qxm66J/LeRZb This is a more appropriate place for this code, since the values we read from AV_PKT_DATA_QUALITY_STATS side data are primarily written into video stats. Rename the function to update_video_stats() to better reflect its new purpose. --- fftools/ffmpeg_mux.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 21771b3ae6..52986b002a 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -56,13 +56,28 @@ struct Muxer { static int want_sdp = 1; -static void do_video_stats(OutputStream *ost, const AVPacket *pkt) +static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) { + const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, + NULL); AVCodecContext *enc = ost->enc_ctx; int frame_number; double ti1, bitrate, avg_bitrate; - /* this is executed just the first time do_video_stats is called */ + ost->quality = sd ? AV_RL32(sd) : -1; + ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; + + for (int i = 0; i < FF_ARRAY_ELEMS(ost->error); i++) { + if (sd && i < sd[5]) + ost->error[i] = AV_RL64(sd + 8 + 8 * i); + else + ost->error[i] = -1; + } + + if (!write_vstats) + return; + + /* this is executed just the first time update_video_stats is called */ if (!vstats_file) { vstats_file = fopen(vstats_filename, "w"); if (!vstats_file) { @@ -155,19 +170,6 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) pkt->pts = pkt->dts = AV_NOPTS_VALUE; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - int i; - uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, - NULL); - ost->quality = sd ? AV_RL32(sd) : -1; - ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; - - for (i = 0; ierror); i++) { - if (sd && i < sd[5]) - ost->error[i] = AV_RL64(sd + 8 + 8*i); - else - ost->error[i] = -1; - } - if (ost->frame_rate.num && ost->is_cfr) { if (pkt->duration > 0) av_log(NULL, AV_LOG_WARNING, "Overriding packet duration by frame rate, this should not happen\n"); @@ -220,9 +222,8 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) ost->data_size += pkt->size; ost->packets_written++; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && - ost->encoding_needed && vstats_filename) - do_video_stats(ost, pkt); + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) + update_video_stats(ost, pkt, !!vstats_filename); pkt->stream_index = ost->index;