* [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language
@ 2022-04-19 0:58 James Darnley
2022-04-20 18:25 ` Michael Niedermayer
2022-06-08 22:35 ` Marton Balint
0 siblings, 2 replies; 4+ messages in thread
From: James Darnley @ 2022-04-19 0:58 UTC (permalink / raw)
To: ffmpeg-devel
---
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
+
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language
2022-04-19 0:58 [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language James Darnley
@ 2022-04-20 18:25 ` Michael Niedermayer
2022-06-08 22:35 ` Marton Balint
1 sibling, 0 replies; 4+ messages in thread
From: Michael Niedermayer @ 2022-04-20 18:25 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1162 bytes --]
On Tue, Apr 19, 2022 at 02:58:29AM +0200, 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
that @end table looks a bit like its not matched
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If the United States is serious about tackling the national security threats
related to an insecure 5G network, it needs to rethink the extent to which it
values corporate profits and government espionage over security.-Bruce Schneier
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language
2022-04-19 0:58 [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language James Darnley
2022-04-20 18:25 ` Michael Niedermayer
@ 2022-06-08 22:35 ` Marton Balint
2022-06-08 23:34 ` Soft Works
1 sibling, 1 reply; 4+ messages in thread
From: Marton Balint @ 2022-06-08 22:35 UTC (permalink / raw)
To: FFmpeg development discussions and patches
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language
2022-06-08 22:35 ` Marton Balint
@ 2022-06-08 23:34 ` Soft Works
0 siblings, 0 replies; 4+ messages in thread
From: Soft Works @ 2022-06-08 23:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Marton
> Balint
> Sent: Thursday, June 9, 2022 12:36 AM
> 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
>
>
>
> 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.
The filter has an "si" parameter (stream index) which is equivalent to
-s:<si>
I understand the desire for being able to choose by language but I'm not sure
whether that's a good idea in this context.
The vf_subtitles filter has always been a workaround over the lack of subtitle
filtering. Without that, it's not possible to move subtitles through a filter
graph, so the vf_subtitles filter does something pragmatic: It opens the input
file a second time and in parallel (assuming the subtitles are in the same media
file as the video onto which these are meant to be overlaid).
This is often leading to sub-optimal performance and even worse when the file
is accessed over network (made up of cheap devices..)
It's already a pretty odd case because vf_subtitles needs to link to both,
avformat and avcodec to do its work.
I'm not sure whether it is right to blow up the vf_subtitles implementation
for parsing and decoding with some special stream selection.
I think once there would be a parameter added for selecting by language, then
there wouldn't be a valid reason anymore to deny the next one requesting a
parameter for choosing only forced subs, another one for excluding (or preferring)
hearing impaired subs, and once again a language-fallback parameter (if lang A isn't
available then lang B), and also a fallback-behavior parameter (like fail or choose
any).
Thinking about this, we'll also realize: ffmpeg itself doesn't have such kind
of stream selection capabilities. I'm not sure whether this is desirable,
maybe it is useful for some, but in case, it should be implemented in
ffmpeg tool to it would be useful in a wide range of cases instead.
Finally, subtitle filtering obsoletes vf_subtitles. It needs to be kept for
compatibility for some time, but it's an inferior option then.
Best regard,
softworkz
_______________________________________________
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-08 23:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 0:58 [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language James Darnley
2022-04-20 18:25 ` Michael Niedermayer
2022-06-08 22:35 ` Marton Balint
2022-06-08 23:34 ` Soft Works
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