[FFmpeg-devel] Internal handling of subtitles in ffmpeg

Patrik patrik
Wed Dec 17 21:24:22 CET 2008

Hey guys.

I am looking into adding some subtitle support to ffmpeg and want to
share an idea before going on.

I have noticed that subtitles are sent internally in ffmpeg between
decoders and encoders as bitmaps, which is a bit limiting if one were to
introduce text-based subtitles.

My idea is therefore as follows:

1. Extend the "format" member of the AVSubtitle struct to include a text
format and eventually specific types of graphic formats
2. Add a member to the AVSubtitle struct to contain the actual subtitle
text (utf8)
3. Create a general purpose function to convert text into a bitmap
4. Add an interface for subtitle codecs to publish what types of
subtitle inputs and outputs they can (or must) have
5. Add some logic in ffmpeg to determine how to convert the subtitle
types between different codecs

My idea, basically, is that if one was to transcode a text-based
subtitle into another text-based subtitle, ffmpeg would recognize this
and pass the text between the codecs.

If the conversion was done from a text-based to a bitmap-based, ffmpeg
would use its "general purpose" bitmap generator to pass bitmaps. (Maybe
this could be enhanced to support arguments for fonts, size, color,
placement, etc.)

If new subtitle graphic formats are added, maybe ffmpeg could convert
between those as well.

If this is considered a good idea, the subtitle support would be much
more flexible and text-based subtitle formats would be much easier to

Apart from this fundamental change - which requires more skill than I
possess - it would be good for the subtitle codecs to be aware of the
video stream's width/height in case the subtitle format (as XSUB) needs
to do absolute placement itself.

Also, I've noticed that some of the subtitle support is incomplete. For
VOBSUB, .idx-files containing the timestamps are not supported and
the .ifo files for subtitle palette on the DVDs aren't used either.

I hope that the subtitle support can undergo some changes that will make
it easier to expand!

Thanks for great work,

More information about the ffmpeg-devel mailing list