From patchwork Wed Aug 3 13: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: 37098 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp457450pzb; Wed, 3 Aug 2022 06:59:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sOo8h1DhQhjQb8tJISpPrzFRTGonbroxorwLChCIJNDfF9zGDVsx9EBWIoK2xdvE4NPsNA X-Received: by 2002:a17:906:fe0b:b0:730:3646:d177 with SMTP id wy11-20020a170906fe0b00b007303646d177mr18291913ejb.688.1659535147648; Wed, 03 Aug 2022 06:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535147; cv=none; d=google.com; s=arc-20160816; b=OO1yHghfwdL29mOrss0lpHRS0uKFC1UYhOrpYJaXkp5/4LTjf8LNTPK63lRTOpniaA fLRbjJQMu/uMCy+38PrmLZStNx+BP9vLln5BpslxcDccK3KIYdp8ia8PJw3apOHmX/Es 2rzcK0RNJauLtG5gED25ynQm1AJmUdDllxxu/ANxbtkwa4lLvTLBzP0O+KTAHcrOVPGS E3JeG16Hljkuqt37gTbHwFDRdr0hDeB7ls5jyPddFMkDEb7oWmv/roYWNDsfRGu3b7Tg BnZSDlcUeL034/YGSFJPaz5MakCYDemB7cFnXbJ0hz5+OBJexAXhTmC1COFNfDI13NXJ mSlw== 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=TN/96EK/RX3yZA+qgRRi/7KZ1KdF+pNMGUPbavmBPvk=; b=bb+LweVij+YiZsvdNgRENAB5VmCMC3yFteKQ/VrJfMbhMFlaEJlqWJI265tTIW0Asx yFsMeaBtfqHBxtXNKaERB2xrVVpcz7O6K5th+RPekyBJoPZ7KOgtDJUyWGmaDVwrT138 BuWXxs7sTRHVzFMBkSuMbOzkd07dSNeoD6u4YV+g4Y1+0FkUU5bEDP1GvLzCbZXsThjY cZldqcg7141srg9OgTQiTUR+Fqy803czP/edudeco8h7HOE/6ho5NxTr0cEHtvgLX7ww 2QXlYnqU03eX8ZfC2o93fHeukciA4EI/p2Y+UPVR0+0hn7mAv5nmIeVfTRYMcEpt6UE1 hQbw== 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 jg42-20020a170907972a00b007307a8f0c3fsi8374019ejc.381.2022.08.03.06.59.06; Wed, 03 Aug 2022 06:59:07 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C618168B7E2; Wed, 3 Aug 2022 16:59:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1848768B4DC for ; Wed, 3 Aug 2022 16:58:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5985B24068F for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id F4__uKAC0lfN for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 94B1F2400F5 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id DD39F3A03EF; Wed, 3 Aug 2022 15:58:51 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:20 +0200 Message-Id: <20220803135844.16662-1-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_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: cpq+DHTxQMlX --- fftools/ffmpeg_opt.c | 79 ++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index a8b064e070..0d5323ea73 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2742,6 +2742,48 @@ loop_end: } } +static void of_add_attachments(AVFormatContext *oc, OptionsContext *o) +{ + OutputStream *ost; + int err; + + for (int i = 0; i < o->nb_attachments; i++) { + AVIOContext *pb; + uint8_t *attachment; + const char *p; + int64_t len; + + if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) { + av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n", + o->attachments[i]); + exit_program(1); + } + if ((len = avio_size(pb)) <= 0) { + av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n", + o->attachments[i]); + exit_program(1); + } + if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE || + !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) { + av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n", + o->attachments[i]); + exit_program(1); + } + avio_read(pb, attachment, len); + memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); + + ost = new_attachment_stream(o, oc, -1); + ost->stream_copy = 0; + ost->attachment_filename = o->attachments[i]; + ost->st->codecpar->extradata = attachment; + ost->st->codecpar->extradata_size = len; + + p = strrchr(o->attachments[i], '/'); + av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE); + avio_closep(&pb); + } +} + static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; @@ -2831,42 +2873,7 @@ static int open_output_file(OptionsContext *o, const char *filename) map_manual(of, oc, o, &o->stream_maps[i]); } - /* handle attached files */ - for (i = 0; i < o->nb_attachments; i++) { - AVIOContext *pb; - uint8_t *attachment; - const char *p; - int64_t len; - - if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) { - av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n", - o->attachments[i]); - exit_program(1); - } - if ((len = avio_size(pb)) <= 0) { - av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n", - o->attachments[i]); - exit_program(1); - } - if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE || - !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) { - av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n", - o->attachments[i]); - exit_program(1); - } - avio_read(pb, attachment, len); - memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); - - ost = new_attachment_stream(o, oc, -1); - ost->stream_copy = 0; - ost->attachment_filename = o->attachments[i]; - ost->st->codecpar->extradata = attachment; - ost->st->codecpar->extradata_size = len; - - p = strrchr(o->attachments[i], '/'); - av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE); - avio_closep(&pb); - } + of_add_attachments(oc, o); if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(oc, nb_output_files - 1, oc->url, 1);