py2avi

I watch a variety of video content on my TV using an original XBox and XBMC. Some of the producers of that content have been switching to higher quality encodings using the Matroska container format1 (e.g. MKV files). These frequently do not play well on my XBMC, so I transcode them into AVI files (XVid+MP3). I googled how to do this and found a handy bash script to do this2. The only downside to that batch script was it did not extract the subtitles from MKV with “soft-subs”3. And being the lazy, forgetful git that I am; I usually would only remember as I went to playback the video file. Plainly, this was unacceptable.

So I decided to write a python-script to automatically: transcode the MKV file, extract the “soft-subs” and extract any attachments (usually true-type font files). From this was py2avi born.

1 For more information on container formats and video encoding, see A gentle introduction to video encoding.

2I’ve since lost the link where I originally found that bash script.

3“Soft-subs” are subtitles applied at playback time from a subtitle datafile, either mixed directly into the video file (.mkv, .ogm, etc), or in a separate file (.ssa, .srt, etc).

Requirements

py2avi was developed using Python 2.5 and requires: mencoder, mkvtoolnix, avifile-xvid-plugin and lame to transcode and extract data from MKV files. py2avi was developed and has been successfully run under both Ubuntu 8.04.1 LTS (hardy) and Ubuntu 8.10 (intrepid). py2avi may work elsewhere, but has not been tested to do so.

Documentation

py2avi is designed to be a cli program. To run it, simply type:

python py2avi.py video_file_to_be_transcoded.mkv

py2avi will then attempt to:

  • extract any “soft-subs” from video_file_to_be_transcoded.mkv and will write them to video_file_to_be_transcoded.ass
  • extract any other attachments included in the MKV file (usually these will be true-type font files)
  • transcode the MKV to an AVI (XVid+MP3)

ChangeLog

  • 0.1.0: Initial Release

To Do

  • Add ability to override options passed to mencoder for advanced users
  • Add ability to transcode additional file-types besides MKV.

License

py2avi is released under the GPL 2.0.

Download

Download py2avi v0.1.0