When I rip my shiny discs to play on my iThings and my Apple TV, my workflow is simple: MakeMKV to transfer the film or TV show to the hard drive, then Handbrake to convert to MP4. It’s a quick and painless process, and I’m sure many others follow the same routine, as it lets you rip a bunch of discs quickly and then leave them encoding overnight (or nights). It is flexible enough to work well for both DVDs and Blurays… Unless or until you put a BBC bluray through the process, when bad things may happen (in my case Doctor Who Series 5 coming out with judders and glitches).
It turns out the reason for this is because we Brits with our 50hz electricity and our PAL videos are pretty much the only ones to use 1080i50 (i.e. HD interlaced at 50fps) and so it’s not well supported, and the encoder Handbrake uses (FFMPEG 1.x) can’t do it justice.
The solution – at least on the Mac – is a little bit fiddly and involves using a newer version of FFMPEG from the command line. The fact it’s easy to forget what you did between ripping BBC blurays is the reason for this post – to remind myself what I did!
The first thing to do – and you only need to do this once – is get the latest FFMPEG. I believe you can now do this just using Homebrew although when I got it (back in January) 2.x wasn’t a stable release so I used this tutorial to make sure I got the latest version. There was no point in getting anything earlier than 2.0 because, just like Handbrake, it wouldn’t be able to encode the streams from my Doctor Who bluray.
Once you’ve got FFMPEG 2.x on your machine, you’re ready to start encoding. But working out your configuration options is a bit more fiddly – because while I’ve got a preset with my preferred settings in Handbrake, on the command line you need to use flags to customise the encoding process. So here’s what I use:
/usr/local/bin/ffmpeg-latest -i inputfile.mkv -map 0:0 -map 0:1 -map 0:1 -c:0 libx264 -preset slow -crf 24 -s hd720 -c:1 libfaac -ac:1 2 -c:2 ac3 -ac:2 6 outputfile.m4v
This gets me the same results as my Handbrake preset – namely, encode video with x264 with quality at rf 24, limit the resolution to 720 lines (that’s all my projector is capable of), and create two versions of the soundtrack – AAC for the iPhone, and AC3 for the surround amp connected to my Apple TV.
Here’s how it does it…
The streams I want to encode are defined by the -map flag, followed by file:stream. 0:0 is the video from my first (and only file) and 0:1 is the audio. I want to encode the video once, but I want the audio twice to give me the two versions of the same soundtrack (the AAC and AC3 versions). Hence the repeat. Then I can specify three sets of encoding details, one for each of these three mapped streams. The -c flag defines the codec, so -c:0 sets it for the first of my mapped streams and so I want the codec for the video (libx264). Then -crf sets the constant quality level (24) while -s sets the frame size (hd720). For the second of my mapped streams, which will be the AAC audio, I use -c:1 to set the codec (libfaac) and I use -ac:1 to set the number of audio channels (2). Then for the third of my mapped streams -c:2 is followed by the codec for AC3 (ac3) and -ac:2 sets the number of audio channels (6). That’s it.
Since these are the settings I want to use every time, I can just change the input and output file names, and let it churn away encoding overnight.