From patchwork Sun Sep 15 20:32:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51610 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9fc3:0:b0:48e:c0f8:d0de with SMTP id k3csp932960vqy; Sun, 15 Sep 2024 13:44:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVhBOqMIYK7QXeyX5YXuNrDa0ukw9ZmJnN/vgWgVn1CbGLQtea9H33v3BeZOuZRIEPZdXQ0Jtw+HOymroSv3iij@gmail.com X-Google-Smtp-Source: AGHT+IHo0vYPs5xMR0dvdUryNLfFrAlYJENgaSTAjK4GrpiVCKQVZB/iqEYmx5gzk/V/xzLPCgwQ X-Received: by 2002:a05:6402:40c5:b0:5c4:23a4:ad54 with SMTP id 4fb4d7f45d1cf-5c423a4afc7mr7513803a12.32.1726433053435; Sun, 15 Sep 2024 13:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726433053; cv=none; d=google.com; s=arc-20240605; b=XHNmoT7nHNC5SCS/IsIG6m7LYDVC4th05PgjzCCAAienMNqT4mVvkvIZzTdJDHF3Y4 6iKhESmee6Scsm33SvLAALBIzak+6xevNbbmS7lbxZREl3szAE9NNwB/KfhehpCCAsG4 mq/7jMHDV+Qdc3qvtmJ3+Fma2V8Qqj68Nh0gAMxtI0aOKqSEShkGWKW8jLiYqdvkZ0p8 xQpB7MBvZ/NcZlMNJhcmsFew7FdnmrJnHjoIdu79l9iKleMB0y8OeDf1Ips0imETI9ia pYQbp3Y8dPJeF+B0hRdfjzTYcOirPia+BJQFlI+mY+cUEu6GFhyYX/yYMcCvErUDGmRp FmIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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 :dkim-signature:delivered-to; bh=8NHEonq7dvhruIdz2oqMo+7dfN9/L8OMCjnrLGjjQPc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=W3h/Ax05qQbcO2+hon3W7BBy8xQP7trq4onhys5sHzboHDHUMm9rWie+wL58gY60U4 6CrB+tM5IhCvw29GdH4IVH5Zsg+9oEqcsdg4SzNV6qJdbMPqA00N+IEzcn8bkAGyTeIX j4Zdz5EHs6hIcv+oJvpzUCehNjpDHON4D1nf0Y7IlIkdpAFiTXefGZEhDnAYMq+6vSK1 ADe7hlGItTJieNh7EWEgaHT0i5m3sVxlVYR6L0VFResq+D5e2A/g4D4hYi1eB9cupldb cajM0Hli8Jsuhfz6/en6Ce9URVImbj2AovtH+UcfEYBO7RSo/IpNdLAHk5X0YUsITJPe KSGQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=MiLYnWsb; 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 4fb4d7f45d1cf-5c42bcac055si2783670a12.535.2024.09.15.13.44.11; Sun, 15 Sep 2024 13:44:13 -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; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=MiLYnWsb; 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 B981B68DC5E; Sun, 15 Sep 2024 23:33:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3E09E68DC46 for ; Sun, 15 Sep 2024 23:33:38 +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=MiLYnWsb; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 885E84DF6 for ; Sun, 15 Sep 2024 22:33:37 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id pc_U0Ocmx4DP for ; Sun, 15 Sep 2024 22:33:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1726432414; bh=N7pRieVOqxo+uNhz/hM463VQq5/ne/DGukeBl97wKLI=; h=From:To:Subject:Date:From; b=MiLYnWsbwgJMn3VAyjd0BJJzlm+HaSkoAS3AIT2zTfwZEI6OCenY20w2ABZAQu9SN TxWMSpNDJB8Rs3TcqZCMfkEIOTlrM2XQHJq9q5/4NxadQwRynP0RH4BVMKTlylYFgS IJ8EjEGy7Ke+WdezN+VqctX82Vz17lUlPpi2fYdM3jQpKbuHl0FF4L/56gq5qj8d3b 1OfteDsxapIKHUj+ZOqj9G8d1ANZ7YOd0/CzGQRZUVfN0hHMRRMj9nlQ/Ukgebqr/f RDCdbjVn9iYx7Gvh1Dwp4rHa38TiCHNFtbPzcwtB86BPssvGz4z80ysYXzoriH6WxP aQrxPiqmbfv6A== 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 C0A254DE1 for ; Sun, 15 Sep 2024 22:33:34 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8DA203A0229 for ; Sun, 15 Sep 2024 22:33:28 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Sep 2024 22:32:48 +0200 Message-ID: <20240915203248.17917-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fftools/cmdutils: extend stream specifiers to match by disposition 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: SkG488Zj4bHI --- Changelog | 1 + doc/fftools-common-opts.texi | 4 +++ fftools/cmdutils.c | 41 ++++++++++++++++++++++++++ fftools/cmdutils.h | 2 ++ tests/fate/ffmpeg.mak | 4 +++ tests/ref/fate/ffmpeg-spec-disposition | 7 +++++ 6 files changed, 59 insertions(+) create mode 100644 tests/ref/fate/ffmpeg-spec-disposition diff --git a/Changelog b/Changelog index b6f91d7c8c..abe99075e8 100644 --- a/Changelog +++ b/Changelog @@ -21,6 +21,7 @@ version : - MediaCodec AAC/AMR-NB/AMR-WB/MP3 decoding - YUV colorspace negotiation for codecs and filters, obsoleting the YUVJ pixel format +- stream specifiers in fftools can now match by stream disposition version 7.0: diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index 1974d79a4c..4e48789def 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -79,6 +79,10 @@ Match the stream by stream id (e.g. PID in MPEG-TS container). Matches streams with the metadata tag @var{key} having the specified value. If @var{value} is not given, matches streams that contain the given tag with any value. +@item disp:@var{dispositions}[:@var{additional_stream_specifier}] +Matches streams with the given disposition(s). @var{dispositions} is a list of +one or more dispositions (as printed by the @option{-dispositions} option) +joined with '+'. @item u Matches streams with usable configuration, the codec must be defined and the essential information such as video dimension or audio sample rate must be present. diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 1573106d8b..8d06358cac 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -1091,6 +1091,43 @@ int stream_specifier_parse(StreamSpecifier *ss, const char *spec, av_log(logctx, AV_LOG_TRACE, "Parsed program ID: %"PRId64"; remainder: %s\n", ss->list_id, spec); + } else if (!strncmp(spec, "disp:", 5)) { + const AVClass *st_class = av_stream_get_class(); + const AVOption *o = av_opt_find(&st_class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ); + char *disp = NULL; + size_t len; + + av_assert0(o); + + if (ss->disposition) { + av_log(logctx, AV_LOG_ERROR, "Multiple disposition specifiers\n"); + ret = AVERROR(EINVAL); + goto fail; + } + + spec += 5; + + for (len = 0; cmdutils_isalnum(spec[len]) || + spec[len] == '_' || spec[len] == '+'; len++) + continue; + + disp = av_strndup(spec, len); + if (!disp) { + ret = AVERROR(ENOMEM); + goto fail; + } + + ret = av_opt_eval_flags(&st_class, o, disp, &ss->disposition); + av_freep(&disp); + if (ret < 0) { + av_log(logctx, AV_LOG_ERROR, "Invalid disposition specifier\n"); + goto fail; + } + + spec += len; + + av_log(logctx, AV_LOG_TRACE, + "Parsed disposition: 0x%x; remainder: %s\n", ss->disposition, spec); } else if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) { if (ss->stream_list != STREAM_LIST_ALL) @@ -1281,6 +1318,10 @@ unsigned stream_specifier_match(const StreamSpecifier *ss, } } + if (ss->disposition && + (candidate->disposition & ss->disposition) != ss->disposition) + continue; + if (st == candidate) return ss->idx < 0 || ss->idx == nb_matched; diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 9441d5726b..e74aa2a98d 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -130,6 +130,8 @@ typedef struct StreamSpecifier { uint8_t usable_only; + int disposition; + char *meta_key; char *meta_val; diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index 3ffaaeb295..869376dd18 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -263,3 +263,7 @@ fate-ffmpeg-loopback-decoding: CMD = transcode \ "rawvideo -s 352x288 -pix_fmt yuv420p" $(TARGET_PATH)/tests/data/vsynth1.yuv nut \ "-map 0:v:0 -c:v mpeg2video -f null - -flags +bitexact -idct simple -threads $$threads -dec 0:0 -filter_complex '[0:v][dec:0]hstack[stack]' -map '[stack]' -c:v ffv1" "" FATE_FFMPEG-$(call ENCDEC2, MPEG2VIDEO, FFV1, NUT, HSTACK_FILTER PIPE_PROTOCOL FRAMECRC_MUXER) += fate-ffmpeg-loopback-decoding + +# test matching by stream disposition +fate-ffmpeg-spec-disposition: CMD = framecrc -i $(TARGET_SAMPLES)/mpegts/pmtchange.ts -map '0:disp:visual_impaired+descriptions:1' -c copy +FATE_FFMPEG-$(call FRAMECRC, MPEGTS,,) += fate-ffmpeg-spec-disposition diff --git a/tests/ref/fate/ffmpeg-spec-disposition b/tests/ref/fate/ffmpeg-spec-disposition new file mode 100644 index 0000000000..4f24619d2b --- /dev/null +++ b/tests/ref/fate/ffmpeg-spec-disposition @@ -0,0 +1,7 @@ +#tb 0: 1/90000 +#media_type 0: audio +#codec_id 0: ac3 +#sample_rate 0: 48000 +#channel_layout_name 0: stereo +0, 0, 0, 2880, 768, 0x72b37931, F=0x3, S=1, 1 +0, 2880, 2880, 2880, 690, 0xa84a4ea2