From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id DEEA24633B for ; Sat, 15 Jul 2023 10:47:36 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5821A68C6A3; Sat, 15 Jul 2023 13:46:41 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C40BB68C589 for ; Sat, 15 Jul 2023 13:46:35 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 845732404F5 for ; Sat, 15 Jul 2023 12:46:35 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id izeb_H0RxNOn for ; Sat, 15 Jul 2023 12:46:34 +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 D13BF2406CF for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 15AEA3A1E4B for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:48 +0200 Message-Id: <20230715104611.17902-24-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/47] fftools/ffmpeg_opt: reimplement -streamid using a dictionary 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This does not require an arbitrary limit on the number of streams. Also, return error codes from opt_streamid() instead of aborting. --- fftools/ffmpeg.h | 7 ++----- fftools/ffmpeg_mux_init.c | 18 +++++++++++++++--- fftools/ffmpeg_opt.c | 12 +++++------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index ba73dcffdc..8a94cd7861 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -73,8 +73,6 @@ enum EncTimeBase { ENC_TIME_BASE_FILTER = -2, }; -#define MAX_STREAMS 1024 /* arbitrary sanity check value */ - enum HWAccelID { HWACCEL_NONE = 0, HWACCEL_AUTO, @@ -184,9 +182,8 @@ typedef struct OptionsContext { int subtitle_disable; int data_disable; - /* indexed by output file stream index */ - int *streamid_map; - int nb_streamid_map; + // keys are stream indices + AVDictionary *streamid; SpecifierOpt *metadata; int nb_metadata; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 359a5149d4..ac4ef328a6 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1111,12 +1111,24 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (!st) return AVERROR(ENOMEM); - if (oc->nb_streams - 1 < o->nb_streamid_map) - st->id = o->streamid_map[oc->nb_streams - 1]; - ms = mux_stream_alloc(mux, type); ost = &ms->ost; + if (o->streamid) { + AVDictionaryEntry *e; + char idx[16], *p; + snprintf(idx, sizeof(idx), "%d", ost->index); + + e = av_dict_get(o->streamid, idx, NULL, 0); + if (e) { + st->id = strtol(e->value, &p, 0); + if (!e->value[0] || *p) { + av_log(ost, AV_LOG_FATAL, "Invalid stream id: %s\n", e->value); + return AVERROR(EINVAL); + } + } + } + ost->par_in = avcodec_parameters_alloc(); if (!ost->par_in) return AVERROR(ENOMEM); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 25a1083366..7002986369 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -128,8 +128,9 @@ static void uninit_options(OptionsContext *o) #if FFMPEG_OPT_MAP_CHANNEL av_freep(&o->audio_channel_maps); #endif - av_freep(&o->streamid_map); av_freep(&o->attachments); + + av_dict_free(&o->streamid); } static void init_options(OptionsContext *o) @@ -727,7 +728,6 @@ char *file_read(const char *filename) static int opt_streamid(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; - int idx; char *p; char idx_str[16]; @@ -737,13 +737,11 @@ static int opt_streamid(void *optctx, const char *opt, const char *arg) av_log(NULL, AV_LOG_FATAL, "Invalid value '%s' for option '%s', required syntax is 'index:value'\n", arg, opt); - exit_program(1); + return AVERROR(EINVAL); } *p++ = '\0'; - idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1); - o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1); - o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX); - return 0; + + return av_dict_set(&o->streamid, idx_str, p, 0); } static int init_complex_filters(void) -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".