Thursday 7 August 2014

Ripping DVD with FFMPEG

This more a post to myself than to others, but even so, others might find it useful as well. Because sometimes having a DVD is inconvenient compared to your usual Matroska file saved on a HDD, I was looking for a simple way to encode the DVD. I have it decrypted and copied in a folder, but there are a bunch of 1 GiB VOB files, which is a) big, b) inconvenient. So the idea is, join the VOBs and transcode it into h264 (substitute theora, vp8 or dirac if you are more radical FLOSS supporter than me) and FLAC for audio. Actually simple search on the net presented me with an easy solution using FFMPEG (I kinda had problems with using the GUI ripping software), but it took some more research (reading the ffmpeg man pages) to find out how to rip more than one audio stream into the final file (I used a JAP/ENG DVD about Aikido).

So, without further ado, here's the command:

ffmpeg -i concat:VTS_01_1.VOB\|VTS_01_2.VOB\|VTS_01_3.VOB -map 0:v -map 0:a -c:v libx264 -crf 18 -vf yadif -c:a flac aikido.mkv

And some info:

  • The ffmpeg command is in ffmpeg package, from rpmfusion free. It's not in Fedora proper because of patent issues, I believe.
  • -i concat:VTS_01_1.VOB\|VTS_01_2.VOB\|VTS_01_3.VOB marks that input file is a direct join of the three VOB files listed, the backslash is to escape the "|" so that it's seen by ffmpeg instead of bash.
  • -map 0:v tells that ALL video streams are to be copied/transcoded.
  • -map 0:a tells that ALL audio streams are to be copied/transcoded.
  • -c:v libx264 tells that for video streams we'll use libx264 codec (i. e. we'll transcode to h264).
  • -crf 18 tells that we want to use Constant Rate Factor, value 18 (which might be a bit of overkill, but I don't want to sacrifice quality for space and I don't have the time tune it).
  • -vf yadif use YADIF deinterlacing, because I don't wanna keep interlacing in the video – I'll be playing it on a computer, after all.
  • -c:a flac tells we'll be using FLAC for audio streams. It's free and lossless. Again, it might be overkill, but I like to keep the original sound without using nonfree codec like AAC or AC3.

When I originally omitted the -map parameters, only single video and single audio stream were transcoded, so it's necessary if you want to transcode more audio streams or different stream than the first one.