[FFmpeg-devel] [PATCH 2/4] ffmpeg: never output subtitles with zero duration

wm4 nfxjfg at googlemail.com
Mon Nov 18 11:39:00 CET 2013


On Sun, 17 Nov 2013 17:38:11 +0100 (CET)
Marton Balint <cus at passwd.hu> wrote:

> 
> On Sun, 17 Nov 2013, wm4 wrote:
> 
> > On Sun, 17 Nov 2013 15:15:00 +0100
> > Marton Balint <cus at passwd.hu> wrote:
> >
> >> Signed-off-by: Marton Balint <cus at passwd.hu>
> >> ---
> >>  ffmpeg.c               | 2 +-
> >>  tests/ref/fate/sub-srt | 2 +-
> >>  2 files changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/ffmpeg.c b/ffmpeg.c
> >> index b2cebb8..6aafdea 100644
> >> --- a/ffmpeg.c
> >> +++ b/ffmpeg.c
> >> @@ -1808,7 +1808,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
> >>
> >>      sub2video_update(ist, &subtitle);
> >>
> >> -    if (!*got_output || !subtitle.num_rects)
> >> +    if (!*got_output || !subtitle.num_rects || !(subtitle.end_display_time - subtitle.start_display_time))
> >>          return ret;
> >>
> >>      for (i = 0; i < nb_output_streams; i++) {
> >> diff --git a/tests/ref/fate/sub-srt b/tests/ref/fate/sub-srt
> >> index ba5e50a..012d475 100644
> >> --- a/tests/ref/fate/sub-srt
> >> +++ b/tests/ref/fate/sub-srt
> >> @@ -1 +1 @@
> >> -a246a00ed72655cb8db3eaf64a522e0d
> >> +73d62f84a94c148014c97363efd4e0f8
> >
> > This is probably wrong. At least vobsub can have subtitles with unknown
> > duration, and then the duration is set to zero.
> 
> Is this something that we would like to enforce (and document :)) across 
> the API, or VobSub is just a special case? How do the renderer know when 
> to stop displaying a subtitle with zero duration? Or using 
> time-overlapping subtitles and zero duration subtitles should be mutually 
> exclusive?

I'd say this case is a weakness of the API: there's no way to signal
unknown duration. Subtitles where 0 duration is valid and really means
0 do exist (e.g. SRT), so unknown duration is a separate case.

As far as I know, PGS subtitles don't have duration set either. It
appears most bitmap subtitles always stop displaying the current
subtitle when the next begins. If subtitles should disappear entirely
for a while, you get a packet that decodes to 0 subtitle rects.
Overlaps are already merged into the subtitle data, so you get a
completely new subtitle packet if a line appears while another line is
already displayed.

All in all bitmap subtitles are so different from text subtitles, that
I use separate code for them, and I have doubt whether "abstracting"
this more would help at all.

The problem that duration 0 is indistinguishable from duration unknown
should still be fixed, IMO.


More information about the ffmpeg-devel mailing list