From: Marton Balint <cus@passwd.hu>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language
Date: Thu, 9 Jun 2022 00:35:43 +0200 (CEST)
Message-ID: <4b9efd47-b79c-599-b8e-b3dd1b52371@passwd.hu> (raw)
In-Reply-To: <20220419005829.1886458-1-james.darnley@gmail.com>
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".
next prev parent reply other threads:[~2022-06-08 22:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-19 0:58 James Darnley
2022-04-20 18:25 ` Michael Niedermayer
2022-06-08 22:35 ` Marton Balint [this message]
2022-06-08 23:34 ` Soft Works
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4b9efd47-b79c-599-b8e-b3dd1b52371@passwd.hu \
--to=cus@passwd.hu \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git