[FFmpeg-devel] [PATCH v5] Add SUP/PGS subtitle demuxer

Petri Hintukainen phintuka at gmail.com
Wed Sep 3 12:44:45 CEST 2014


On ma, 2014-09-01 at 16:45 +0200, wm4 wrote:
> On Mon, 1 Sep 2014 08:34:52 +0000 (UTC)
> Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
>
> > wm4 <nfxjfg <at> googlemail.com> writes:
> > > +        full_packet_size = AV_RB16(buf + 10 + 1) + 10 + 3;
> > > +        if (buf_size < full_packet_size)
> > > +            break;
> > 
> > I don't know if it is worth the effort, but you could 
> > check for the first byte as well:
> > if (buf[10] != 0x80 || (buf[10] | 3) != 17)
> >     break;
> > With this change, you could increase the scores, reduce 
> > the number of maximum packets in the loop and maybe 
> > speed up probing iiuc.
> 
> the 10th byte is the segment type field. Are you sure this check covers
> all valid types? What if the format is extended later with more types?
 
Interactive Graphics Streams use 0x18 (Interactive Composition Segment).
I don't see any reason why IG streams could not be muxed to .sup file,
but I don't know if it is "allowed" and if such files exist in real
life.

BluRay text subtitle streams use 0x81 (Dialog Style Segment) and 0x82
(Dialog Presentation Segment).

I don't know if 3D PGS uses some additional segment types. But this is
unlikely, most (if not all) PG 3D parameters are stored in metadata or
embedded in H.264 mvc scalable nesting SEI messages.


Here are some other "rules" that could be used in probing:

Order of segments in PG display set is fixed:

PCS [WDS] [PDS ...] [ODS ...] END

Unless the stream was cut from middle of display set, it always starts
with Presentation Composition Segment and ends to End Of Display. (If
stream was cut, and there are any segments before first PCS, those are
useless).

Segment size can't be random value:
PCS
- 11th byte should be < 3 (= N)
- payload length must be 11 + 8*N + 8*C   (where C <= N)
WDS
- first byte should be < 3 (= N)
- payload length should be 9*N + 1
PDS
- first byte should be < 8
- payload length should be 5*N + 2, where N is 0...255
ODS
- payload starts with 16-bit integer, value should be < 0x40
END
- payload length should be 0
(I can double check those if those will be used)

Muxing order and dependencies in presentation also imply some
easy-to-check rules for timestamps.

> > > +    if (nb_packets < 4)
> > > +        return AVPROBE_SCORE_RETRY;
> > 
> > If you find three consecutive packets on the 
> > start of the file, at least EXTENSION is 
> > appropriate imo even without checking the 
> > content, possibly more.
> 
> I can do that, though then I'd return AVPROBE_SCORE_RETRY + 1. AFAIK
> this is the lowest score that means "safe detection", and it possibly
> gives room for other formats in case of misdetection. EXTENSION is
> pretty high.
> 
> If I change this, I'd have to adjust the following checks too so that
> it makes sense. Suggestions?
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel




More information about the ffmpeg-devel mailing list