From patchwork Sun Apr 1 21:42:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bodecs Bela X-Patchwork-Id: 8275 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp1906539jad; Sun, 1 Apr 2018 14:42:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/EO58gxOUz51REnycNRIwz6PWS7DyYfagn9ldwQjsHT6QSpmAvPSRPG0LJgmSG5CpyanFh X-Received: by 10.28.126.20 with SMTP id z20mr7164504wmc.152.1522618960521; Sun, 01 Apr 2018 14:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522618960; cv=none; d=google.com; s=arc-20160816; b=rU6hMqcfqk/jYvXLRHLykyFRFGXPrUNuQj1bquvtMQvO7rHx0KUC+Yb4Ok7QUC03bE 0Sv4otm9V41dHx9a/oComhA/9JwKQymip3NqMEKF84lGfuqtZHeWMsKPK1/coULwAGzX mh7nbLzmyV3QgdO02X4dpTkR8xv0y90ehOo+GR5/J52MlxRpdFR6QeFG4pJqkz8b4c0i NTu+Ydi+cMQSfapJfjvSbg1hoah4TZXHoyLFGluyGzrSwiwRIvL4nm3P/tpZy8d0ANWY e9aH3OPTLAzjFPkhj6PZ5vb9hWM4BfrmtOrnAFCqPgS7SGjIX/ieLbx106DnxUy36vTW uUQg== 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=Uc2jG0naPLu5QFDTPNhg/Z4NBrDv4e1N++nzBjDUtL4=; b=Am2OgbAEcrfbMRG/VzZSwexAmlfgTV0G0WUUat8Gn0+uFEKHoZuACPZTzjAWzAgo/U BcikXcyraCRrusRt+GQkUWZCZDCg52ZDQB5FmD/2PcnHJQD1eACl/T9yahaoX9bfT2mr kSmJPYsQlseeMLW7h3+nfygKz/G9fqEAQmpWAZnaGpti+9YlrUKgLj5+0cIvxtMTyX+E lTa0VOg5ldDXGTmMlhs+I4/RI5gUTrEQv27aaoSFEdCvdupOPSlDKRxKhCIxDcNZgmO3 Ru0n1V94R23x7indphJ0/Hnm+EDkRZ+RndE0EHJCz+ORUgZixJp/sN+3aQUeVTJL3zaw eZnQ== 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 h196si6448826wmg.241.2018.04.01.14.42.40; Sun, 01 Apr 2018 14:42:40 -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 EE98B689A70; Mon, 2 Apr 2018 00:42:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-xsmtp2.externet.hu (mail-xsmtp2.externet.hu [212.40.96.153]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 64AE2680414 for ; Mon, 2 Apr 2018 00:42:13 +0300 (EEST) Received: (qmail 19415 invoked from network); 1 Apr 2018 21:42:32 -0000 Received: from unknown (HELO ?192.168.3.7?) (bodecsb@vivanet.hu@100.100.1.36) by 0 with ESMTPA; 1 Apr 2018 21:42:32 -0000 To: FFmpeg development discussions and patches From: Bodecs Bela Message-ID: <0b533ebc-731a-137c-1884-b5b6667c2b1e@vivanet.hu> Date: Sun, 1 Apr 2018 23:42:34 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Language: hu Subject: [FFmpeg-devel] [PATCH] avformat/utils: Stream specifier enhancement 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, currently when specifying the program id you can only decide to select all stream of the specified program (e.g. p:103 will select all streams of program 103) or narrow the selection to a specific stream sub index (e.g. p:145:1 will select 2nd stream of program 145.) But you can not specify like all audio streams of program 145 or 3rd video stream of program 311. In some case, mainly working with multiprogram mpeg-ts containers as input, this feature would be handy. This patch makes it possible to narrow the stream selection among streams of the specified program by stream type and optionally its index. Handled types: a, v, s, d. Examples: p:601:a  will select all audio streams of program 601, p:603:a:1 will select 2nd audio streams of program 603, p:604:v:0 will select first video stream of program 604. This syntax enhancement does not interfere in any way with current/exiting syntax or working command lines please review this patch. thank you in advance, best, Bela From ac3fb61a574e5d945389bf4e725408f3f28835b9 Mon Sep 17 00:00:00 2001 From: Bela Bodecs Date: Sun, 1 Apr 2018 23:29:14 +0200 Subject: [PATCH] avformat/utils: Stream specifier enhancement Currently when specifying the program id you can only decide to select all stream of the specified program (e.g. p:103 will select all streams of program 103) or narrow the selection to a specific stream sub index (e.g. p:145:1 will select 2nd stream of program 145.) But you can not specify like all audio streams of program 145 or 3rd video stream of program 311. In some case, mainly working with multiprogram mpeg-ts containers as input, this feature would be handy. This patch makes it possible to narrow the stream selection among streams of the specified program by stream type and optionally its index. Handled types: a, v, s, d. Examples: p:601:a will select all audio streams of program 601, p:603:a:1 will select 2nd audio streams of program 603, p:604:v:0 will select first video stream of program 604. Signed-off-by: Bela Bodecs --- doc/fftools-common-opts.texi | 10 +++++-- libavformat/utils.c | 65 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index 185ec21..71ad428 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -42,10 +42,14 @@ 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}] -If @var{stream_index} is given, then it matches the stream with number @var{stream_index} +@item p:@var{program_id}[:@var{stream_index}] or p:@var{program_id}[:@var{stream_type}[:@var{stream_index}]] +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. +program. In the latter 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}. @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 f13c820..7d68677 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5062,11 +5062,66 @@ FF_ENABLE_DEPRECATION_WARNINGS if (s->programs[i]->id != prog_id) continue; - if (*endptr++ == ':') { - int stream_idx = strtol(endptr, NULL, 0); - return stream_idx >= 0 && - stream_idx < s->programs[i]->nb_stream_indexes && - st->index == s->programs[i]->stream_index[stream_idx]; + if (*endptr++ == ':') { // p::.... + if ( *endptr == 'a' || *endptr == 'v' || + *endptr == 's' || *endptr == 'd') { // p::[:] + enum AVMediaType type; + + switch (*endptr++) { + case 'v': type = AVMEDIA_TYPE_VIDEO; break; + case 'a': type = AVMEDIA_TYPE_AUDIO; break; + case 's': type = AVMEDIA_TYPE_SUBTITLE; break; + case 'd': type = AVMEDIA_TYPE_DATA; break; + default: av_assert0(0); + } + if (*endptr++ == ':') { // p::: + int stream_idx = strtol(endptr, NULL, 0), type_counter = 0; + for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) { + int stream_index = s->programs[i]->stream_index[j]; + if (st->index == s->programs[i]->stream_index[j]) { +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + return type_counter == stream_idx && + (type == st->codecpar->codec_type || + type == st->codec->codec_type); +FF_ENABLE_DEPRECATION_WARNINGS +#else + return type_counter == stream_idx && + type == st->codecpar->codec_type; +#endif + } +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + if (type == s->streams[stream_index]->codecpar->codec_type || + type == s->streams[stream_index]->codec->codec_type) + type_counter++; +FF_ENABLE_DEPRECATION_WARNINGS +#else + if (type == s->streams[stream_index]->codecpar->codec_type) + type_counter++; +#endif + } + return 0; + } else { // p:: + for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) + if (st->index == s->programs[i]->stream_index[j]) { +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + return type == st->codecpar->codec_type || + type == st->codec->codec_type; +FF_ENABLE_DEPRECATION_WARNINGS +#else + return type == st->codecpar->codec_type; +#endif + } + return 0; + } + } else { // p:: + int stream_idx = strtol(endptr, NULL, 0); + return stream_idx >= 0 && + stream_idx < s->programs[i]->nb_stream_indexes && + st->index == s->programs[i]->stream_index[stream_idx]; + } } for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)