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 83861429A9 for ; Wed, 8 Jun 2022 22:35:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A849C68B6C2; Thu, 9 Jun 2022 01:35:51 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B70F168B4EF for ; Thu, 9 Jun 2022 01:35:44 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3E48EE7389 for ; Thu, 9 Jun 2022 00:35:45 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VP5XZ5cK7J3H for ; Thu, 9 Jun 2022 00:35:43 +0200 (CEST) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 5D427E7388 for ; Thu, 9 Jun 2022 00:35:43 +0200 (CEST) Date: Thu, 9 Jun 2022 00:35:43 +0200 (CEST) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20220419005829.1886458-1-james.darnley@gmail.com> Message-ID: <4b9efd47-b79c-599-b8e-b3dd1b52371@passwd.hu> References: <20220419005829.1886458-1-james.darnley@gmail.com> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Tue, 19 Apr 2022, James Darnley wrote: > --- > doc/filters.texi | 5 +++++ > libavfilter/vf_subtitles.c | 23 ++++++++++++++++++++--- > 2 files changed, 25 insertions(+), 3 deletions(-) > > diff --git a/doc/filters.texi b/doc/filters.texi > index a161754233..cfbc807f16 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -21160,6 +21160,11 @@ Override default style or script info parameters of the subtitles. It accepts a > string containing ASS style format @code{KEY=VALUE} couples separated by ",". > @end table > > +@item language > +Use first stream with the given language, ISO language code. @code{subtitles} > +filter only. Requires the language metadata to be read from the file. > +@end table Using a stream specifier to select a stream would be more general. Regards, Marton > + > If the first key is not specified, it is assumed that the first value > specifies the @option{filename}. > > diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c > index 82e140e986..95f0a940d9 100644 > --- a/libavfilter/vf_subtitles.c > +++ b/libavfilter/vf_subtitles.c > @@ -54,6 +54,7 @@ typedef struct AssContext { > char *fontsdir; > char *charenc; > char *force_style; > + char *language; > int stream_index; > int alpha; > uint8_t rgba_map[4]; > @@ -271,6 +272,7 @@ static const AVOption subtitles_options[] = { > {"stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS}, > {"si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS}, > {"force_style", "force subtitle style", OFFSET(force_style), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS}, > + {"language", "use first stream of this language", OFFSET(language), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS}, > {NULL}, > }; > > @@ -340,9 +342,8 @@ static av_cold int init_subtitles(AVFilterContext *ctx) > goto end; > > /* Locate subtitles stream */ > - if (ass->stream_index < 0) > - ret = av_find_best_stream(fmt, AVMEDIA_TYPE_SUBTITLE, -1, -1, NULL, 0); > - else { > + /* If the user has specified a particular stream use that. */ > + if (ass->stream_index >= 0) { > ret = -1; > if (ass->stream_index < fmt->nb_streams) { > for (j = 0; j < fmt->nb_streams; j++) { > @@ -357,6 +358,22 @@ static av_cold int init_subtitles(AVFilterContext *ctx) > } > } > > + /* Otherwise find the first stream with the given language code. */ > + else if (ass->language) { > + ret = -1; > + for (j = 0; j < fmt->nb_streams; j++) { > + const AVDictionaryEntry *lang = av_dict_get(fmt->streams[j]->metadata, "language", NULL, 0); > + if (lang && !strcmp(lang->value, ass->language)) { > + ret = j; > + break; > + } > + } > + } > + > + /* Finally fall back to the "best" stream. */ > + else > + ret = av_find_best_stream(fmt, AVMEDIA_TYPE_SUBTITLE, -1, -1, NULL, 0); > + > if (ret < 0) { > av_log(ctx, AV_LOG_ERROR, "Unable to locate subtitle stream in %s\n", > ass->filename); > -- > 2.35.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". > _______________________________________________ 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".