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 4FAF149457 for ; Sat, 10 Aug 2024 17:17:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 86A5B68DAC1; Sat, 10 Aug 2024 20:16:43 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5288A68D93B for ; Sat, 10 Aug 2024 20:16:35 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=GgIFnkuU; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id CB670EE6 for ; Sat, 10 Aug 2024 19:16:34 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id drjh8gzgHM33 for ; Sat, 10 Aug 2024 19:16:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1723310193; bh=TCsqoCtvwq1erUiJWG8srBWEA1jR5A5SZU0AT25RKms=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GgIFnkuUZDJ2lhFG5Hkfcq9vLP/WfWg9XFRG9IsHoGmeeYsqP2pHVWy1yrjYwTCY6 128yg2NT99EK31lcMCBTqSPlH7m070edAaQu4Sn+9j/IuTKXcG8ZriZpVmuGMwo6Lg fL31b5+DXMpOP0ETFgAHpfTN0IDaXfMAIYMTA5F3zrTdxHwKp3M2TRGfTklnW5G5e3 YvwCCzFbKd024KpMXGsa7Q+itUS+b1QX9mfsMkXtjQ2yJScNCes81kBYjunSvhUpOz LyuzWrvBSaEqej9d9RSgEbMhvMmA/siauPgCZSa7D7G88/HmAOC4MibDFr7h/5Pdc+ +sRq5rYwFloew== 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 mail1.khirnov.net (Postfix) with ESMTPS id 51F2B4DDB for ; Sat, 10 Aug 2024 19:16:33 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7673A3A27B8 for ; Sat, 10 Aug 2024 19:16:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Aug 2024 19:16:21 +0200 Message-ID: <20240810171621.26757-6-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240810171621.26757-1-anton@khirnov.net> References: <20240810171621.26757-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] fftools/ffmpeg: switch -map parsing to new stream specifier API 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: Makes optional map handling less hacky, fixes combining optional maps with metadata matching on tags/values containing the '?' character/ Forward errors from stream specifier parsing, previously the code would ignore them. --- fftools/ffmpeg_opt.c | 54 ++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index f6df6ae952..3cbf0795ac 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -427,22 +427,20 @@ static int opt_map(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; StreamMap *m = NULL; + StreamSpecifier ss; int i, negative = 0, file_idx, disabled = 0; - int ret; - char *map, *p; - char *allow_unused; + int ret, allow_unused = 0; + + memset(&ss, 0, sizeof(ss)); if (*arg == '-') { negative = 1; arg++; } - map = av_strdup(arg); - if (!map) - return AVERROR(ENOMEM); - if (map[0] == '[') { + if (arg[0] == '[') { /* this mapping refers to lavfi output */ - const char *c = map + 1; + const char *c = arg + 1; ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps); if (ret < 0) @@ -451,33 +449,55 @@ static int opt_map(void *optctx, const char *opt, const char *arg) m = &o->stream_maps[o->nb_stream_maps - 1]; m->linklabel = av_get_token(&c, "]"); if (!m->linklabel) { - av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map); + av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", arg); ret = AVERROR(EINVAL); goto fail; } } else { - if (allow_unused = strchr(map, '?')) - *allow_unused = 0; - file_idx = strtol(map, &p, 0); + char *endptr; + + file_idx = strtol(arg, &endptr, 0); if (file_idx >= nb_input_files || file_idx < 0) { av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx); ret = AVERROR(EINVAL); goto fail; } + arg = endptr; + + ret = stream_specifier_parse(&ss, *arg == ':' ? arg + 1 : arg, 1, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Invalid stream specifier: %s\n", arg); + goto fail; + } + + if (ss.remainder) { + if (!strcmp(ss.remainder, "?")) + allow_unused = 1; + else { + av_log(NULL, AV_LOG_ERROR, "Trailing garbage after stream specifier: %s\n", + ss.remainder); + ret = AVERROR(EINVAL); + goto fail; + } + } + if (negative) /* disable some already defined maps */ for (i = 0; i < o->nb_stream_maps; i++) { m = &o->stream_maps[i]; if (file_idx == m->file_index && - check_stream_specifier(input_files[m->file_index]->ctx, + stream_specifier_match(&ss, + input_files[m->file_index]->ctx, input_files[m->file_index]->ctx->streams[m->stream_index], - *p == ':' ? p + 1 : p) > 0) + NULL)) m->disabled = 1; } else for (i = 0; i < input_files[file_idx]->nb_streams; i++) { - if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i], - *p == ':' ? p + 1 : p) <= 0) + if (!stream_specifier_match(&ss, + input_files[file_idx]->ctx, + input_files[file_idx]->ctx->streams[i], + NULL)) continue; if (input_files[file_idx]->streams[i]->user_set_discard == AVDISCARD_ALL) { disabled = 1; @@ -511,7 +531,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg) } ret = 0; fail: - av_freep(&map); + stream_specifier_uninit(&ss); return ret; } -- 2.43.0 _______________________________________________ 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".