This Does Not Compute

Technology, gaming, music and things that just don't compute

Undoing Ordered Chapters, Part 2: Fixing Broken Subtitles

appicons

If you’ve read my previous post on this topic, undoing ordered chapters (properly known as “segment linking”) in MKV files is a bit of a pain. I just recently noticed a problem with one particular series that I was trying to fix, in that the subtitles would look like crap after being run through UnlinkMKV (and before any other processing was done, such as conversion to MP4 in HandBrake). The subtitles looked fine before the files were fixed; what was the deal?

It took me some tinkering but I managed to figure it all out. The steps and screen shots lie ahead for OS X users.

What’s Going On

There are three parts to an MKV file, at least when it comes to fansubbed anime: a video track (usually H.264); one or more audio tracks (either AAC or FLAC); and a subtitle track (in SSA or ASS format, which are very similar). The subtitle track, likewise, has three components to it: a list of timecodes as to when and where to place subtitles on screen; the subtitles themselves (character dialogue, sign text, etc.); and a stylesheet that defines the fonts and colors to use for the subtitles.

With all of the files I had run through UnlinkMKV, the subtitle track on the OP, episodes, and ED had the same stylesheet. I’m guessing this was done on the fansubbers’ part for the sake of simplicity; there’s no harm in including styles that aren’t referenced in that particular file/segment. Thus, the OP had not only the styles needed for the OP subtitles, but also the styles for the episode subtitles, and so on.

This one particular series, though, was a bit different. The OP had only its subtitles, as did the ED. But the episode files had the styles for all three. This works out OK because, as the video file signals to jump to the next segment, that segment’s full SSA/ASS subtitle file is loaded. In this series’ case, opening Episode 1 caused it to immediately jump to the OP, then play the episode, then play the ED.

The problem is in how UnlinkMKV has to handle its reorganization process. It works by scanning the episode file then taking note of any linked segments (e.g. the OP and ED files). It then breaks the episode file into pieces at those points where the linked files play, and assembles all of the pieces (including the OP and ED) into the correct order as one single file. It’s easy to stitch video and audio tracks together, but the subtitle track has to be rebuilt. What threw this series for a loop was that UnlinkMKV only keeps the subtitle styles from the first segment in the chain (in this case, the OP) and then assembles all of the subtitles in order. And since the OP only has references to just the styles it uses, once the main part of the episode starts playing, its subtitles revert to a plain, small font — the sign that the style is missing.

What needs to happen is to have all the files have the same stylesheet before running them through UnlinkMKV. Here’s how to do it.

Tools Needed

In addition to having the full UnlinkMKV software setup from the previous article, you’ll need two freeware/shareware tools:

  1. MKVtools — shareware. The program works just fine if you don’t register, but there are some nag screens until you do. The guy’s only asking like $5, so I say just buy it so homeboy can get a Big Mac.
  2. mkvtoolnix — sound familiar? This is the same freeware package that we installed through MacPorts in the previous article. This time, though, you want the precompiled version, which has a GUI.

Here We Go

Gonna try to keep this succinct:

  1. Open episode 1 of your series in MKVtools.
  2. Check the box next to the subtitle track.
  3. Click the Edit Tracks tab, select Extract Tracks, then click Go.01
  4. Repeat steps 1 through 3 for all OP and ED files that came with your episodes.
  5. Open the .ass or .ssa file for episode 1 in TextEdit or similar. The subtitles are going to be in the [V4+ Styles] section.02
  6. Also open the .ass or .ssa file for your first or only OP file. Note here how there are fewer styles than in episode 1.03
  7. Visually compare the styles between the two. Copy and paste any styles that don’t exist in the other. You ultimately want both stylesheets to look the same.
  8. Repeat the same process for any other OP or ED files. Ultimately, all of your files need to have identical stylesheets.
  9. Save your changes, then open the OP file in MKVtools again.
  10. Check the box next to the subtitle track, and take mental note of what’s in the Title field for it.
  11. Click the Edit Tracks tab, select Remove Tracks, then click Go.
  12. MKVtools will spit out a new file with the same name, but ending in .removed.mkv. Open this new file in MKVtools.
  13. Click the Add Track button and select your newly-edited subtitle file.
  14. Next to the subtitle track, enter the Title name from step 10.04
  15. Check the box next to the subtitle track.
  16. Click the Edit Tracks tab, select Add Tracks, then click Go.05
  17. MKVtools will spit out a new file again, with the name ending this time in .added.mkv.
  18. Repeat for any/all remaining OP and ED files. If you found that your episode did not contain styles that your OP/ED files did, then you’ll need to repeat the above extract/edit/remove/add process for the episode files too.
  19. Now we need to fix the segment ID on the new OP/ED files, or else the episode file won’t be able to find them. Open Mkvtoolnix, then go to File and choose Header Editor.
  20. Go to File, then Open, and choose your original OP file (not the new, edited one).
  21. Expand the Segment Information section.
  22. Select the entry for Segment Unique ID.06
  23. Note that the Original Value and Current Value strings match. Copy the string to the Clipboard.
  24. Go to File, then Open, and choose your edited OP file (remember, it ends with .added.mkv).
  25. Expand Segment Information and click on Segment Unique ID.
  26. Note that this Segment ID is different than before — MKVtools regenerated it when adding the new subtitle file back in.
  27. Paste in the original Segment ID to the Current Value field.07
  28. Go to File and choose Save.
  29. Repeat steps 20 through 28 for any remaining OP and ED files (as well as your episode files, if you had to change the subtitles for them too).
  30. Put all of the episode files, and the new OP and ED files, into their own separate folder, then test them in your normal MKV-compatible video player (I use VLC). The subtitles should look correct throughout the whole episode.
  31. If all looks well, run the files through UnlinkMKV as usual.
  32. Rock on.
Advertisements

Comments are closed.

%d bloggers like this: