[FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add an option to choose sub stream by language

Soft Works softworkz at hotmail.com
Thu Jun 9 02:34:01 EEST 2022



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of Marton
> Balint
> Sent: Thursday, June 9, 2022 12:36 AM
> To: FFmpeg development discussions and patches <ffmpeg-devel at 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
> >
> > + at 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.
> > + at 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






More information about the ffmpeg-devel mailing list