• Published on | Feb 04, 2018 | by Chris Osborn

Chapters and Subtitles

My Plex server continues to fill up, mostly with various TV series and cartoons. I generally prefer to get my content from DVD or Blu-Ray disks because most of the time they include chapter markers. Chapter markers are fairly important to me, at least for TV series. Why? Because when you're watching a TV series it gets old having to watch the opening titles every single time, and trying to skip over them can be tricky when they aren't a nice even multiple of 30 or 60 seconds. Another popular thing from the seventies and eighties was also to put a preview of what's going to happen in the upcoming episode at the very beginning to try to draw in channel surfers who hadn't decided what they were going to watch that evening. I have no desire to watch those previews since I already know I'm going to watch the episode.

Plex will allow you to jump around between chapter markers by using the up-arrow. Unfortunately it doesn't do anything to indicate to the viewer that chapter markers are available. I've started getting into the habit of pushing up when the opening titles start. Of course when there aren't any chapter markers you're suddenly thrown ahead 10 minutes, and fumbling to get back to where you were often causes Plex to freak out and get stuck trying to tell the server what part of the video to send it.

Another TV series I recently purchased the Blu-Ray for is Space: 1999. It included chapter markers but almost none of the episodes actually put a chapter marker right after the opening credits (with a bizarre embedded "This Episode" preview).

In order to deal with missing chapter markers I added a new script to the viddin collection called guess-chapters. I was originally thinking I would give it patterns to use to set chapter markers but it turned out to not really be necessary. The way it works is it scans a video file looking for black scenes combined with silence. After the scan is done it prints out a list of offsets that are possibly chapter markers. It can also create chapter markers on the video file by passing it a list of offsets which it will then match as closely as possible to the guessed offsets.

After I get the list of possible chapter positions I load the video in VLC and use the Jump to Time command to go to each offset one at a time and check whether or not it seems like an appropriate chapter marker. It sounds slightly tedious but in practice it only takes 10 or 15 minutes to run through and add complete chapter markers to an entire season. There is usually a pattern and once you do a couple of them you can see the pattern and it only takes a minute to verify and update the file.

For videos that already have chapter markers there's also an option to add more chapter markers to the existing ones. This made it easy to add the missing markers to Space: 1999.

Reading Along With the Story

Another update I've made is better subtitle support in rip-video. I rewrote the script in Python and now in addition to scanning and adding a forced subtitle track if there is one, it will also add the full subtitles into a separate track. Forced subtitles are the ones that only show up when people are speaking in a different language, such as when aliens are speaking or a foreign language is being spoken. This works with both files created by makemkv from Blu-Ray disks and DVD subtitles ripped directly by HandBrake.

Getting both the forced and regular subtitles requires a few passes. The first pass is done by HandBrakeCLI in scan mode which will automatically pick out any subtitles marked forced and add that as a track to the mkv file. To get the complete subtitle track from a DVD requires running another rip with HandBrakeCLI but instead of scanning it is configured to pull all subtitles. I tried using mencoder to pull the subtitles but it ended up messing up the timestamps of all the text and caused subtitles to be displayed later and later as the video progressed.

In order to make the subtitle rip go as fast as possible the width of the output video is set to 1 pixel wide. After that mkvmerge is used to identify all the subtitle tracks and the longest one that matches is then merged into the destination mkv.

Getting subtitles from Blu-Ray is a similar process, although first makemkv is used to pull the titles from disk. Again HandBrakeCLI first rips the video and creates a forced subtitle track. But instead of having to run HandBrakeCLI a second time to get the complete subtitles, the original file created by makemkv is analyzed to find the longest subtitle track and merged into the destination mkv.

You can get my video tools on github here.

Join The Discussion