How to convert MKV to AVI using MEncoder

MEncoder actually is able to decode MKV (Matroska). However, I encounter some strange problem regarding the conversion of MKV to AVI using 1 pass encoding. The error message looks like below.

Too many audio packets in the buffer: (4096 in 8255101 bytes).
Maybe you are playing a non-interleaved stream/file or the codec failed?
For AVI files, try to force non-interleaved mode with the -ni option.

Unfortunately, my video is not AVI files. Anyway, there is a workaround for this problem.

The problem seems to cause by audio decoder for MKV or probably Ogg Vorbis. So the easiest solution is to extract audio stream first then multiplex that audio stream to a new AVI file. Follow me.

  1. Extract the uncompressed audio stream to audio.wav.

    mplayer input.mkv -ao pcm:fast:file=audio.wav -vc null -vo null
    
  2. Encode AVI using mencoder as usual plus -audiofile audio.wav.

    mencoder input.mkv \
        -ffourcc divx \
        -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=400 \
        -audiofile audio.wav \
        -oac mp3lame -lameopts vbr=3 \
        -o output.avi
    
  3. Remove the intermediate file audio.wav.

    rm -f audio.wav
    

As a result, I wrote a simple shell script to automate above steps.

#!/bin/sh
 
INPUT=$1
OUTPUT=$2
 
mplayer "$INPUT" -ao pcm:fast:file=audio.wav -vc null -vo null
mencoder "$INPUT" \
    -ffourcc divx \
    -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=400 \
    -audiofile audio.wav \
    -oac mp3lame -lameopts vbr=3 \
    -slang eng \
    -sws 2 -vf scale=352:-3 \
    -o "$OUTPUT"
 
rm -f audio.wav

In order to convert input.mkv to output.avi, run below command.

mkv2avi input.mkv output.avi

Note that the script also rescales the video to at most 352 by width. I found this tip at 1 and 2.

Tags: , , ,

why rescale the output? Is

why rescale the output? Is there no way to do this without the recale.

reduce size

I rescale the output to reduce the output file size. If you don't want to resize, just simply ignore -sws 2 -vf scale=352:-3.

MKV to AVI Converter can do this

search in google with keywords "MKV to AVI Converter", you will find the app that can convert MKV to AVI in few steps. better and easier than MEncoder , but not a freeware. OK. i directly place the link here http://www.008soft.com/mkv-to-avi.htm (if posting the link violates the policy of howforge, pls skip)

Nothing better than free software

First at all, that MKV to AVi its for windows users, second, exist a better software for windows and its free, based in mencoder http://sourceforge.net/projects/alltoavi Thanks for the script...

alltoavi

Is there a command for linux to do same thing for "mkv2avi input.mkv output.avi" using alltoavi

Thank-you, it works fine,

Thank-you, it works fine, very nice and straightforward script. I only used this setting for better quality : vcodec=mpeg4:vhq:vbitrate=6000 (and no resizing) Converted a 4.4gb HD.720p .mkv into 3gb .avi without apparent quality loss. Another movie went from 4.4gb .mkv to 3.9gb .avi.

You're the man

Thanks for this explanation, you made my day!

Nice one

Thanks I was looking for this for ages Works like a charm

Most excellent!

Thanks Sugree! Most excellent, I only wish everything was this simple... Ryan

AlltoAVI has a horrible UI

AlltoAVI has a horrible UI chock full of annoying tooltips and crap, including some background music while you convert. I'd try finding Cygwin versions of the Linux utilities first.

Post new comment