[MPlayer-dev-eng] [PATCH] Style tag support for srt and microdvd subtitles

Jonatan Nilsson jh.nilsson at gmail.com
Wed Nov 4 20:33:28 CET 2009


Greetings,

This patch adds support for font styles in external srt and microdvd
(.sub) subtitles. Srt-subtitles uses html tags to define tags such as
<i> for italic, <b> for bold and the <font> tag, which sets size,
color and face. Microdvd subtitles uses a format of its own, with tags
enclosed in braces { }. The current version of mplayer strips out and
ignores html tags in srt files, while nothing is done at all about
microdvd tags. Microdvd tags do, however, get stripped by accident (or
luck) if libass is used to render them since ass tags also uses
braces.

What the patch does in short:
1. In subreader.h: added a struct to contain info about any style
changes in a subtitle. The existing subtitle struct will now contain a
list of these.

2. In subreader.c: rewrote sub_read_line_subviewer and
sub_read_line_microdvd to make them handle tags. Tags parsed are saved
in the style struct which is added to the subtitle struct.

3. In function libass/ass_mp.c: ass_process_subtitle: added code that
converts style structs in the subtitle processed to corresponding ssa
tags.

4. In subreader.c: Added corresponding functionality to the functions
dump_srt and dump_microdvd to print out the subtitle's style tags.

The style changes will only be visible if libass is used to render
them. I only had a quick look at how it could be done using the
regular font rendering and determined that it would be trickier. That
change could possibly be done in the future, the style info is parsed
anyway and is available in the subtitle struct.

The version of libass that is currently included in mplayer does not
handle underline or strike-through, so those styles won't be shown.
The external libass handles them however, so as soon as mplayer starts
using the external libass they should start working automatically.

Along with the patch, I'm also attaching two example subtitle files so
you could try it out. I guess the patch is pretty large, I didn't
split it because the different patches (if split into logical parts)
would patch to the same file, and probably to adjacent parts of it,
which may cause more harm than good. But if you want me to split it
anyway, I'd be happy to.

Regards,
Jonatan Nilsson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: subtitle_styles.diff
Type: text/x-patch
Size: 33689 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20091104/2256f284/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: srt_example.srt
Type: application/octet-stream
Size: 470 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20091104/2256f284/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: microdvd_example.sub
Type: text/x-microdvd
Size: 272 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20091104/2256f284/attachment-0001.bin>


More information about the MPlayer-dev-eng mailing list