Article List

How to Rip Blu-Rays


Today, instead of rambling, I’m going to write a guide. That’s right, we’re going to learn! What will we be learning about?

...You’ve read the title, you should know already.

The text in the purple boxes is not necessary to know to follow the guide, but the information there is nonetheless relevant and interesting, so unless you're in a big hurry, it won't hurt to read through that, as well.


The Basics


So, you’ve just bought a shiny new Blu-Ray, and you’ve decided that it’d be really cool to make a digital copy of it to store on your computer. Perhaps you just want to back-up your physical media, perhaps you want all your movies, digital and physical, in the same, easily-accessible place. Either way, you can’t just copy the file off the disc and paste it into a folder, it usually won’t work. This is where MakeMKV comes to the rescue. But (especially in Europe) the discs often come with excess audio and subtitle tracks that you may not really care for, but that still take up space, so it’d be nice to get rid of them. Or maybe the video’s interlaced. Or maybe you want to really efficiently save space, and thus encode it with a different codec or bitrate. Whatever the case may be, ffmpeg will be our tool of choice. As we’ll soon find out, subtitles on Blu-Ray discs can be tricky to extract or edit. For that, and any other subtitle-related thing, we’re going to use SubtitleTools. Lastly, for any issues with sound that we may experience, there’s Audacity. MakeMKV is unfortunately not FOSS, but it has a 30 day trial period, which is more than enough to rip a decent-sized Blu-Ray collection. Also, the trial refers only to Blu-Rays; DVDs can be ripped as long as you want. Ffmpeg, Subtitle Edit and Audacity are all Free and Open-Source. In regards to operating systems, MakeMKV, ffmpeg and Audacity have native Linux and Windows versions. SubtitleTools is Windows-only, but you can run it on Linux without any problems using Wine. You’ll also need a Blu-Ray optical drive, obviously.

Once you have the disc in the drive, open MakeMKV and click on the drive icon. It’ll begin parsing the contents of the drive. If you haven’t yet activated the software, once you press the button it’ll ask if you want to activate the trial period. Simply say yes and let it do its thing.

Blu-Ray Encryption

If you tried to play your shiny new Blu-Ray disc in a regular media player once you got it, you may have also experienced problems, like me, where the media player simply wouldn’t play it, even though it would play DVDs, CDs and other media discs just fine. The reason for that is encryption. Blu-Ray discs come encrypted, usually with what’s called AACS (Advanced Access Content System). To decrypt it, you need a decryption key. There are ways of obtaining the key from the disc, but from what I understand it’s not exactly easy. The intended way of playing such discs is to use either proprietary software like Cyberlink PowerDVD or physical Blu-Ray players that come with these keys already provided, licensed by disc manufacturers. Naturally, many people have collectively said “Fuck you” and circumvented the encryption by getting and sharing the keys among themselves. There are ways to add these keys to VLC, but I personally prefer to get rid of the garbage altogether and have a normal video file to watch at my leisure. If you want an interesting story about people rebelling against AACS, read up on the Free Speech Flag designed by John Marcotte.

Once the disc has been read, you’ll be presented with a few titles to choose from. The biggest one is likely to be the movie proper, which is what you want. The others can be things like trailers and other extra material. Once you’ve selected what you want to rip (you can select multiple files, of course, it’ll just make the ripping take longer), hit the “Save selected files” button on the side and the process will begin.

If you look at the screenshot, you’ll notice that there are two titles (pieces of media) with the size 30.2 GB. If you were to rip both, you’d see that they’re almost identical. The only difference is that the one that doesn’t have “X chapters” in the title does not include chapters (duh), and it has no subtitle tracks. So you should choose the version appropriate for you, whether you care about subtitles and/or chapters. Another note is that you may notice some things missing. If your disc has special features, for example, they may be absent from this menu. The reason for that is that, by default, MakeMKV ignores any titles shorter than 2 minutes. This has the effect of ignoring the 10-20 second background videos for the selection menu or the pre-movie disclaimers, which you most likely don’t care for, but it can sometimes skip things you do want to rip, as well. To change that, go to View → Preferences → Video and change the Minimum title length (seconds) to something more appropriate. Then simply close the application and start it again, so that you get to parse the content again.

Don't set it too low, or else you'll get a lot of junk.


After the program finished doing its thing, you can view the results in the output folder. By default, it’ll be a new folder with the movie’s name, in your home directory. If all you’re concerned with is a playable file, then you’re pretty much set! But that’s like ripping a CD and not bothering to properly tag the files with titles, covers, composers, etc., so if you want it to be nice and neat like that, you’ll want to keep reading the guide.


The Slightly-Less-Basic Basics


In the examples above, I was ripping the movie called Spirited Away. The end file has the following attributes:
- 1 video track
- 6 audio tracks (6.1 Japanese, Stereo Japanese, 5.1 Finnish, Stereo Finnish, 5.1 Swedish, 5.1 Danish)
- 3 subtitle tracks (Finnish, Swedish, Danish)

I don’t care for the Finnish or Danish language alternatives, yet they take up 4.9 GB of space, which I’d rather be saving. This isn’t the only movie I have, and several of them having these useless tracks can add up rather quickly. At the same time, the file is missing any English language alternatives, which I do want to have. To get the undesirables out and the desirables in, we’re going to use ffmpeg. It is a command-line tool, meaning it has no graphical interface, but it is nonetheless easy to use. If you’ve never used a terminal before, read the primer below.

On Using the Terminal

There’s maybe a dozen people in the entire world who use Linux but who don’t know how to use the terminal, so this bit will focus on Windows. There are two ways of accessing it, either using CMD or using Powershell. There are some differences behind them, but they are not relevant to what we’ll be doing. Start by pressing the Windows icon in the bottom-left corner, and typing in either cmd or powershell, then clicking the program of choice in the search results. By default, the program will start in your home directory, so we’ll need to navigate to the folder where we’ll be working from. To list out what’s in your current directory, use dir, and to move to a different directory, use cd. If my folder structure looks like this: C://Users/Cirno/Videos/SpiritedAway/ffmpeg, with ffmpeg being the folder I’ll be working on, but the program currently being in C://Users/Cirno/, I’ll need to use the command cd Videos/SpiritedAway/ffmpeg to get to where I want to be. In the case that you need to access a folder that’s above the folder you’re currently in, use cd ../. If the directory or file you’re trying to access is more than one word (for example “Program Files”), put the name in quotation marks, like this: cd ”Program Files”. To reference files outside of the folder you’re in works the same way. So if I’m in C://Users/Cirno/Videos/SpiritedAway/ffmpeg and I want to use ffmpeg with a file that’s in C://Users/Cirno/Videos, the following command will do the trick: ffmpeg -i ../../file.mkv. However, that means more writing and keeping track of directories, so I recommend keeping the files you’re working with in the same folder as ffmpeg. Now, if you try following this guide, you might get errors suggesting that there is no ffmpeg on your system. That’s because you haven’t really installed the program, you just downloaded the standalone executable file. When you’re in the folder where the ffmpeg.exe and ffprobe.exe files are, instead of starting your commands with ffmpeg, begin with ./ffmpeg. Everything should work fine, then. If there’s anything else that you have trouble with that I forgot to mention here, consult your internet search engine of choice. There’s plenty of help out there.

Upon downloading/installing ffmpeg, you’ll get three programs to use. The first is ffmpeg, which we’ll be using to do most of the work. The second is ffprobe, which we’ll use to inspect the files, check what tracks they have, what format they’re in, and such. The third is ffplay, which is a simple tool to play files. I won’t bother with that one, since I can just use VLC for that.

So, the file I got out of MakeMKV is called Spirited Away_t00.mkv. That’s a bit of a mouthful, so to make my work easier, I’m going to rename it to away.mkv. To begin with, let’s use ffprobe to check exactly what is in the file.

ffprobe away.mkv

Here is the entire output of the above command. It is quite lengthy, so I've put the stuff that we actually care about in bold letters.

We’ll see all the tracks present in the file, numbered from 0:0 down to 0:11. The first one is the video track, which we definitely want to keep. So I’m going to extract it using the following command:

ffmpeg -i away.mkv -map 0:0 -c:v copy video.mkv

-i away.mkv specifies that I am inputting a file called away.mkv. You can input more than one file, and you’ll need to type -i before the name of each of them. -map 0:0 is saying that I want to take the first track and only the first track of the file. If I hadn’t used that, the new file would include the video track, the first audio track and the first subtitle track, which we don’t want. -c:v copy is saying that I want to copy the video from the old file to the new file exactly as it is. -c:v stands for Video Codec, and giving it the copy argument tells it to keep all the parameters as is and to not re-encode it. If we hadn’t done that, ffmpeg would re-encode the video in a codec, bitrate, etc. that it considers suitable, which would stretch out this operation immensely and lead to loss of quality (and a smaller file size). Re-encoding is a processor-intensive task, so the speed varies from computer to computer. On my setup (Intel Core i5 4460), re-encoding a 2 hour movie like Spirited Away would likely take in excess of 4-6 hours, depending on the parameters set. Meanwhile, copying the file as is only takes around a minute. Lastly, video.mkv is the output file. The format has to match what’s being put into it. I would get an error if I tried to name the output video.mp3, because an MP3 file cannot store video. Throughout the process, I recommend using short, simple and descriptive names for the files that you create, to make working on them easier.

Now, let’s grab the audio files. Here are the commands I will be using:

ffmpeg -i away.mkv -map 0:1 -c:a copy audio_jpn6.1.dts
ffmpeg -i away.mkv -map 0:3 -c:a copy audio_jpnstr.wav
ffmpeg -i away.mkv -map 0:6 -c:a copy audio_swe5.1.ac3

Notice that now we’re saying -c:a copy instead of -c:v copy, since what we’re working with are audio files, not video files. The new files are named in a way that lets me know what exactly they are, without being hard to type in. Notice the different file extensions. The first track, being a Japanese 6.1 audio track, uses the DTS-HD MA format. It stands for “Digital Theater Systems HD Master Audio” and is used in most surround sound audio tracks that I’ve seen. It’s a lossless, compressed format of audio storage. The proper extension for that is .dts. The second track is pcm_s24le. The PCM part stands for Pulse-Code Modulation, which is a form of audio encoding. The rest defines attributes of the track (for example that it is 24-bit). It is a lossless and compression-less audio format, with the preferred extension being .wav. The last track uses ac3, which refers to the Doly AC-3 audio format, which is both lossy and compressed. The right extension for that is .ac3.

Now, let’s move on to the subtitles. If you’ve worked with subtitles before, for example on YouTube, you might be used to formats like SRT and ASS. Blu-Rays, however, are a little different. If you scroll over to the subtitle tracks, you’ll see that they’re encoded in hdmv_text_subtitle. This format decided to be special and, instead of storing text as, well, text, it stores the text as images that are displayed on the screen at the correct time. This has some advantages, but it has one debilitating disadvantage – most media players can’t deal with it. If I try to play the MKV file in VLC, even though the subtitles are turned on, they’re just not showing up. To fix this, we need to turn the images into regular text, and the only (reasonable) way to do that is with OCR, or Optical Character Recognition. In other words, we’ll need a program that can look at the images and figure out what the text on the images actually is.

This is where Subtitle Edit comes into play. Open the program, drag the MKV file onto it and drop. A dialogue box will appear, asking you which subtitles you want to work with, after which it’ll start parsing them. There is a small chance that the subtitles will somehow already be figured out, skipping the OCR itself. I don’t know what it depends on, but I know that my copy of Spirited Away is one of those cases, so for the next few screenshots I’ll have to use a different movie.

OCR window of Subtitle Edit. Have all your settings just like on the screenshot.


Once the program finished parsing the file, a new window will appear. At the top, make sure to select Tesseract 4 as the OCR method. I’ve never used nOCR, and had a very bad experience with Binary image compare. Once that’s set, select the language of the subtitles – in this case, it’s English. If the language you want is missing, click the three dots on the side, find the language you want and download the pack for it. This setting determines what the program will look for in the image to figure out the text. If you set it incorrectly, for example select English while the subtitles are in Arabic, you’ll end up with a mess that makes no sense. Next, select the appropriate dictionary in the drop-down menu to the left. After the program figures out the text, it checks whether or not it makes sense by comparing the result to a list of words. If the word appears there, it will just keep going, but if the word is not in the dictionary, it’ll ask you for help.

In this example, it doesn’t understand the word “Aishiteta” because it’s not an English word, but rather a rōmaji version of a Japanese word. In this window, I can see the original image and the text that the OCR came up with, as well as a text box for the word that wasn’t recognized. In this case, the word was transcribed correctly, so I should press “Add to user dictionary”. This will extend the dictionary it checks against, so if the word ever comes up again, it’ll know that it’s correct.

What if the word is not actually correct? Then I simply write the correct form, and then press “Change all”. This means that, if the same mistake appeared anywhere else, it’ll be changed into what you’ve typed in. If there’s a mistake where it treats one word as multiple words, for example it transcribes “would’ve” into “would ve”, you’ll need to press “Edit the whole text” and make appropriate changes. In general, you should pay attention to the entire transcribed text, especially if the original image is in italics. Italics likes to screw things up, so the OCR might not set something as italics even though it should be, or vice versa.

Starting OCR kills my computer - what gives?

An issue I’ve encountered while using Subtitle Edit is that, if I set the language for Tesseract to English and start OCR, it calls on dozens of tesseract processes which never actually do any OCR but instead slow my PC down to a crawl. I am not sure what the cause is, nor if it’s specific to my setup or a general issue, but in case you experience it as well, here’s how I solved it – I simply set the language to something else. As I said previously, this setting determines how the program figures out what’s being written, so setting it incorrectly can have weird results. However, setting it to something fairly similar to English (like another Germanic language, for example Swedish or German) and keeping the dictionary at English led to no issues on my end, so consider trying that.

On the topic of Subtitle Edit not working as it should, another issue I’ve had when using on Linux was downloading languages. Perhaps it’s due to my setup of Wine, but trying to download a new language from the list hangs at 100% and never actually installs anything. The way I got around that issue was by instead clicking on Open “Dictionaries” Folder, then in my web browser going to https://github.com/tesseract-ocr/tessdata, downloading the relevant .traineddata file and manually putting it in the folder.

Once that’s done, press OK. At this point we’re pretty much done, but you are welcome to check if the subtitles work correctly. Double-clicking on any line will take you to that part of the file where it’s displayed, letting you check if it’s synchronised with the audio. If you’ve got multiple audio tracks, you can switch between them in Video → Choose audio track. If all’s good, you can select the right format and encoding, and go to File → Save to save the results. As far as formats go, I recommend using either SubRip Text (SRT) or Advanced SubStation Alpha (ASS). ASS is more versatile, allowing for things like custom fonts and colors, while SRT is more basic, use whichever you’d like. As for encoding, it only matters if you’ve got some special characters or languages. Otherwise, I’d suggest just going with UTF-8 with BOM.

A word of warning about OCR

Keep in mind that OCR looks only at what’s written, it does not preserve things like colour, font or position. Things like that you’ll have to fix afterwards, yourself. Here’s an example of problems that might occur. The first two images show the subtitles as they appear when playing the video with original, Blu-Ray subtitles, while the third and fourth image show the same subtitles after they've gone through OCR but before I got around to fixing them.

Here's how the subtitles should look, when played from the disc...

...and here's how they look after OCR and without corrections.

The exact fixes depend on what exactly is broken, so I won’t go over every single option individually, but just know that you can right-click on any offending subtitle line and get the fixes you need. Be sure to check with the video playback that it looks as it should.

If you’ve got other subtitles that you want to add into the file (good sources are OpenSubtitles and SubScene), the important thing is to see if they’re synchronised. You can do that by opening the original MKV file in VLC Media Player, right-clicking, going to Subtitles → Add Subtitle File… and selecting the right file. Then, find a scene with some dialogue, and go to Tools → Track Synchronisation.


In the new window, use the appropriate option to adjust the delay of the subtitles, until you see that they are lined up with the sound. Remember the number. Open the subtitles in Subtitle Edit, go to Synchronisation → Adjust all times (show earlier/later)… and put in the number you got before. Click the right option, depending on whether they should be moved back or forth, close the dialogue box and save the subtitles.

Now we have everything we need, so it’s time to combine them into the finished file. To do that, We’re going to use the following command:

ffmpeg -i video.mkv -i audio_jpnstr.wav -i audio_jpn6.1.dts -i audio_swe5.1.ac3 -i subs_eng.ass -i subs_swe.ass -map 0 -map 1 -map 2 -map 3 -map 4 -map 5 -c:a copy -c:v copy output.mkv

First, we specify all the input files. The order in which we type them in defines what index each track will get. This is especially important when defining the first audio track, as that's what will play by default when you open the file. Since I will most likely watch the movie on my computer, using my headphones, I want stereo audio rather than 6.1 audio. So it makes sense to define the stereo track as the first one, so that I don't have to manually switch to it when I start the movie. Then, we have to make sure that they’re all included in the final file. -map 0 -map 1 -map 2 -map 3 -map 4 -map 5 is how we do that. If we didn’t do that, the only things included in the output file would be video.mkv, audio_jpnstr.wav and subs_eng.ass. Once again, we say -c:a copy -c:v copy to avoid re-encoding, and since we’re working with both audio and video files, we have to write both -c:a and -c:v. Then the file name, which in this case is output.mkv. And we’re done! We now have a file with the following components:
- 1 video track
- 3 audio tracks (Japanese Stereo, Japanese 6.1, Swedish 5.1)
- 2 subtitle tracks (English, Swedish)

That’s precisely what we wanted… but there’s one thing missing. Metadata. If I want to change the audio track, I don’t choose between Japanese Stereo, Japanese 6.1 and Swedish 5.1. I choose between Track 1, Track 2 and Track 3. Same goes for the subtitles.

This is not good, since I have to either remember which is which or test ahead of time to see what I should use. So let’s delete that file, and use a different command, which will also give us metadata.

ffmpeg -i video.mkv -i audio_jpnstr.wav -i audio_jpn6.1.dts -i audio_swe5.1.ac3 -i subs_eng.ass -i subs_swe.ass -map 0 -map 1 -map 2 -map 3 -map 4 -map 5 -c:a copy -c:v copy -metadata title=”Spirited Away | Sen to Chihiro no Kamikakushi” -metadata:s:a:0 language=jpn -metadata:s:a:0 title=”Stereo” -metadata:s:a:1 language=jpn -metadata:s:a:1 title=”Surround 6.1” -metadata:s:a:2 language=swe -metadata:s:a:2 title=”Surround 5.1” -metadata:s:s:0 language=eng -metadata:s:s:1 language=swe output.mkv

The first new thing, -metadata title=”Spirited Away | Sen to Chihiro no Kamikakushi”, specifies the title for the entire file. This is the title you see when you open the file in VLC. If that title is not set, it instead displays the filename. Next, we specify the language and title of each audio track. We specify the track with s:a:0, where 0 is the index. For example, audio_jpn6.1.dts is the second audio track we specified so we will refer to it using s:a:1. Keep in mind that, in computers, the indexes usually start with the number 0. That's why the 1st track has the index 0, the 2nd track is 1, the 3rd track is 2, and so on. We set the language using a 3-letter language code (jpn for Japanese, eng for English, swe for Swedish, dan for Danish, fin for Finnish, pol for Polish, and so on), and the title is useful to distinguish between different tracks of the same language, or to inform what kind of sound it provides. Subtitles are tagged in much the same way, just with s:s:0 instead of s:a:0 (a for audio, s for subtitle). In this case, I didn’t bother with a title tag, because the language alone is enough to tell me what is what, but in some cases it can be useful. A lot of anime might come with English subtitles for English audio, and English subtitles for Japanese audio, so clarifying that in the title is useful. The end result looks like this:

That’s about it, when it comes to general Blu-Ray ripping. There will be minor differences depending on what exactly you want to do, but if you’re going to use the tools that I used, I think there’s a good chance most (if not all) of the steps above will apply to you. It’s a reasonably effective way of ripping media – from inserting the disc into the drive to having a finished file takes maybe 20 minutes, with half of that time spent waiting for the initial rip from Blu-Ray to your computer drive. Let’s discuss, then, some of the more obscure and odd problems one might encounter when trying to digitize their movie collection.


Problem #1 - Misaligned audio


We don’t have to look far, actually. The very file we’ve just created is broken, in a way. If I set the audio track to Japanese Surround 6.1, I’ll find that the audio is not synchronised to the video. This isn’t because of anything specific that we’ve done. You can get the file from the disc, everything will work fine. You can extract the video track exactly as is, extract the audio track exactly as is, combine them into a new file exactly as they are, and the problem will already be present. To my knowledge, that is a problem related to the way DTS encoding works. I don’t know the technical details, but I’ve seen this problem occur every so often with DTS audio tracks, and maybe once or twice with AC-3, but never with PCM. There are ways of fixing that kind of problem using ffmpeg, for example with the command -itsoffset, or by just remembering to apply the delay in VLC before playing the file, but I find the second option to be bothersome, while the first option was a pain and I almost never got it to work. Instead, what we’re going to do is use Audacity to alter the audio so that it’s in sync.

Audacity can open DTS audio, but it cannot save DTS audio. Ffmpeg has a way to export into that format, but the codec is experimental, and for messing with audio I’ve personally found Audacity’s graphical interface to justify using it, instead. To solve the format dilemma, we’re going to export our audio in the FLAC format. Just like DTS, it is lossless and compressed, and whatever loss of quality the conversion may introduce will almost certainly be imperceptible.

Let’s say that the audio comes 1 second before or after the video. To speed up the audio (if the audio comes after the video), simply select the first 1 second (you can use CTRL+1 and CTRL+3 or hold CTRL and use your mouse wheel to zoom in and out) and delete it. Make sure that you’re actually deleting it, not just making it silent. If you want to delay the audio, on the other hand (if the audio comes before the video), make sure that the selection marker is at the beginning of the track (Start and End of Selection at the bottom should all be zeroed out), then go to Generate → Silence. In either case, what you have to be absolutely sure of is that you’re applying the change to all tracks. The blue/white rectangles in front of each waveform show whether or not the track is selected. For them all to be selected, they all have to be blue. In the case where you’re adding a delay, that just means not touching anything after importing the track in and going straight for the silence generation. In the case of removing audio, you have two options. You can either select your one second on any given track, click on every white rectangle while holding CTRL and then delete the audio, or you can press CTRL + A, then at the bottom where it specifies the selection start and end, set it to whatever your delay is, and hit Delete.

Now that you’ve changed the audio, all that’s left is to export it. Before we do that, though, we have to make sure that we can actually export it correctly. You see, by default, Audacity mixes everything down into Stereo. Even if you input a 5.1 or 6.1 audio track, once you export it, it’ll be Stereo. To avoid that, you have to go to Edit → Preferences → Import/Export and enable Use Advanced Mixing Options. Hit OK, then go to File → Export → Export Audio. In the bottom drop-down menu select FLAC Files, make sure that the Bit Depth is set to what the original was, and export.

The end result will be a FLAC file with similar size and near-identical quality to the original audio, but with none of the synchronisation issues. You can go ahead and use the commands discussed previously to use it when creating a new MKV file, and enjoy sound appearing when it should.

But wait! I DO want to compress!

All of the above applies, of course, if what you’re looking for is a backup of the disc as close to the original quality as possible. This is far beyond what you may be used to, and even beyond what you may consider reasonable. In general, a decent way to estimate quality is to look at bitrate. From what I’ve seen, a typical Blu-Ray movie at 1080p will have video with a bitrate of around 18-20 Mbps. A typical DTS-HD MA audio track will have a bitrate of around 4 Mbps, while a Stereo track encoded with PCM will sit around 1,5 Mbps. By comparison, a YouTube video at the same resolution will have a bitrate of 4 Mbps, while the audio will only be 0.1 Mbps (128 kb/s). A high quality music stream from Spotify will be at 0.3 Mbps (320 kb/s). Bitrate, like many things, tends to follow Weber’s law. A 256 kb/s audio stream will sound a fair bit better than a 128 kb/s one, but a 4 Mbps stream will sound essentially identical to a 2 Mbps stream, unless you’ve got amazing ears and equally amazing audio equipment. While something like an action movie might sometimes make use of the 20 Mbps of video, you could just as well halve it and get pretty much the same watching experience at half the file size. That goes even further with things like anime which, due to its style, looks pretty much perfect at 5-6 Mbps.

If space is of no concern, feel free to keep the files as they are. If space is a concern though, or if bandwidth comes into play (if you’re going to stream the movies or store them in a cloud, for example), reducing the bitrate might be a good idea. Recommended amounts vary depending on what exactly the file is, but as a general rule of thumb, you can cut both video and audio bitrate by half and still get something at or above the quality of Netflix and other streaming services, while saving many gigabytes.

Sometimes, the synchronisation issues can be more insidious. In my copy of Laputa: Castle in the Sky, the Swedish audio track has a weird quirk where it starts off synchronised, but ends up being desynchronised by the end. Again, I suspect it’s an issue of the audio playing back at a different framerate than the video, but regardless of the cause it’s still something we can fix with Audacity.

We begin by playing the movie at the start. The track is synchronised, the characters speak exactly when they’re supposed to. Then, we move to the end, looking for any dialogue. We use VLC’s synchronisation options to measure the offset. In my case, it was 0.5s. The problem doesn’t appear at any specific point, but rather grows throughout the entire 2 hour runtime, so what we need to do is to adjust the audio as if we were squeezing it, to make it 0,5s slower by adjusting the length of the entire clip, rather than just cutting off any specific part. If you’ve worked with audio before, you’ll know that squeezing audio like that will make the pitch higher (unless you’re playing with Fourier transforms), but since we’re not going to be changing it by more than a few seconds (which is maybe 0.03% of the entire length), the pitch change should not be perceptible. So, how do we do it? Start off, as you can guess, by importing the audio track into Audacity. Then, we select everything with CTRL + A, go to Effects → Change Speed, and set the New Length to be 0.5s shorter than the old speed. Click OK, wait for it to finish, export the audio in the appropriate format, and we’re done!


Problem #2 - Subtitles turned to junk


An issue that you may come across that’s not necessarily related to Blu-Rays are broken subtitles. Specifically, when downloading subtitles from the internet, you may sometimes find that any non-standard characters (for example letters not encountered in English) will be a mess. In this example, I grabbed some Korean subtitles for Grave of the Fireflies off the internet, and as you can see, what I got isn’t exactly Korean.

The fix for this is very simple, though. Simply open the file in Subtitle Edit. Looking in the top-right corner, we see that these subtitles are encoded in Windows-949, also known as UHC Korean. When we load the file in a media player, however, it uses your system’s default encoding, unless specified otherwise. This creates the problem where the encoded text calls for a character that, in its encoding might be valid and normal, but in our system’s encoding turns out to be a bunch of nonsense. The solution is to simply change the encoding in Subtitle Edit to something more common, like UTF-8 with BOM, and save it. Now it is going to play correctly.

You probably won't see these weird rectangles like in the screenshot;
they're caused by a lack of fonts on my Wine install.



Problem #3 - Interlaced video


The last issue I’m going to talk about is interlaced video. If you’re not familiar with the term, then here’s a little history lesson.

In “ye olden days”, also known as “before ca. 2005”, the vast majority of screens, be it TVs or monitors, were not flat-screen LCDs, but bulky CRTs. The way they worked was that there would be an electron beam, firing at the screen from inside, going left to right, line by line, directed by magnets. However, there were various problems with how long an image would be displayed, so to avoid ghosting, flickering and the like, what we got was interlaced video stream. Instead of going from line 1 to line 2 to line 3 and so on, it’d first do all the odd-numbered lines, then do all the even-numbered lines. The refresh rate was fast enough that most people wouldn’t really notice it, and so all was good.

Fast forward to today, and almost nobody uses CRTs. Instead, modern displays use progressive video, where the lines (or, rather, pixels) are generated in order, 1, 2, 3, 4, and so on. The problem appears when you try to play interlaced video on a progressive screen. They don’t exactly understand how it’s supposed to work, so they draw the images as if they were progressive. The result is that, particularly in action-focused scenes with lots of movement, your image ends up being stripey.

There are two ways to deinterlace video. First is to do it on the go. VLC will automatically detect interlaced video and convert it as it plays. In the case that it isn’t detected correctly, you can manually turn it on by going to Video → Deinterlace. The second way is to do it once and for all, using ffmpeg. Below is how that can be done.

I have my copy of Cowboy Bebop, a TV show from the late 90s, which is interlaced. I can verify that by using ffprobe on the file and checking the attributes. This line tells us everything:

Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc

If the video was progressive, we’d see yuv420p(tv, bt709, progressive). Instead, however, we see top first which specifies which lines come first – that only makes sense if the video is interlaced. There’s actually another issue with the video that I’ll be fixing, that being the resolution. As you can see, the video is at 1920x1080, Full HD resolution at widescreen aspect ratio. However, Cowboy Bebop is a 4:3 show, so it should actually be 1440x1080. The extra 480 pixels are black bars on both sides of the video, which I personally want gone. So I will have to crop the video, as well.

To deinterlace video, you have two options - either use the -deinterlace argument, or specify a deinterlacing algorithm as a video filter. Regardless of which one you choose, I recommend specifying that only the video track be put into the output file, using -map 0:0. This saves time on encoding and avoids issues like cloned audio tracks later on. The first option would look like this:

ffmpeg -i title_t03.mkv -map 0:0 -deinterlace output.mkv

The issue with this one is that I frankly have no idea how it actually deinterlaces things. It does its job, alright, but I don’t know how it does that. Instead of using that and hoping that everything goes well, we can specify an algorithm for it to use. There are a number of algorithms available, including bwdif, yadif, w3fdif and nnedi. To pick the best one for you, I recommend just testing them out (you can convert only the first minute of the video using -t 00:01:00.000, to save time) and comparing the results. For a very granular comparison, you can specify your output file as %d.png, which will create images of every individual frame. I heard that nnedi is extremely good for live-action footage, but that it’s very slow. For my use case, I compared them and found bwdif to give the best results, so that’s what I will use in the coming commands. To specify a deinterlacing filter, we can use this command:

ffmpeg -i title_t03.mkv -map 0:0 -vf bwdif output.mkv

Now, a side-effect of using bwdif is that it doubles the framerate. This doesn’t have any meaningful impact on the video, but if it’s something you wish to avoid, you can specify the framerate to be the same as the original. In my case, the input file is at 30 FPS, while the output with bwdif is at 60 FPS, so I just have to use the fps command to force it to use 30 FPS. Both fps and bwdif are video filters, so to use both of them we write one after the other, separated by a comma, like so:

ffmpeg -i title_t03.mkv -map 0:0 -vf bwdif,fps=30 output.mkv

If I use this command, I will see that the file has grown significantly smaller than it was before. The reason for that is the lack of -c:v copy in the command. We cannot use it since we are actually changing the video with our filters, but without it we’re just leaving ffmpeg to figure things out, and in my case, the new bitrate is around 2000 kbps, whereas the old one usually sat between 17000-19000 kbps. In other words, we’re losing quality. The solution is to specify the bitrate outselves. For this, we’ll use the -b:v option (bitrate:video). So our command grows to this:

ffmpeg -i title_t03.mkv -map 0:0 -vf bwdif,fps=30 -b:v 18000k output.mkv

Now, since we’re talking about quality, let’s talk about codecs. A codec is, put simply, the way in which the image data is compressed and stored. The two most popular codes at the moment are AVC (also known as H264) and HEVC (also known as H265). If the goal is to play the movies on a computer or stream them, I recommend using HEVC. At the same video quality, it reduces file size by as much as 50%, and at the same bitrate, it offers superior video quality. If, however, your goal is watching the files on many different devices (especially phones), or putting it on the internet, I would suggest sticking with AVC, as it’s the more common one and more widely adopted. To specify AVC as the codec in ffmpeg, use -v:c h264, and if you want HEVC, use -v:c libx265. I am going to be converting my file to HEVC, so the command grows further into this:

ffmpeg -i title_t03.mkv -map 0:0 -vf bwdif,fps=30 -b:v 18000k -c:v libx265 output.mkv

The last thing left is to get rid of the black bars on the sides. This is fairly simple, as I just need to crop the output. As with most positional stuff in computers, we treat the top-left corner as position 0,0 and go from there. The black bars are 240 pixels wide, meaning that the part that I want to keep starts at 240,0. It is 1440 pixels wide and 1080 pixels tall. The video filter we’ll use is “crop”, and putting all the right values into it will look like this: “-vf crop=1440:1080:240:0”, which can be read as “crop an area the size of 1440x1080, starting at position 240,0”. Putting that into our command, we get:

ffmpeg -i title_t03.mkv -map 0:0 -vf bwdif,fps=30,crop=1440:1080:240:0 -b:v 18000k -c:v libx265 output.mkv

And that’s pretty much everything that we wanted to do. Starting with an interlaced video encoded in AVC with black bars on the sides, we end up with a progressive video encoded in HEVC, with no black bars to speak of, and the quality is preserved. Adding metadata and combining the video and the other tracks will now continue exactly as before.


That's All, Folks!


Well, this was quite a long one, but that’s to be expected, since I tried to cover many topics. I hope you got something out of it, and that it’ll make digitizing your movie collection a simpler endeavour. Good luck ripping!


Back to the top