SurlyJake Blog

Convert High-Def MKV to Play on Xbox 360 Using Linux

| Comments

There are a million different tutorials out there on how to convert a MKV file into a format that an xbox360 will play. You may have found, like i did, that most of them use 50 different questionable pieces of software to manipulate individual tracks and separate the mkv, etc, etc… I think those are ridiculous.

Please read the FAQ regarding xbox360 file format compatibility.  It may help you pick better options for your particular files than the general ones i offer below.

The solution is simple: Use Avidemux.

  1. Install avidemux. To install it is simple. It’s in the Ubuntu repositories and I imagine you can also find it in other distros quite easily.

  2. Open avidemux and open the mkv you want to convert. If prompted some garbage about 264 and safemode, just use safe mode and dont worry about it.

  3. Select File –> Properties. This will tell you some info on the formats in use in your video file. Take this opportunity to identify what the xbox doesn’t like. When you are finished, click OK. If you want a second opinion, open up the folder with your mkv in it. Right click –> properties –> Audio/Video tab. This will also tell you the video and audio formats.

  4. We obviously know that it wont play a video in a MKV container, so first thing to do is change the “Format” dropdown to say “MP4” (you can, of course use AVI, but the majority of files I run into are h.264 and aac audio. For this combo, you want mp4…)

  5. From the Properties menu, recall the video codec. H264 files show as “AVC1” inside of avidemux. I’m sure theres a technical reason for this, but do you want to talk about it or watch your video? Most of the time, you can leave the video droptown in avidemux on “Copy” this is nice because it means that your processor wont be re-encoding the video. This saves you quality and time.

  6. From the properties menu, recall the audio codec. If you have a video with AAC stereo audio, leave the dropdown on “copy”. This is where most of my files need some love. Many MKV’s have 5.1 surround audio tracks. This is great, but not for an xbox360. To mix the audio down to stereo, select AAC on the audio dropdown, then click “filters”. In the mixer dropdown, select “stereo”.

  7. Click “save”. Avidemux will prompt you for a filename for the converted file. It does not default a file extension, so do yourself and your xbox a favor and add one yourself like “.mp4”.

Once avidemux is finished with your file, it’s ready to go.

Script to Run Handbrake on an Entire Folder

| Comments

UPDATED 8-10-10: This script has been superceeded by its newer version at The new version features all of the previous features, but can also traverse recursively through a folder structure.
if [ -z "$1" ] ; then
for file in "$TRANSCODEDIR"/*
    HandBrakeCLI -i "${file}" -o "${file}.mp4" --preset="iPhone & iPod Touch"""

Save that into a .sh file like “”

Updating FreeBSD Ports Nicely Using Nice

| Comments

Thanks to: for pointing me in the right direction. Compiling port updates can take a while and slow down your server. What you can do is use the ‘nice’ utility to force the processes to a lower priority. This will help your server to run almost normally during an update.

When you use the ‘nice’ command inside of csh or tcsh, you need to mind that you give the full path to the binary so you dont use the built-in ‘nice’ command.

# /usr/bin/nice -n 10 {your update command}

What i use is:

# /usr/bin/nice -n 10 portupgrade -aRrP

Man page for ‘nice’:

Freebsd-update Fetch Interupted

| Comments

I lost power while freebsd-update fetch was downloading patches up to 8.0-Release-p3. When the server came back online, I ran a freebsd-update fetch again and it still found two files that needed updating. after running freebsd-update install, got this error:

# freebsd-update install
Installing updates...gunzip: (stdin): unexpected end of file
gunzip: (stdin): unexpected end of file

I guess a patch archive was corrupted. no problem though, just remove the download:

# rm -r /var/db/freebsd-update/files

now you can run

# freebsd-update fetch
Looking up mirrors... 3 mirrors found.
Fetching metadata signature for 8.0-RELEASE from done.
Fetching metadata index... done.
Fetching 2 metadata files... done.
Inspecting system... done.
Preparing to download files... done.
Fetching 2 files... done.

The following files will be updated as part of updating to 8.0-RELEASE-p3:
# freebsd-update install
Installing updates... done.

no problems

ZFS Cant Rm: No Space Left on Device

| Comments

If you completely fill up a zfs pool, it wont let you delete files on it. What you CAN do, is pick a scapegoat file to wipe out or remove a snapshot. Then you will be able to use the rm command. what I did:

# df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
themirror       39G     39G      0B   100%    /home/jacob/themirror
# rm 3gfile
rm: 3gfile: No space left on device
# dd if=/dev/null of=3gfile
0+0 records in
0+0 records out
0 bytes transferred in 0.000046 secs (0 bytes/sec)
# rm 3gfile

FreeBSD Error in /boot/loader.conf

| Comments

While experimenting with ZFS in FreeBSD, I made some tweaks to the vk.kmem_size variable in /boot/loader.conf. when setting it like this:


everything worked, but I wanted to see what would happen if i doubled it. Unfortunately, setting vm.kmem_size to 2048 kept the FreeBSD kernel from booting. At startup it would just do this:

panic: kmem_suballoc: bad status return of 3
cpuid = 0

To fix the erroneous variable setting, I had to :

  1. Reboot.

  2. Wait for the FreeBSD Boot menu. (the screen that lists Default, ACPI disabled, safe, and single user modes)

  3. Press 6 to select “Escape to loader prompt”

  4. At the loader prompt, type “show”. This will provide all the default variable settings. press the spacebar to page down. In my case, at the end, the incorrect variable was: vm.kmem_size=“2048”.

  5. to switch it back and allow the system to boot, type

    set (variable)=(correct value)

in my case this was:

set vm.kmem_size=1024M
  1. type


When you are finished with all that fun, you should edit the /boot/loader.conf file back so you don’t have to do this again. Thanks to “crsd” from the FreeBSD IRC channel for the help.

Debian Eth0, Eth1, Eth2, in Virtualbox or VMware Virtual Machines When Copying

| Comments

Debian uses udev. Udev handles mapping MAC’s to the appropriate /dev/eth(X) file. If you copy a Virtual machine, Udev will remember the MAC address of the old NIC. When you copy the machine, the virtual host usually generates a new MAC address for the VM. Udev will assign the new Device to eth1, eth2, and so on. If you want to change your NIC assignments make Udev forget the old MAC. In Debian 5 (lenny) it is in this file:


In Debian 4 (etch) it is in this file:


To apply changes in Lenny: “udevadm trigger” or “udevtrigger” (in Etch)

Karmic Install Cannot Login (Gdm Freezes) Nvidia

| Comments

On a fresh install of karmic, using an Nvidia 7800 GT. When I went to click on my username to log in, some artifacts would appear on the screen, then the system would freeze. hard. Couldnt even ctrl+alt to another console. Installing the Nvidia drivers fixed the issue. To fix it:

  1. Do a hard reset on the machine

  2. When you arrive at the GDM screen, DO NOT CLICK ON ANYTHING.

  3. press CTRL + ALT + F5. Your screen will switch over to a text console.

  4. Log in.

  5. Install the Nvidia glx driver

    sudo aptitude install nvidia-glx-new

  6. Reboot the machine.

    sudo reboot

Windows 32 (X86) or 64 (AMD64) Detection in Batch Files

| Comments

While there are a lot of ways to detect for a 64 bit version of windows. you can test for %programFiles(x86)%, but handling the output and writing the IF comparisons is messy.

In Batch files, you can easily check for architecture by using the “processor_architecture” variable. x86 versions of windows will have this set to “x86”, and x64 versions “x64”. Here’s an easy example:

    @echo off
    IF %processor_architecture% == AMD64 echo This is a 64-bit version of windows
    IF %processor_architecture% == x86 echo this is a 32-bit version of windows.

Uninstall ALL Versions of WinZip Batch Script

| Comments

I have been struggling with this for quite a while, and ran into a lot of issues with all of the different versions on our network. There are people with 100 line .vbs scripts to do this, and I think this is much simpler:

@echo off
REM    Detects winzip and silently uninstalls
REM    There is a un-stoppable pop-up window. so this will kill
REM    all instances of  IE after the UN-installation.
taskkill /F /IM wzqkpick.exe
wmic product where "name like '%%winzip%%'" call Uninstall
REM This section is for WinZip <12
If Exist "%programfiles(x86)%\Winzip\winzip32.exe" GOTO 64
If Exist "%programfiles%\Winzip\winzip32.exe" "%programfiles%\WinZip\Winzip32.exe" /Uninstallx
taskkill /F /IM iexplore.exe
"%programfiles(x86)%\WinZip\Winzip32.exe" /Uninstallx
taskkill /F /IM iexplore.exe

For getting rid of WinZip 12, the magic happens in the ‘wmic’ line. It searches all of the installed product’s names for “winzip” and will uninstall anything it finds. This only works for products that use MSI’s. If you ran this outside of a batch file, you will have to use a single % percentage sign instead of the %% double percentage sign… Windows scripting sucks, and that’s just the way it is. Same thing that happens in “FOR” loops.

I never knew anything about the Windows management instrumentation control (wmic) until now, but I will be sure to exploit it’s features.