The Humble Geek

Stuff I write.

Dressing to Unimpress

Contrary to popular belief the purpose of church is to further educate your spirit and renew your faith in God. When people worshipped in temples that had bare earth for a floor and stone for benches they did not bear silk dresses or kahki slacks. Gathering for worship should be a casual encounter and not a date with Christ. I call upon Christians to keep their fancy attire locked in the closet and attend each Sunday with their everyday clothing (if it is a suit, so be it!).

My reasoning for my feelings? A touch of a sense of biggotry. We're taught to be humble and love one another. There are those that do not have the benefit of a Sunday outfit and we should not exclude anyone by an unspoken expectation of one. A change of dress code would do us all a little good as church has become too much of a social function instead of a spritual one.

Third Times the Charm

I am putting in the call now. The Texas Rangers must win the World Series this year. The team has finally clicked and is firing on all cylinders. For most of the season they have flirted with the best record in the AL or MLB. They post high or first in the power rankings. No one else in the AL seems to be much of a threat unless Tamba Bay the Athletics keeps up their offense. I don't know what to make of the Reds or Nats in the NL until we face them in the WS, but I don't believe they are as good as us.

Why the urgency? I have a feeling after this year that the players entering free agency will part ways. Yes, the dugout is friendly and everyone are good friends but my instinct tells me Hamilton will depart for a larger contract. Other names may leave as well. This year is the year this team needs to win it all.

Crossing the Streams to the Playstation 3 (part 2)

Lets say you have downloaded some TV shows. I won't ask where you got them, but I will show you how to play them on the PS3 through Mediatomb. This will require the patches mentioned in the part 1 post as video playing is pretty stupid without them.

First off, Mediatomb needs to know what to do with .mkv files on your computer. The PS3 has no idea how to play Matroska containers unfortunately. It would be a simple and free (as in speech) for Sony to implement, but that's too hard for them to do without money or IP rights in their favor. The following settings will tell Mediatomb to stream MKV files as MPEG files and use ffmpeg to transcode.

/etc/mediatomb/config.xml

<extension-mimetype ignore-unknown="no">
    <map from="mkv" to="video/x-matroska"/>
    ... other maps already exist, don't delete them ...
</extension-mimetype>
... skip down to the <profiles> tag and add this block...
<profile name="video-matroska" enabled="yes" type="external">
    <mimetype>video/mpeg</mimetype>
    <accept-url>no</accept-url>
    <first-resource>yes</first-resource>
    <hide-original-resource>yes</hide-original-resource>
    <agent command="ffmpeg-tr" arguments="%in %out %range" />
    <buffer size="10485760" chunk-size="524288" fill-size="0"/>
</profile>

The following are a few "ffmpeg-tr" script file examples. Ffmpeg has a few options as I have come to find out that the PS3 is a bit picky at video encodings. If you do not have a flawlessly encoded file the PS3 will most likely not play the file.

The first example will require a fast machine (at least 4 cores) as it reencodes the video into a fresh H.264 stream and leaves the audio intact. Use this if the video file you have is skipping or not even playing on the PS3.

/usr/local/bin/ffmpeg-tr

#!/bin/bash

START_SECONDS=`echo "$3" | awk '{split($0,a,"-"); print a[1]}'`
MILLISECONDS=`echo "$START_SECONDS" | awk '{split($0,a,"."); print a[2]}'`
START_TIME=`echo $START_SECONDS | awk '{print strftime("%H:%M:%S", $0,1)}'`
START="$START_TIME.$MILLISECONDS"
END_SECONDS=`echo "$3" | awk '{split($0,a,"-"); print a[2]}'`
if [ -z $END_SECONDS ]
then
MILLISECONDS=`echo "$END_SECONDS" | awk '{split($0,a,"."); print a[2]}'`
END_TIME=`echo $END_SECONDS | awk '{print strftime("%H:%M:%S", $0,1)}'`
END="$END_TIME.$MILLISECONDS"
fi

exec /usr/bin/ffmpeg -threads 4 -r 24000/1001 -i "$1" -vcodec libx264 -b 8000k -preset faster -level 41 -r 24000/1001 -vsync 1 -acodec copy -async 1 -f mpegts - > "$2"

If your video file is in good shape, then you can get away without encoding anything. Most .mkv files are already in video formats the PS3 will play (h.264 video, AC3/Dolby audio) so you can get away with a direct copy of the data. This requires very little computing power so any computer can do this.

/usr/local/bin/ffmpeg-tr

#!/bin/bash

START_SECONDS=`echo "$3" | awk '{split($0,a,"-"); print a[1]}'`
MILLISECONDS=`echo "$START_SECONDS" | awk '{split($0,a,"."); print a[2]}'`
START_TIME=`echo $START_SECONDS | awk '{print strftime("%H:%M:%S", $0,1)}'`
START="$START_TIME.$MILLISECONDS"
END_SECONDS=`echo "$3" | awk '{split($0,a,"-"); print a[2]}'`
if [ -z $END_SECONDS ]
then
MILLISECONDS=`echo "$END_SECONDS" | awk '{split($0,a,"."); print a[2]}'`
END_TIME=`echo $END_SECONDS | awk '{print strftime("%H:%M:%S", $0,1)}'`
END="$END_TIME.$MILLISECONDS"
fi

exec /usr/bin/ffmpeg -threads 4 -i "$1" -vcodec copy -vbsf h264_mp4toannexb -acodec copy -copyts -copytb -f mpegts - > "$2"

You can also mix and match between re-encoding audio only or both video and audio.

Crossing the Streams to the Playstation 3 (part 1)

I wish I didn't have to write this article, but when there's a dozen audio formats, a dozen video formats, and a dozen media containers there's only one result: headaches. If you own a Playstation 3, a Linux computer, and have Mediatomb installed, you can take advantage of the UPnP feature on the PS3 to play your audio or video over the network. This part 1 of 2 posting will start with audio.

FLAC to PCM

The Playstation 3 is a funny thing when it comes to audio. If you only have Optical (TosLink) or Coax audio output you're stuck with 48kHz sample rate. If you have HDMI you can go higher. The example below will get you FLAC transcoding into 48kHz PCM that the Playstation 3 will play.

/etc/mediatomb/config.xml

<profile name="audio-flac" enabled="yes" type="external">
   <mimetype>audio/L16</mimetype>
   <accept-url>no</accept-url>
   <first-resource>yes</first-resource>
   <hide-original-resource>yes</hide-original-resource>
   <accept-ogg-theora>no</accept-ogg-theora>
   <sample-frequency>48000</sample-frequency>
   <audio-channels>2</audio-channels>
   <agent command="ffmpeg-flac" arguments="%in %out" />
   <buffer size="4194304" chunk-size="262144" fill-size="0"/>
</profile>

/usr/local/bin/ffmpeg-flac

#!/bin/bash

exec /usr/bin/ffmpeg -threads 2 -i "$1" -ar 48000 -acodec pcm_s16be -f alaw - > "$2"

Why 48kHz? I have some 96kHz media so I'd rather it go to the PS3 at the best possible rate. The PS3 will resample to 48kHz if you choose to go with 44.1kHz anyway so you might as well go with 48kHz. You can up this to 96kHz on an HDMI connection, but I don't have one to test with.

Extra Credit

Mediatomb development does not seem very active, but some folks have made patches to add features that make streaming more enjoyable. One annoying part of streaming on the PS3 is the default grey music icon for your tracks. This can be replaced by the album art with patch number one. You can't seek in tracks either, but that is also negated with patch number two.

Coming up: Transcoding matroska containers into the best possible format.

Go Go Texas Rangers

texas-rangers.jpg This is the year I can feel it. The year the Texas Rangers win the World Series. Each player is continuing to play well in the playoffs. They might not be a constant force in every game, but every player has stepped up. TV commentators have been forced to mention how well the Ranger's batting order plays and how there is no real "number 9" slot.

In a perfect world they will sweep the National League team, which will work out perfectly for my Game 4 tickets. The NL teams look like they will be good competition though so I will just hope for a good Game 4 to go to.

Go Rangers!

- page 1 of 11