iso2mkv - versatile convertor from DVD to XviD/vorbis MKV, on top of MPlayer/MEncoder
Download iso2mkv, version 2011-05-02, 8 kB
This is a command line script: quite simple and easy to use, and fast, but is started in a terminal (don't be surprised).
iso2mkv is software for automated DVD to XviD/vorbis MKV video conversion. Gives almost total control on the process of video compression at maximum quality, while being simple and straightforward to use (a kind of 'life-hack'). The intended audience is advanced end-users and the script is not user-error-proof.
Based on mplayer, mencoder, oggenc or lame, and mkvmerge (if not properly installed, won't work). This is only a Bash 3 script that wraps the other programs. If you can watch the DVD with MPlayer, you can compress it with iso2mkv. Other used programs (hopefully included in most GNU/Linux distributions) are basename, bc, nice, stat. Recommended programs are normalize and dvdxchap (from 'ogmtools').
Under construction (alpha status). Without any warranty.
- Can work from a device (/dev/hdc), image file (film.iso), DVD directory (VIDEO_TS) or list of VOB/MPEG files.
- Automated calculation and compression for the video stream to XviD.
- Extraction of the chapter information with dvdxchap.
- Compression of the audio streams to mp3 (cbr, vbr) or ogg-vorbis.
- Inclusion of zero or several audio streams in the final film (i.e. original, dubbing, director's comments).
- Extraction of the subtitles in VOBsub format (zero or more streams).
- Maximum size of the resulting files, and splitting into pieces by size or time.
- Quality selection for the video and audio streams.
- Zones(*) for higher/lower quality for the video compression, a 'simple' and an 'advanced' mode (currently MEncoder-CVS is required).
- It is possible to stop and resume the process, i.e. another day or in another directory, or only do some extractions (i.e. one audio-stream), or repeat an action etc. The program logs all launched commands which can later be examined and/or re-started.
- The script is not (user-error|novice|fool)-proof, please read it, understand it, read this help file and be sure you have write permissions and plenty of disk space.
(*) iso2mkv was the first MEncoder frontend ever to use the newly implemented, at the time still undocumented, XviD-quality-zones capability. :-)))
Things it currently can't do, but may be added in the future:
- Currently some ideas/wishes won't work because the script is unaware of the total duration of the film. Working on it. (not urgent, seems difficult)
- Use of codec other than XviD. (not urgent, medium difficult)
- Audio extraction of AC3s. (not urgent, medium difficult)
- Save to another video container (avi, ogg, ogm); even if MKV is the best, chances are that your living-room MPEG4 player won't accept it (medium urgent, medium difficult)
Options and settings
- -o /output-path/basename - where to write files and how to name them; default: ./video; will create files /output-path/basename.mkv, /output-path/basename.sub etc.
- -d /path/to/dvd-device/or/iso/or/dir - required, no trailing slash
- -T Title - dvd title number, default 1
- -a "lang lang ..." - audio languages to extract, space separated, default "128" (which is usually the original sound stream), may be a two-letter code or stream ID: en, fr, 128, 0x81. For MPEG conversion use -a 0.
- -s "sub sub ..." - subtitles to extract, space separated, no default; may be a two-letter code: en, fr, or stream ID: 0-32
- -c "crop parameters" - video filters, ex. "704:416:8:80"; no default; if not set (and if -C is not present), the script will start mplayer -vf cropdetect so that you can copy these parameters
- -b bitrate - video quality bitrate in kbit/s, default: 900
- -t filesize - target filesize in MBs; if unset will use video bitrate above
- -B "size_or_time" - break final MKV into pieces. -B "700m" for 700 megabytes; -B "00:20:00" for pieces that last 20 min. Check out the mkvmerge manual for the --split option; the sizes/times are somewhat approximative. (If you split your film, you may need additional settings for the subtitles in your film.mkv.conf)
- -U - use on-the-fly encoding for audio files, no intermediary WAVs; this skips Normalize, but saves a lot of space; the FIFO directory is /tmp and you may change it in the script itself: select a writeable directory on a filesystem that supports FIFOs (ext, reiser, not fat32); see also -D
- -V "VTS_04*.VOB" - (quotes required) VOB mode, extract the film from several VOBs instead of from a mirrored DVD; no path, path is defined in "-d" above; the VOBs should be decrypted; this mode is not extensively tested and may not work well because even MPlayer does not print enough information with the -verbose switch: use with care; for best results mirror the whole DVD and use the -T option.
This mode can also be used to convert one or many MPEGs into a xvid/mkv compressed file, see below for exemple.
- -O driver - override your default video output driver (ex. -O xv) for the cropdetect and previews, same as mplayer -vo xv. New drivers gl and gl2 cannot do a cropdetect, xv can.
- -R x/y - set picture ratio, for example 16/9 -- use if MPlayer cannot resize the picture properly. (Usually the ratio is 16/9, 16/10 or 4/3.)
- -e pixels - force a new picture width, ie. smaller (default is the same as the original video; the height is calculated automatically).
- -Q - use '-nosound' instead of '-oac copy' (not recommended, you should know what you're doing).
- -m number - set audio to MP3.
For VBR use number=[0-9] (the quality). For CBR use number>9 (the bitrate), i.e. -m 128.
Note that if unset, the default compression will be ogg-vorbis.
- -v vorbis-quality - set audio OGG-Vorbis compression, default: 4. You can add other oggenc options, i.e. -v "4 --downmix"
- -C - don't start crop-test mode, crop is OK, or no crop needed
- -u "min:sec" - start time for crop testing; default: "0:45"; if you encode a very short clip you may set this to -u 20 (for 20 sec)
- -k - keep existing files, don't re-process and overwrite if targets exist : in order to 'continue' an interrupted conversion: just append -k to the last command line.
- -A - skip audio extraction (not needed, or allready extracted)
- -S - skip subtitle extraction (not needed, or allready extracted)
- -K - skip chapter extraction (not needed)
- -p - skip first pass; allready done, and the file divx2pass.log is in the working directory. In case you are not satisfied with the quality or size of the result, just redo a second pass with different bitrate/filesize (use options -A -S -p above)
- -P - skip second pass
- -M - skip merging the video and audio into one film
- -W s - wait "s" seconds between phases. If unset, after every extraction or compression, the script will stop and ask the user to press Enter (usefull for bug-tracing). If s>0, will beep and wait "s" seconds, you can go to sleep or away and it will automatically do everything. See also below for the file "/output-dir/abort".
- -q - quiet, suppress beeps between steps
- -x blah - additional settings appended to pass1 and pass2 xvidencopts, ex. "cartoon[:greyscale:other]", default is: "turbo:pass=%d", this will append something else.
- -X blah - additional settings appended to pass2 xvidencopts, default is: turbo:pass=2:bitrate=%d. Notice: Use -x to define BOTH pass1 and pass2 additional "xvidencopts"; use -X to define only DIFFERENT pass2 "xvidencopts" than those from -x (-x adds to pass1 and to pass2; -X overwrites what may have been added to pass2).
- -n 19 - lower (re-nice) the CPU priority, default: 19 (lowest, so you can do something else on your computer)
- -N - no re-nice prefix, use default CPU priority
- -D - remove temporary WAV audio files (other temp files are not removed; see also -U, -E)
- -L - remove log file
- -E - remove ALL temporary files (never tested, not recommended)
Multizone options - not extensively tested, will work only with latest MEncoder from CVS. Be carefull, errors in your command line may not generate a complaint. Attention, the options were modified/simplified in version 0.8.0:
- -r fps - rate, frames per second, default 25.000
- -w weight - the 'simple zone mode'-Lower Quality correction, 0.01-1.00; default 0.15 (for the main film the weight is 1.00)
- -z "start end" - 'simpe zone mode', High Quality Zone start-end time (if it is min:sec) or frame (if it is a number);
- the 'time' format may be min:sec, hour:min:sec or secs, and the 'second' part may be a decimal number, like 1:33:45.1 or 4321.7s;
- the 'frame' format is a simple integer.
-z "1:0 1:33:45" (HQ is from 1min to 1h33m45s);
-z "1500 1:33:45" (1min=1500frames@25fps→1h33m45s)
- -Z "z1=w1 z2=w2 ..." - 'advanced zone mode': zonestart[=zoneweight],
space separated; zonestart can be
time (min:sec) or frame (number); zoneweight is [0.01-2.00], default 1
- same 'time' and 'frame' format as in -z.
-Z "0=0.2 1:32 1:40:33=0.15" (the 1:32 is the same as 1:32=1)
Local config files.
In the package you downloaded there is a sample config file that can be copied and edited in order to set some default options and no more enter them on the command line.
Please copy the "iso2mkv.conf" sample file in the directory "~/.mplayer/", or in the current working directory (where the program is started). The sample file is well documented and should be easy to set.
These local settings will be preserved in case of an upgrade. iso2mkv never writes to this file, it only reads from it. This should be especially usefull on BSDs as the 'stat' command for getting file sizes is different than on GNU/Linux, and the main script need no longer to be edited on every upgrade.
Other features -- control files. After each action, subtitle, audio, video pass, the program will ask you "Press 'Enter' to continue, 'Ctrl+C' to abort, 'q' to stop asking this question". There are 3 files that you can create in the output directory (where the files are written), to control the execution of the program, and override what may have been defined (-W) or replied here previously:
- if you create a file "/output-dir/abort", the script will abort the processing after the current action, like if you pressed Ctrl+C;
- if you create a file "/output-dir/fullauto", the script will change to full automatic mode, will continue without asking you to press Enter -- like if you pressed "q", or like the option "-W 4";
- if you create a file "/output-dir/reask", the script will change to interactive mode, and will ask you to press Enter -- if you previously pressed "q", or defined "-W", or had a file "fullauto";
- all these files are checked between the actions, so will take effect after the current processing; to quit immediately the whole program, press Ctrl+C several times till you return to your shell prompt.
Sample command line
iso2mkv -o "./popeye" -d "/mnt/hda8/temp-rip/POPEYE_1938" -T 2 -a "en" -s "bg en fr" -t 703
This means that files will be saved (-o) to the current directory and will be named "popeye.mkv", "popeye.sub" etc. The DVD is in the directory "/mnt/hda8/temp-rip/POPEYE_1938" (where there is a dir VIDEO_TS and inside, some .VOBs, .IFOs). The second title (-T 2) will be processed, the English audio stream (-a "en") and for the subtitles (-s "bg en fr"), Bulgarian, English and French in that order. The total target size (-t) of the files (.mkv, .sub and .idx) will try not to go beyond 703 MBs. As nothing set, the selected audio stream "en" will be extracted and converted to ogg-vorbis at quality 4.
When you start the program, if you don't indicate "crop settings" (i.e. -c "720:416:0:80"), MPlayer will be launched with the command line -verbose -vf cropdetect on the chosen title, on the 45th second of the film. That way you can copy the crop settings (-vf crop) and remove the black lines above and below the film. You can also re-check the audio and subtitles' IDs.
You can change these settings. To start the real conversion, you have to add to the command line either -c "something" (crop set), or -C -c "something" (crop set, no need to test), or only -C (no crop, no need to test).
iso2mkv -o "./popeye" -d "/mnt/hda8/temp-rip/POPEYE_1938" -T 2 -a "en" -s "bg en fr" -t 703 -c "720:416:0:80"
Crop test. If you haven't set -C, MPlayer will be launched again, just to test and see the crop settings. Press "q" to close it. If it was OK, press Enter, else press Ctrl+C and change the command line.
Then the extraction beguins: first the subtitles (one after another), then the audio streams: extraction, normalization, compression to ogg-vorbis, then the two passes of the video encoding and finally the audio and video are merged in a big .MKV file.
Finally, the files that you need are "popeye.mkv", "popeye.sub" and "popeye.idx".
Sample command line for the VOB-mode (-V switch)
iso2mkv -o "./popeye" -d "/opt/rip/VIDEO_TS" -V "VTS*.VOB" -a "128 129" -s "0 1"
This means that one title of the DVD was ripped/decrypted (with vobcopy or dvdbackup) and the VOBs are /opt/rip/VIDEO_TS/VTS*.VOB; two audio streams (128 129) and two subtitles (0 1) will be added.
Compressing a MPEG to xvid.mkv
iso2mkv -o ./fld -d ../archive.org -V "The_Flying_Deuces.mpeg" -a 0 -U -v "2 --downmix" -b 600 -x "greyscale" -c "560:416:10:8"
I downloaded the film from archive.org. It is placed in "../archive.org/The_Flying_Deuces.mpeg". Output file will be "./fld.mkv". Extract the only audio stream (-a 0) on-the-fly (-U) directly to ogg-vorbis at quality (-v) 2 and downmixed to mono. Video bitrate (-b) 600 kbps in (-x) "greyscale". Cropped (-c).
License and lack of warranty
The text in the file 'iso2mkv' is distributed under the MIT license. Without any warranty. You can use it only if you read it, fully understand what you do and have legal rights to backup your DVDs and/or your MPEGs. In no event will the writer(s) be liable for your use of their text or for you not respecting any local law, like DADvSI for example.
Brief list of major recent changes.
- 2011-05-02 - modified regular expressions to work with newer versions of Bash; if it doesn't work for you, use an older version of iso2mkv
- 2007-04-25 - fixed a bug related to the forced resize of the picture
- 2007-04-22 - added local configurations, chapter extraction, simple log file, options -e, -Q, -K, -L, finds automatically where/if there are normalize and dvdxchap, small bugfixes, better display during the on-the-fly audio encoding
- 0.8.4 - added options -E and -q (thanks to Alex Botero-Lowry) and -O. More improvements and FreeBSD compatibility will follow shortly.
- 0.8.3 - small bugfixes and fifo-filename changes.
- 0.8.2 - some bugs were fixed in the advanced multizone time-calculation -- the 'fractional seconds' support is now operational but "bc" is required again. :-(
- 0.8.1 - a problem was found in the multizone time-calculation -- the 'fractional seconds' support has been temporarily removed
- 0.8.0 - added picture ratio settings (-R); greatly simplified multizone command line options, with a 'simple' and an 'advanced' mode; changed FIFO name so now you can run multiple iso2mkv-processes at once (however, considering the CPU-load, you probably wouldn't); removed external dependencies from bc, sed, expr, their functionnality could be done in BASH; added two more control files
- 0.7.0 - added MPEG to MKV conversion, options -U (audio passthru, direct output, no intermediary WAVs), -B (split final MKV in pieces); added MP3 VBR compression, a hopefully A-V synchronization bugfix, other fixes and changes
- 0.6.0 - added option -V (extract from several VOBs, use with care); no default subtitle extraction; license changed to MIT-type license
- 0.5.1 - bugfix in the "--help", forgot to update -p and -P
- 0.5 - added options -k -u -D -W, changed options for skipping passes to -p and -P; announced at freshmeat
- 0.4 - major rewrite, added command line options (before you had to edit the script itself), added multizone options, filesize choice; announced at download.bg
- 0.3 - added ogg vorbis sound
- 0.2 - can work from a directory if it is mirror from a DVD by dvdbackup or vobcopy
- 0.1 - first release, to convert an iso image to XviD-mp3.mkv
The great programs that are used by iso2mkv:
Other usefull software, enhancing your DVD-backup (if you "mirror" your DVD to a hard disk, it should be faster when you compress it with iso2mkv):
- Vobcopy, a tool for backup, only tested with the switch "vobcopy -m" (mirror)
- DVDBackup, another good tool for backup, also tested only in "mirror" mode: "dvdbackup -M"
Other free software, similar to iso2mkv (please try them and use them, they are much better than iso2mkv for most actions and will suit most of the people):
- TuxRip, a very good and mature interactive bash script with nice features
- ANDREW, also a great interactive command line program
- OgmRip, a great GUI for ripping and encoding DVD, probably the best of them all