How to convert a VOB file to avi

aviffmpegvideovideo-encoding

I am trying to convert a VOB file copied from a DVD into an avi in Ubuntu 13.10. I tried dvdrip, which failed due to a frame count error or something. I tried acidrip as well, but it always choose an audio track I did not want to use. I would prefer to have a command line solution to create an avi with the following features:

  • usable with mplayer (i.e. using the step functions)
  • with the subtitle as required (or no one at all)
  • with the correct audio track
  • with video and audio in sync

I tried some ffmpeg and avconv commands and managed to create an avi, but the video and audio were completly out of sync. So what options should I use to have the VOB file converted to an avi file?

I would appreciate some explanations on the suggested options!

Additional information:

  1. The ffmpeg command gives the following output for the input file

    Input #0, mpeg, from 'Videos/Test/VIDEO_TS/VTS_01_1.VOB':
      Duration: 00:04:53.32, start: 0.045500, bitrate: 29284 kb/s
        Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [PAR 8:9 DAR 4:3], 7500 kb/s, 27.68 fps, 59.94 tbr, 90k tbn, 59.94 tbc
        Stream #0.1[0x82]: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
        Stream #0.2[0x80]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
        Stream #0.3[0x81]: Audio: ac3, 0 channels
    [buffer @ 0x15ca6e0] w:720 h:480 pixfmt:yuv420p
    
  2. The following command

    ffmpeg -i Videos/Test/VIDEO_TS/VTS_01_1.VOB -ss 589 -t 274 -sameq -acodec copy -ab 320k output.avi
    

    for example resulted in a crash of my Ubuntu session.

  3. The following command

    avconv -i Videos/Test/VIDEO_TS/VTS_01_1.VOB -acodec copy -vcodec copy output.avi
    

    for example resulted in the following error:

    Application provided invalid, non monotonically increasing dts to muxer in stream 1: 374 >= 374
    av_interleaved_write_frame(): Invalid argument
    
  4. The following command

    avconv -i Videos/Test/VIDEO_TS/VTS_01_1.VOB -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a libmp3lame -b:a 128k output.avi
    

    for example resulted in the following error:

    Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height
    
  5. The following command

    avconv -i Videos/Test/VIDEO_TS/VTS_01_1.VOB -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a ac3 -b:a 128k output.avi
    

    for example seemed to work for some frames. But very soon I encountered many errors of the form

    [ac3 @ 0x120d480] frame sync error
    Error while decoding stream #0:1
    frame CRC mismatch
    
  6. The following command

    mencoder Videos/Test/VIDEO_TS/VTS_01_1.VOB -oac copy -ovc x264 -x264encopts bitrate=2500 -o output.avi
    

    did some converting, but is (i) using subtitles although I did not want to use them (ii) got the audio wrong (audio and video is terribly misplaced) and (iii) seems to be slower than the movie actually goes (might take 2 hours for a 90 minute movie).

  7. I tried to command given here (third post from Xeratul), but it stopped with the error

    FATAL: Cannot initialize video driver.
    
  8. I tried the suggestion made below to look at the mencoder page. This page suggests to use two passes:

    the first reads informations about the movie, the second uses that
    information to encode.

    but neither it is explained which information to extract nor how to use them in the second pass. So I used the following command:

    mencoder Videos/Test/VIDEO_TS/VTS_01_1.VOB -nosound -ovc x264 \
    -x264encopts direct=auto:pass=2:bitrate=900:frameref=5:bframes=1:\
    me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
    -vf scale=-1:-10,harddup -o video.avi
    

    which did convert the video, but with an unwanted subtitle. It is not clear at all how I can avoid using a subtitle.

Best Answer

To get rid of the subtitles I believe you can add the -nosub switch, right after the .VOB file's name.

Example

$ mencoder Videos/Test/VIDEO_TS/VTS_01_1.VOB -nosub -nosound -ovc x264 \
-x264encopts direct=auto:pass=2:bitrate=900:frameref=5:bframes=1:\
me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
-vf scale=-1:-10,harddup -o video.avi

Details

These incantations are often very dense so to break this one down a bit

  • input file: Videos/Test/VIDEO_TS/VTS_01_1.VOB
  • output file: -o video.avi
  • no subtitles: -nosub
  • don't encode sound: -nosound
  • encode with given codec: -ovc x264

list of other codecs

$ mencoder -ovc help
MEncoder SVN-r36171-4.8.1 (C) 2000-2013 MPlayer Team

Available codecs:
   copy     - frame copy, without re-encoding. Doesn't work with filters.
   frameno  - special audio-only file for 3-pass encoding, see DOCS.
   raw      - uncompressed video. Use fourcc option to set format explicitly.
   nuv      - nuppel video
   lavc     - libavcodec codecs - best quality!
   libdv    - DV encoding with libdv v0.9.5
   xvid     - XviD encoding
   x264     - H.264 encoding
  • x264 encode options: x264encopts
  • set mode for direct motion vectors: direct=auto
  • number of passes: pass=2
  • target encoding bitrate: bitrate=900
  • pre. frames used as predictors in B- and P-frames (def: 3): frameref=5
  • concurrent # of B-frames: bframes=1
  • fullpixel motion estimation alg.: me=umh

    NOTE: umh - uneven multi-hexagon search (slow)

  • enable all macroblock types: partitions=all

  • rate-distortion optimal quantization: trellis=1

    NOTE: 2 - enabled during all mode decisions (slow, requires subq>=6)

  • quantizer increment/decerement value: qp_step=4

    NOTE: maximum value by which the quantizer may be incremented/decremented between frames (default: 4)

  • quantizer compression (default: 0.6): qcomp=0.7

  • motion prediction for macroblocks in B-frames: direct_pred=auto
  • maximum interval between keyframes in frames: keyint=300

  • options after this are video filters: -vf

NOTE: For the video filter switches, it's important that you use harddup as the last filter: it will force MEncoder to write every frame (even duplicate ones) in the output. Also, it is necessary to use scale=$WIDTH,-10 with $WIDTH as -1 to keep the original width or a new, usually smaller, width: it is necessary since the H.264 codec uses square pixels and DVDs instead use rectangular pixels.

  • scale=-1
  • -10
  • harddup
Related Question