From patchwork Mon Dec 13 15:20:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 32425 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5573125iog; Mon, 13 Dec 2021 07:23:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcdT6szUch30s/rfS9FEeKw5FUuRLWLPfxB+ZxcaX0zZPa/CjwenkEGvR/K6KBNqsm+sJp X-Received: by 2002:a50:ce46:: with SMTP id k6mr64095540edj.45.1639408989255; Mon, 13 Dec 2021 07:23:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639408989; cv=none; d=google.com; s=arc-20160816; b=HTzVDdSTs9FvPp/2vhEP5kyP2iPvqdbZ7zUu014AmG+V1Ao6GFbSb2BKG71pi20ewT Jqzewhmd2tvZkj+jYqOuXIDgPbs0NhsdWwHOpyW9VszaCMRfk/goEI8YJIBoulgLnJH8 ARE5hrfpHVcBPUNTyqlp+TBRPE1Uk+v0UiT47ebxdXgb10NyxjL78rQV5VsA6cZtzFtR D8xlwWVY3zvPmGvIim9warhee27ncIyS9TQMWaxavKQLCFB6PYEwKDch1B9Xh5cWVVbv bekvqbLMchRXkB2adtCeqPhrPVeOMfhA/ofK526/H32VY6H3Ed+ubX+U0gyxirWUr+st 3yxg== 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=yODfgVJi+TFd/3w8DTVFaxGhhqbrAPhkLFskU7MhU0M=; b=yu8WVWEq1WlS0TC1u+GP6X1GsOhmK9QwNYQsQWm3a+vHJLgjy0rb0VHJEfXAmIJDkp UWkJS/CSA7/V+sSkmQhAFM2Lgrh8Xaa1DxJhuCuJCEYzd7M2UWj5pPDotyzyuaN/uHjz UI8/YQ/jXKY4Qxl/diSd31nFnZ2OfbOenHUIjBFEuVh2cThMAp4T3Q1+VqXjICZ7E7Bc C9W2ohlchRhz2OFv2YOQBuE/GHecT9dqDL0bhGOnz05wXQG/KB71aSxeYb1PhNdhPTA5 gufaotf/C/PpNnQvWIHfTjd59kI8OpuF9b7kROojGBrjPj6/pJ/FRgHd2mZCznH+j3oJ JDLg== 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 lf8si15000915ejb.635.2021.12.13.07.23.08; Mon, 13 Dec 2021 07:23:09 -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 20A1368AFBC; Mon, 13 Dec 2021 17:22: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 EB24568807F for ; Mon, 13 Dec 2021 17:22:09 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 861B32404FE for ; Mon, 13 Dec 2021 16:22:09 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id EiiUcL44btjH for ; Mon, 13 Dec 2021 16:22: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 8E667240507 for ; Mon, 13 Dec 2021 16:22:07 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1FB313A0769; Mon, 13 Dec 2021 16:22:07 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Dec 2021 16:20:24 +0100 Message-Id: <20211213152042.5900-6-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213152042.5900-1-anton@khirnov.net> References: <20211213152042.5900-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/24] 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: MIDhkTALt8bx --- 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 a00fe58063..1fb10869b4 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -4436,19 +4436,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 (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 e7c6ddd8f8..fec8537506 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; +}