Converting MKV/BluRay Subtitles

Subtitles come in a myriad of formats, and not all of them work in every container format, and not all containers are as easy to work with. Converting Matroska (mkv) files to MP4s cause issues when the mkv has PGS (Blu-Ray) subtitles.

PGS subtitles can be embedded in Matroska video files, but not MP4s. But tagging and putting other information in Matroska files is a pain in the butt, and there aren’t many good tools for it. DVD Subtitles, however, can be put into MP4 files. Even though technically it isn’t part of the standard, most players recognize and play them fine.

PGS and DVD (VobSub) subtitles are both bitmap formats, and are trickier to convert than text based subtitles. There are two methods I have found that work well in converting from PGS to VobSub (versus using OCR to convert which is often messy, especially if it’s not pure text).

The first method is with BDSub2Sub. This is a <shudder> java based tool that does a very good job of converting and preserving as much information as possible. It has both a GUI and a CLI interface. It seems to do a slightly better job than the second method.

The second method is using ffmpeg. Finding details on the ffmpeg method has been a challenge. The documentation is sparse, but I’ve pieced enough together to make it work acceptably.

This one allows you to recontainer, and convert from mkv to MP4 at the same time. An example command:

ffmpeg -fix_sub_duration -i source.mkv -c:v copy -a:a copy -c:s dvdsub destination.mp4

The -fix_sub_duration option is critical. Without it, the subtitles never clear, so they just write one after the other on top of each other.

Other options available:

Subtitle options:
-s size             set frame size (WxH or abbreviation)
-sn                 disable subtitle
-scodec codec       force subtitle codec ('copy' to copy stream)
-stag fourcc/tag    force subtitle tag/fourcc
-fix_sub_duration   fix subtitles duration
-canvas_size size   set canvas size (WxH or abbreviation)
-spre preset        set the subtitle options to the indicated preset 

You will want to set the canvas size to the original source video size, regardless of what size you’ve rescaled the video to. i.e. if the source is a Blu-Ray at 1080p (1920×1080), and you encode the video to 720p (1280×720), you would set the canvas size (i.e. the size of the subtitles) to 1920×1080, and the player will scale it to the video playback size correctly.

ffmpeg doesn’t seem to bring any palette information across, or just defaults to gray. I need to do more rigorous testing when I can find some good samples of PGS subtitles that have fades, or multiple colors.

Leave a Comment