Introduction
Blu-ray discs store subtitles as pictures, not text, in a format called PGS
(Presentation Graphic Stream). When the subtitle track is extracted from a disc or an
MKV file, it is saved as a .sup file. Each subtitle is a run-length
encoded bitmap with a colour palette, placed at a position on screen.
Because the subtitles are images, they cannot be edited or restyled as text. Tools such as Subtitle Edit use optical character recognition to turn them into SRT.
Structure
The full reference is in Segments, Composition and windows and Palettes and objects.
A SUP file is a series of segments. Each starts with a 13-byte header: the magic bytes
PG (50 47), a 32-bit presentation timestamp and a 32-bit
decoding timestamp on a 90 kHz clock, a segment type byte and a 16-bit size. All
numbers are big-endian.
The segment types, in hexadecimal, are 16, the presentation composition, which says what to
show and when; 17, the window definition; 14, a palette;
15, an object holding the run-length encoded bitmap; and
80, the end of a display set. A display set, from a composition segment to
an end segment, puts one subtitle on screen or clears it.
0MagicPG2 bytes2Presentation timestamp4 bytes6Decoding timestamp4 bytes10Segment type14to17or801 byte11Segment size2 bytes13Segment datavaries
Not described
Blu-ray’s presentation graphics stream is documented by reverse engineering; the Blu-ray specification itself is not public.
Known, not yet covered
- Viewer: the explorer shows every segment (PCS, WDS, PDS, ODS, END) with its fields, the display sets with their presentation times and composition states, the palettes (YCbCr converted to RGB as FFmpeg does, BT.709 above 576 lines and BT.601 otherwise), the objects with fragments joined and run-length data decoded, and each display set composed as a picture. The composed pictures equal FFmpeg's overlay pixel for pixel on the test files. It does not apply cropping (FFmpeg does not either; the page gives both readings of the crop flag), does not draw the windows, and does not decode interactive graphics segments (ICS, type 18) of menu streams, which it names only. Rules that come from FFmpeg's decoder (at most 8 palettes, 64 objects and 2 composition objects, the flush on any state but Normal) are labelled as FFmpeg's, because the Blu-ray specification is not public.
Unknown
- Reference: the value of the crop flag in a composition object: FFmpeg uses 0x80 for cropped and 0x40 for forced, while another write-up gives 0x40 for cropped and no forced flag. The page states both.
Links
Software
- Subtitle Edit – free subtitle editor that converts PGS to text by OCR (Windows, Linux)
- MKVToolNix – adds and extracts PGS tracks in MKV files (Windows, macOS, Linux)
- VLC media player – free media player that shows PGS subtitles (Windows, macOS, Linux, mobile)
- mpv – free, minimal media player that shows PGS subtitles (Windows, macOS, Linux)
- FFmpeg – command-line tools that decode PGS and burn it into video (Windows, macOS, Linux)
- BDSup2Sub – converts and resizes PGS and VobSub subtitles
Developers
- libavcodec – FFmpeg’s codec library, which decodes PGS (C)