MKV Containers - Why Use Them + Scripts 5

Posted by JD 11/02/2010 at 10:30

So the HD-Nation video-cast (available online or on your TiVo) did a few episodes about what you can do with MKV containers for your media.

Below are a few other links about MKV Containers and a few shell scripts to get the MKVs to playback correctly.

Other Links on MKVs

Other links for how and why to use MKV containers are:

Some Specific Code for MKVs

Below are a few shell scripts that I use to convert to MKV or fix different issues like audio compression or sync or video aspect ratios. I hope these help someone. These scripts are not general in nature – they are very specific to my environment and probably will not work directly for you. You will want to modify them for your needs.

mkv-convert.sh with subtitles

#!/bin/bash
FPS=30000/1001 # for TV # FPS=25 # for DVDs
for filename in "$@"; do # filenames can’t have spaces
IN=$filename
NEW=${IN/%?/mkv}
SRT=${IN/%?
/srt}
if [[ "$IN" == "$NEW" ]] ; then
NEW=${IN}.mkv
fi

if [ -f "$SRT" ] ; then # Subtitle File Available? nice mkvmerge —compression "-1:none" —default-duration "2:${FPS}fps"

-o "${NEW}" "${IN}" "$SRT"
else
nice mkvmerge —compression "-1:none" —default-duration "2:${FPS}fps"
-o "${NEW}" "${IN}"
fi
done

mkv-fix-compression.sh forces uncompressed audio headers inside MKV files so the WD TV Live HD can play the audio.

#!/bin/bash
 FPS=30000/1001 # for TV # FPS=25 # for DVDs
for filename in "$@"; do  # filenames can't have spaces
   IN=$filename
   NEW=${IN/%???/a.mkv}
   if [[ "$IN" == "$NEW" ]] ; then
      NEW=${IN}.mkv
   fi
   nice mkvmerge --compression "2:none" --default-duration "2:${FPS}fps" -o "${NEW}" "${IN}"
done

Fix Aspect Ratios during playback

#!/bin/sh
for filename in "$@"; do  # filenames can't have spaces
   IN=$filename
   nice mkvmerge --display-dimensions '1:640x480' -o "${IN}-f.mkv" "${IN}"
done

Anyway, showing concrete examples may be helpful to someone, even if the scripts are very specific for my needs. The mkvmerge program is part of the cross platform MKVToolnix. I’m using the version that Ubuntu repositories have, but you can also get mkvtoolsnix directly from the developer here. There is a GUI version of mkvmerge, mmg, for the people that prefer GUIs. There is another MKV packer from the MKVTools developer here. I’ve never used it.

Trackbacks

Use the following link to trackback from your own site:
https://blog.jdpfu.com/trackbacks?article_id=848

  1. JD 11/21/2010 at 10:27

    Good News!

    A recent WD TV Live HD firmware update (11/2010) fixes the need to disable audio compression in MKV containers. In the scripts above, that means removing the —compression “2:none” parts can be done.

    Anyway, that’s one more win for the good guys.

  2. JD 11/23/2010 at 04:20

    Another WD TV Live HD firmware update this week –
    Release 1.04.10 (11/22/10)

    • Supports Facebook application.
    • Supports Deezer application.
    • Supports Flingo application.
    • Supports AccuWeather application.
    • Supports USB keyboards.

    My device is doing the update now, so I don’t really know if this is a good thing or not. Seems to me, most of these are just ways to track users, except the USB keyboard.

    Any chance of some Bluetooth keyboard lovin’? This is a TV device after all and wireless keyboards would be good. Of course, many of the wireless keyboards do use USB dongles, so this update will help those people.

  3. Tom 04/17/2011 at 04:17

    Hello John,

    do you already know the alternative firmware WDLXTV created by b-rad?
    http://forum.wdlxtv.com/
    It provides many new features, addons and Web abilities to the WD, so perhaps it’s something you want to check.

    But the reason for my post is, I wanted to ask you for help as you seems comfortable with linux scripting:
    I use the WD for many download jobs and so I have to unrar a lot of archives. At the moment I manually create an unrar-script, but I think there should be more user-friendly way.
    So is there an easy way to create a script with the following function?

    1. Example directories and files
    /download/folder1/archive1.part1.rar
    /download/folder1/archive1.part2.rar
    /download/folder1/archive1.part3.rar
    /download/folder1/archive2.part01.rar
    /download/folder1/archive2.part02.rar

    /download/folder2/archive1.part1.rar
    /download/folder2/archive1.part2.rar

    2. The script I manually create to run the unrar-process in background
    #!/bin/sh
    unrar e -o /download/folder1/archive1.part1.rar
    unrar e -o /download/folder1/archive2.part01.rar
    unrar e -o /download/folder2/archive1.part1.rar

    3. What should be done
    - specify the folders, which should be checked: script.sh folder1 folder2
    - it checks, if the number of parts are equal to the number of the last downloaded part, otherwise a part is missing (=> if the last part number of the archive is part8 or part08, there have to be 8 parts downloaded)
    - the last part has to be smaller than the part before, otherwise it’s not the last part of the archive
    - if all is checked and ok, a script like the example under 2. is created (only part1 or part01 of each archive has to be insert)

    As my English is not so good, I hope I was able to get the point and describe it clearly though.

    Greetings
    Tom

  4. JD 04/17/2011 at 08:56

    Hi Tom,

    I looked at the WDLXTV firmware, but didn’t need any of the extras it provides. I don’t have any storage directly attached to my WD TV Live for a few reasons. I like a completely silent player, but also don’t want any hassles that running a custom firmware bring.

    That is an interesting script. I don’t use rar files much, but I’d probably run whatever scripts I came up with out of a crontab daily. I don’t really download any files from the internet except Linux ISOs and patches from Adobe’s crap.

    1 line will do what you need:

    find /download -type f -name “*1.rar” -exec unrar e {} \;
    will do it. Hopefully the blog software doesn’t break this code. Just delete the rar files after you’re done and it will never try to unrar them again. Or you could simply rename the rar file with “1.rar” in the name to something that doesn’t match the regex above. For large rar archives with 11, 21, 31, … parts, you may want a slightly different, more exclusive regex. I doubt unrar would do any harm even if those files (11, 21, 31, 41, 51, … 101, 111, 201) exist. You’d probably just gen an error.

    BTW, I’m certain that your English is better than my German, even with the 3 yrs of classes back in school. ;)

  5. Tom 04/17/2011 at 11:39

    Hi John,

    thanks for your quick reply.
    I think I understand the command you’ve provided and it should point me in the right direction. I will try some things in the next few days and perhaps I’ll get some pleasant results.
    So thanks for your help and have a nice weekend :-)

    Greetings,
    Tom