How to convert matroska MKV to AVI on Linux ?
Today, I discover that my M3100 player doesn’t know how to play Mastroka files. Mastroka files are really kool since the subtitles are embeded in .. but that’s it, my player refuse to play open it.
This stuff can be repack in a AVI (xivd..) file with some open source tools. Here, a little script to do the hard stuff ;)
#!/usr/bin/python
# Little script to depack Matroska file, and repack them
# in a AVI + subtitle format.
import sys
import os
def message(msg):
print "=" * 78
print "= %s" % msg
print "=" * 78
def usage():
print "Mastroka repacker script"
print " Usage: "+sys.argv[0]+ " filename"
if __name__ == "__main__":
if len(sys.argv) < 2:
usage()
else:
filename = sys.argv[1]
basename = filename[:-4]
message("Unpacking file: %s" % filename)
os.system("mkvextract tracks %s 1:temp_video.avi 2:temp_audio.ogg 3:%s.srt" % (filename,basename) )
message("Repacking file: %s.avi" % basename)
os.system("ffmpeg -i temp_audio.ogg -i temp_video.avi -vcodec copy %s.avi" % (basename) )
message("Cleaning files")
os.system("rm temp_video.avi temp_audio.ogg")
/Enjoy Video
- Media Player (Dvico 3100) + Netgear WGT634U = Cheap Wifi Media Player
- Last PPP Ip .
- Howto change the sound in a video (divx)
- Extract soundtrack (MP3) from DVD with mplayer
- Building mpeg/avi/divx with a webcam
admin May 8th, 2007
- Utils
- Comments(15)
This script depends on package mkvtoolnix
i have a problem with this…
built on Jan 28 2007 22:48:38, gcc: 4.1.2 20070106 (prerelease) (Ubuntu 4.1.1-21ubuntu7)
temp_audio.ogg: could not find codec parameters
Cleaning files
root@desktop:/Potter
When it finish remove the file .ogg and .avi
Please.
what i need?
Cool script, thanks for that !!!
Tried the script but then fell foul with the ffmpeg params.
After checking out the ffmpeg site I found the latest version as of 8/1/2008 supports .mkv:
ffmpeg -i cobra.mkv -target vcd cobra.avi
Thanks for that update, Brett, it was exactly what I needed.
Thanks,
Very useful…
I’m new to this so I’m a bit confused. I tried this on a 1.1GB 720p x264 encoding and wound up with a 26MB audio file with no video. The sound quality was seriously degraded as well. I commented out the temp_video.avi file, which looks to be about the right size, but I couldn’t find anything that could play it.
What am I missing here?
Thanks,
Keith
Keith, check the mkv contains a ogg file. It’s perhaps something else. (try the file command)
Thanks for your reply “jkx”.
“file *” returns the following:
keithh@pvr [106]: file *
temp_audio.ogg: ATSC A/52 aka AC-3 aka Dolby Digital stream, 48 kHz,, complete main (CM) 3 front/2 rear, LFE on,, 384 kbit/s reserved Dolby Surround mode
temp_video.avi: JVT NAL sequence, H.264 video @ L 51
XXXXX.hdtv.x264-bia.avi: RIFF (little-endian) data, AVI, 0 x 0, >30 fps,
XXXXX.hdtv.x264-bia.mkv: Matroska data
It managed to extract a decent sized ogg file but the file command gives no indication of whether or not it is an ogg file. It probably isn’t since it’s video. Am I barking up the wrong tree here? Was your script only intended to extract the audio?
keithh@pvr [105]: wc -c *
139198464 temp_audio.ogg
1012791223 temp_video.avi
25978426 XXXXX.hdtv.x264-bia.avi
1153155923 XXXXX.hdtv.x264-bia.mkv
2331132311 total
I mispoke when I said I commented out the temp_video.avi file. I meant to say that I commented out the *removal* of that file in your script.
It looks like the tools are willing to do what I need. Perhaps I need some different options. Any more suggestions that you might have would be very welcome.
Thanks again,
Keith
Hum, take care the ogg file is a 5.2 stream. I’m quite sure you need to resample (or tweak) ffmpeg to handle this.
Hi -
Does the conversion decrease the quality of the video/audio?
Thanks
No, the quality remains the same. In fact, it’s only a repack, not a real convert
Hi i got an error when i tried this script,
I put this script into a file called mkvtoavi and made it executeable
then in bash#
./mkvtoavi
File “./mkvtoavi”, line 9
print “=” * 78
^
IndentationError: expected an indented block
And i am not really good with scriptprogramming. but it seems it’s something thats missing :( please reply to my email as soon as you can :)
Ok, figured out an answer to my own question, and got it down to one line with no intermediate files. Your modified .py script becomes:
#!/usr/bin/python
# Little script to depack Matroska file, and repack them
# in a AVI + subtitle format.
import sys
import os
def message(msg):
print “=” * 78
print “= %s” % msg
print “=” * 78
def usage():
print “Mastroka repacker script”
print ” Usage: “+sys.argv[0]+ ” filename”
if __name__ == “__main__”:
if len(sys.argv) < 2:
usage()
else:
filename = sys.argv[1]
basename = filename[:-4]
message(”Converting file: %s” % filename)
os.system(”mencoder %s -ovc lavc -oac lavc -o %s.avi” % (filename,basename) )
To Yoshii, this script needs you to tab in some things to work…
#!/usr/bin/python
# Little script to depack Matroska file, and repack them
# in a AVI + subtitle format.
import sys
import os
def message(msg):
TAB—>print “=” * 78
TAB—>print “= %s” % msg
TAB—>print “=” * 78
def usage():
TAB—>print “Mastroka repacker script”
TAB—>print ” Usage: “+sys.argv[0]+ ” filename”
if __name__ == “__main__”:
TAB—>if len(sys.argv) TAB—>usage()
TAB—>else:
TAB—>TAB—>filename = sys.argv[1]
TAB—>TAB—>basename = filename[:-4]
message(”Unpacking file: %s” % filename)
os.system(”mkvextract tracks %s 1:temp_video.avi 2:temp_audio.ogg 3:%s.srt” % (filename,basename) )
message(”Repacking file: %s.avi” % basename)
os.system(”ffmpeg -i temp_audio.ogg -i temp_video.avi -vcodec copy %s.avi” % (basename) )
message(”Cleaning files”)
os.system(”rm temp_video.avi temp_audio.ogg”)