From patchwork Mon Nov 14 15:13:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39277 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp2488562pzb; Mon, 14 Nov 2022 07:15:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Y3LigRu4bfasHxN5VWIUOM4NsrOzAJeg1FveRPtfjg15CCaYm+xw49PAMWHjPoiTk98Dx X-Received: by 2002:a17:906:4113:b0:7aa:97c7:2bfe with SMTP id j19-20020a170906411300b007aa97c72bfemr10439309ejk.196.1668438916800; Mon, 14 Nov 2022 07:15:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668438916; cv=none; d=google.com; s=arc-20160816; b=OaCSntheMiZQCTsH5DSKVt8MLYDI7tKYwVjRGGx76QjCKQ8SXdvhUHi0dK6SUhKN5M 2nVOckw0rk1KZq9nmOavRAhdLwiLMZdz6fq/HK2IARv1FTSPlxH6glU2C69IzFXsiWYr /u8yEJKcapTWCM4enriM4woU0AisUT/6yB04TngY2EM1DTdmYn8IuPBTRx6uM6+9n6kh Zya5Fn8veGcsmjLShsVINhuamd3c7jpPrDsYXwU+NOWkKOXY07HRuXSR0HsMoi12ATe2 yMeB4RWdj15uMCNB6UmJsiz2zDUrzTvkEgXdbMjPyuPZHu8yw3vN44GN/JVdpKPJJJ0U W8TQ== 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=jo6PBmtSWPN5E8EVeKaG0nqUpCkfck9wN/RlQHq9uU4=; b=J4+DtODl2P/zK6gQfUOkRAhr7+9oe3r/6ZLDyQayCB78QDGB1U8wb3CawcDMsrqgd4 Lq64KDS+lzjv0warETiO6bVHTu4WpkUekmtfYvlKVHgdLfVjKJoPhUnptu/Ldt37ONdJ GWhknIoh5Z1HyFiPGxB0EiWy7tpYFR9M2y0Eb0QhCtiUr+6IJXrwFZP0XN4ei4ylsNdp OFZLtKoe4BtHlICuluWaG7lTSIhBpcM75UoS4D6HysQ7YJVwyeaMdjFVs0o4IG44nIr5 5vwRFOnPYXfSExWFJmRwq+/+G0vbyfVOoZ24O0WAMmLXFyLvOo4whdWOrr8Jap0Q0svl WNyw== 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 ga8-20020a1709070c0800b007adffbaa908si9899136ejc.916.2022.11.14.07.15.16; Mon, 14 Nov 2022 07:15:16 -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 B7DD268BE21; Mon, 14 Nov 2022 17:14: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 032A768BE1E for ; Mon, 14 Nov 2022 17:14:25 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9ADE5240591 for ; Mon, 14 Nov 2022 16:14:22 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id JuwwrumG9SJC for ; Mon, 14 Nov 2022 16:14:20 +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 146E82404F8 for ; Mon, 14 Nov 2022 16:14:19 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9CEB43A02FD for ; Mon, 14 Nov 2022 16:14:18 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Nov 2022 16:13:44 +0100 Message-Id: <20221114151350.5134-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221114151350.5134-1-anton@khirnov.net> References: <20221114151350.5134-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] fftools/ffmpeg_mux_init: move more code from of_open() to create_streams() 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: g27S+aWdqPPz Specificaly, the of_add_attachments() call (which can add attachment streams to the output) and the check whether the output file contains any streams. They both logically belong in create_streams(). --- fftools/ffmpeg_mux_init.c | 99 ++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 4755a2cc38..303bf25096 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1062,8 +1062,50 @@ loop_end: } } +static void of_add_attachments(Muxer *mux, const 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(mux, o, -1); + 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 void create_streams(Muxer *mux, const OptionsContext *o) { + AVFormatContext *oc = mux->fc; int auto_disable_v = o->video_disable; int auto_disable_a = o->audio_disable; int auto_disable_s = o->subtitle_disable; @@ -1101,6 +1143,14 @@ static void create_streams(Muxer *mux, const OptionsContext *o) for (int i = 0; i < o->nb_stream_maps; i++) map_manual(mux, o, &o->stream_maps[i]); } + + of_add_attachments(mux, o); + + if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { + av_dump_format(oc, nb_output_files - 1, oc->url, 1); + av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1); + exit_program(1); + } } static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_us) @@ -1194,47 +1244,6 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u return 0; } -static void of_add_attachments(Muxer *mux, const 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(mux, o, -1); - 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 void of_add_programs(AVFormatContext *oc, const OptionsContext *o) { /* process manually set programs */ @@ -1782,14 +1791,6 @@ int of_open(const OptionsContext *o, const char *filename) /* create all output streams for this file */ create_streams(mux, o); - of_add_attachments(mux, o); - - if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { - av_dump_format(oc, nb_output_files - 1, oc->url, 1); - av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1); - exit_program(1); - } - /* check if all codec options have been used */ unused_opts = strip_specifiers(o->g->codec_opts); for (int i = 0; i < of->nb_streams; i++) {