29 November, 2013

Extracting Video from DVDs

Time and again I find a need to snag video from a DVD and perform some routine video processing.

FFMpeg works nicely with standard video files, less nicely with DVD structures.  While you can certainly extract video directly from the DVD VOB files (ref: http://en.wikibooks.org/wiki/Inside_DVD-Video/Directory_Structure) it's less than desirable since the locating the specific VOB file that contains the segment of video your interested in can be a bit of a setback.

Enter Mplayer;
Mplayer can readily play DVD contents in a user friendly way.  It can also dump the file to a more usable file if you can persuade it to do so.

You can extract the full main title into a single VOB file can be done by playing the DVD somewhat normally, but adding a few arguments;


$ mplayer dvd:// -dumpstream -dumpfile /tmp/video.vob


user@River:~$ 
The above will extract the main title into a single VOB file.  Examining with FFMpeg and you'll find that the output file has a video stream and a single audio stream;



$ ffprobe -i /tmp/video.vob

ffprobe version 1.1.2 Copyright (c) 2007-2013 the FFmpeg developers

  built on Feb 10 2013 17:42:38 with gcc 4.4.5 (Debian 4.4.5-8)

  configuration: --enable-filter=split

  libavutil      52. 13.100 / 52. 13.100

  libavcodec     54. 86.100 / 54. 86.100

  libavformat    54. 59.106 / 54. 59.106

  libavdevice    54.  3.102 / 54.  3.102

  libavfilter     3. 32.100 /  3. 32.100

  libswscale      2.  1.103 /  2.  1.103

  libswresample   0. 17.102 /  0. 17.102

[mpeg @ 0x2cd4c60] max_analyze_duration 5000000 reached at 5004678

Input #0, mpeg, from '/tmp/video.vob':

  Duration: 01:37:58.02, start: 0.280633, bitrate: 5012 kb/s

    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 32:27 DAR 16:9], 26.50 fps, 59.94 tbr, 90k tbn, 59.94 tbc

    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s


You may choose an alternative container rather than a VOB by specifying an alternative extension, such as an AVI container by specifying output file video.avi.

Now, we have something we can readily work with.

Let's snag a 30 sec clip starting at 90 seconds in:




$ ffmpeg -i /tmp/video.vob -qscale 0 -ss 90 -t 30 /tmp/clip.mpg



If you're only interested in the video, you can extract only the video by specifying;


$ mplayer dvd:// -dumpvideo -dumpfile /tmp/video01.avi


Or, if you're only interested in listening to the Big Bang Theory like an audio tape, extract only the audio;




$ mplayer dvd:// -dumpaudio -dumpfile /tmp/video01.aac




Cheers.