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.

6 comments:

Anonymous said...

Woh, that's the post I wanted about a month ago, thanks !

Does it keep the chapters ?

Anonymous said...

nice thanks ! But your command line is truncated on your blog, i had to browse the source code of the HTML page to see the full command.

Martin said...

@ANON 7:50 CEST: nope, it doesn't keep chapters, but using mkv-tools gui it's pretty straightforward to add them back.

@ANON 10:07 CEST: it isn't truncated, or at least it shouldn't be, it just overflows to next line, which, granted, is harder to use…

mickey said...

With your solution I found some issues. The video is not correctly generated even if the audio is fine. I found another website which uses tccat instead of concat'ing source VOBs, and appending ffmpeg in pipeline. I have tried with only 5 chapters of input DVD and they seems to work fine.
Source here

Anonymous said...

Instead of transcoding the audio to flac, you can use -c:a copy. This will copy the stream directly from the input file instead of transcoding it. You said you don't want to use a nonfree codec, but x264 is a little borderline, no?

Anonymous said...

Very nice article. I used the following on Windows, with quotes to hide the pipe characters "|". Just used x264/mp3 with defaults and the result was good.

ffmpeg -i concat:"VTS_03_1.VOB|VTS_03_2.VOB|VTS_03_3.VOB" -c:v libx264 -vf yadif -c:a mp3 output.mp4