From patchwork Fri Apr 13 10:16:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bodecs Bela X-Patchwork-Id: 8435 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp590304jad; Fri, 13 Apr 2018 03:17:03 -0700 (PDT) X-Google-Smtp-Source: AIpwx487r4bFpOx6XWTNpGKAMnPErOAp4R3qKhBVoRNLTxkGtawZt45IJPfN1GmELs0fW9zKyIwW X-Received: by 10.223.164.28 with SMTP id d28mr3152337wra.113.1523614623233; Fri, 13 Apr 2018 03:17:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523614623; cv=none; d=google.com; s=arc-20160816; b=CDWDQTJN2Xu1UFglfa48V4/jwRtnEiCblM/5P1S7pmEBv5zj1fOV1BgeZGkEsxjLQb qqx+dfNHoQ2q3wuALZAP9BccNR5raGGzec1OV3fvj/WUdBIve6R5yF7+zhQzkMQ4xnyH 6MiXupRdK81V2G+lQ50Rl1cogTDl0GZoasRivUR8Aty3MTCnHKCiTBPI/Nc4X16NUrzZ ilyjwwYT1qoA3qpLKnRGrA32ca6dn/rFC0iHiYa7pg0G/wDUOuMGGkibH7hHsdYOQ4Pt +6kVn+TbmjnwgWXeYZvkriTc57gphDu1BWFb+D3gh2OH3RRYa+6dwG0YooOdbImykdhs a7zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:user-agent:date:message-id:from:to :delivered-to:arc-authentication-results; bh=EklYKFOF/nfOejOsS6JzqS+ArZ/tKPzYQa8ggYpc5zc=; b=yUs6DECPgk45DpAK9xoiAehIDpVGtXL/R6jIXWMdEsUy/AdZRL/wgsdoFi5Mg8Cksi eNhLIFeCMtQ6omj1BRxlMmi97WBgfmm4IlB4y2WT0ic5SVca+/QFm1KTcIUnhw75AIqr YVIV9XRuYiwrNVLRWT/nMj1ACiIvOVK8UMPAz9yOyfCuhvy9xuvDWLVc5E1yuLEcxoXF wzH6uS4ObpAULXhRWbXpORZoQ72Cvm3MYU+IBi6kyPTSFGC9t/ECeWTz3iDhwzmmsdEu d0Qctp48AINZkXMSblTnpSKtU+r3f/IHvVnwff6RXnh2t4//yQQ1N+ll8IpfjFcrpA2k +LmQ== 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 j14si1004550wme.149.2018.04.13.03.17.02; Fri, 13 Apr 2018 03:17:03 -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 145A1689F89; Fri, 13 Apr 2018 13:16:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-xsmtp1.externet.hu (mail-xsmtp4.externet.hu [212.40.96.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA285689C25 for ; Fri, 13 Apr 2018 13:16:28 +0300 (EEST) Received: (qmail 32162 invoked from network); 13 Apr 2018 10:16:53 -0000 Received: from mail.officeline.hu (HELO ?10.0.0.10?) (bodecsb@vivanet.hu@217.173.32.91) by 0 with ESMTPA; 13 Apr 2018 10:16:53 -0000 To: FFmpeg development discussions and patches From: Bodecs Bela Message-ID: Date: Fri, 13 Apr 2018 12:16:52 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Language: hu Subject: [FFmpeg-devel] [PATCH] avformat/utils: Stream specifier enhancement 2. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Dear All, In some cases, mainly working with multiprogram mpeg-ts containers as input, it would be handy to select sub stream of a specific program by their metadata. This patch makes it possible to narrow the stream selection among streams of the specified program by stream metadata. Examples: p:601:m:language:hun  will select all sub streams of program with id 601 where sub streams have metadata key named 'language' with value 'hun'. p:602:m:guide  will select all sub streams of program with id 602 where sub streams have metadata key named 'guide'. This syntax enhancement does not interfere in any way with current/existing syntax or working command lines. please review this patch. thank you in advance, best, Bela From fbec3c0c9b8189b1517f33394548c58c112a48ed Mon Sep 17 00:00:00 2001 From: Bela Bodecs Date: Fri, 13 Apr 2018 12:11:32 +0200 Subject: [PATCH] avformat/utils: Stream specifier enhancement 2. In some cases, mainly working with multiprogram mpeg-ts containers as input, it would be handy to select sub stream of a specific program by their metadata. This patch makes it possible to narrow the stream selection among streams of the specified program by stream metadata. Examples: p:601:m:language:hun will select all sub streams of program with id 601 where sub streams have metadata key named 'language' with value 'hun'. p:602:m:guide will select all sub streams of program with id 602 where sub streams have metadata key named 'guide'. Signed-off-by: Bela Bodecs --- doc/fftools-common-opts.texi | 10 ++++++++-- libavformat/utils.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index 79feb39..84705c0 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -42,14 +42,20 @@ streams, 'V' only matches video streams which are not attached pictures, video thumbnails or cover arts. If @var{stream_index} is given, then it matches stream number @var{stream_index} of this type. Otherwise, it matches all streams of this type. -@item p:@var{program_id}[:@var{stream_index}] or p:@var{program_id}[:@var{stream_type}[:@var{stream_index}]] +@item p:@var{program_id}[:@var{stream_index}] or p:@var{program_id}[:@var{stream_type}[:@var{stream_index}]] or +p:@var{program_id}:m:@var{key}[:@var{value}] In first version, if @var{stream_index} is given, then it matches the stream with number @var{stream_index} in the program with the id @var{program_id}. Otherwise, it matches all streams in the -program. In the latter version, @var{stream_type} is one of following: 'v' for video, 'a' for audio, 's' +program. In the second version, @var{stream_type} is one of following: 'v' for video, 'a' for audio, 's' for subtitle, 'd' for data. If @var{stream_index} is also given, then it matches stream number @var{stream_index} of this type in the program with the id @var{program_id}. Otherwise, if only @var{stream_type} is given, it matches all streams of this type in the program with the id @var{program_id}. +In the third version matches streams in the program with the id @var{program_id} 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 #@var{stream_id} or i:@var{stream_id} Match the stream by stream id (e.g. PID in MPEG-TS container). @item m:@var{key}[:@var{value}] diff --git a/libavformat/utils.c b/libavformat/utils.c index cc35998..84b926d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5124,6 +5124,34 @@ FF_ENABLE_DEPRECATION_WARNINGS } return 0; } + + } else if ( *endptr == 'm') { // p::m: + AVDictionaryEntry *tag; + char *key, *val; + int ret = 0; + + if (*(++endptr) != ':') { + av_log(s, AV_LOG_ERROR, "Invalid stream specifier syntax, missing ':' sign after :m.\n"); + return AVERROR(EINVAL); + } + + val = strchr(++endptr, ':'); + key = val ? av_strndup(endptr, val - endptr) : av_strdup(endptr); + if (!key) + return AVERROR(ENOMEM); + + for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) + if (st->index == s->programs[i]->stream_index[j]) { + tag = av_dict_get(st->metadata, key, NULL, 0); + if (tag && (!val || !strcmp(tag->value, val + 1))) + ret = 1; + + break; + } + + av_freep(&key); + return ret; + } else { // p:: int stream_idx = strtol(endptr, NULL, 0); return stream_idx >= 0 &&