Code I/O

A topnotch WordPress.com site


Leave a comment

Building a simple home entertainment server …

The need: Enable consumption of media in the home network, yet keeping portability of media storage intact.

Having tons of photos, music and videos (various formats) makes it hard to organize them, as well discovering them becomes critical as time passes by.  I was evaluating various solutions that will enable me to organize,  stream and discover them such that it can be consumed in my home network.  Yet, provide me a flexibility to port content when needed (especially when I travel).

I had the following options

  1. NAS (Network storage): bulky and non-portable.  The storage sits in a centralized location and transporting the drive might be difficult.  Not all storage devices lets installation of customer software.
  2. Boxee: Pretty good at organizing content, fetching sub-titles, however, I do not like sharing my private information.
  3. UPnP media server: a little cumbersome to configure, and good ones aren’t free.
  4. iTunes: Requires format change, and works only with Apple products.  Perhaps I might end up buying more Apple tools and products (iPod, iPad, …); which changes too quickly and makes my investment look ridiculous.

However, none of the above gives me portability.

What did I finally come up with?

  • Used a portable drive – to dump all my resources
  • Used an old system that runs Ubuntu with my portable drive connected.
  • Used AutoIndex to index the drive.  This is simple, lightweight, runs as a PHP module in Apache.
  • I’ve customized AutoIndex to make MP3 audio and Video (AVI, MPEG, MP4, MKV) playable  in a browser.  No plugin is required for MP3, however, it depends on a browser plugin for Video.  I’ve also added icons for GNOME;  You can try out the updated code by downloading it from here.

I’ve also submitted the new changes to AutoIndex (in a discussion: )

When at home, use the media server, when on the go, just unplug the drive and take it along 🙂  Thus bringing in convenience and portability together.

The sandbox was built with:

  1. An old PC (a Pentium processor).
  2. Ubuntu Lucid Lynx
  3. Apache 2.0
  4. PHP 5.0
  5. AutoIndex
  6. Firefox 3.6.9 Browser


Leave a comment

5 Minutes on Linux: Automating app launch on boot

Adding corn jobs is a way to automate launching of apps. Another approach is to make those apps launch when a user logs in. Depending on how the app must be started up, one can make the right choice.

Add a wrapper to the binary to launched in /etc/init.d

echo "/home/tester/tools/apache-httpd/bin/apachectl $1" > /etc/init.d/start-apache
update-rc.d start-apache defaults 3
service start-apache start

Here is my experience: I wanted to index media on an external drive; one of the coolest indexing app I found is AutoIndex which is a PHP module (so runs under apache httpd); however this possessed a challenge. The external NTFS driver gets mounted by gvfs (fuseblk); Since I wanted to manage the drive via gvfs (and not via ntfs-3g mounting via fstab), I thought it was a good idea to leave it that way.

Now the challenge was to get apache running as a service (launched by user “daemon”) to access the gvfs mounted drive. The permissions cannot be changed (at least I have not found a resolution there).

Then, what’s the solution?

Install apache and php modules in a user account (user: tester)
Make the tester auto-login on boot
Add apache (user installed) to launch on login: (GNOME: System -> Preferences -> Startup Applications")
Add "gnome-screensaver-command -l" (Lock the screen): (GNOME: System -> Preferences -> Startup Applications")

You’ll have the user installed apache running on boot and have the screen locked for security purposes.

This is a hack I did at home to get media streaming work with drives mounted by gvfs.


Leave a comment

5 Minutes on Linux: Unable to remove user shares

Problem: Sharing directories in Linux using samba is common.  However, there are instances, when users who shared them are no longer on the system (probably removed).  The share names they used stay in the system as zombie entries.  When some one wants to share a directory using a name that was zombied, it is not possible.  The SMB protocol uses unique share names.

Challenge: for GUI users, one does not have a facility to unshare or manage the orphan shares.

Solution 1 (to unshare): use the command line:

net usershare list
net usershare delete sharename

Solution 2 (to remove orphan shares):

ls -l /var/lib/samba/usershares
sudo rm /var/lib/samba/usershares/sharename

Once this is done, users will be able to reuse the share name again.  Better approach is to automate removal of share entries from /var/lib/samba/usershares (owned by users) when the user is removed.


8 Comments

5 Minutes on Linux: How to join/merge M4V files in ubuntu?

What is M4V, how is it different from MP4? This is something that needs an understanding, click here to lean more.

 

Do you have multiple .m4v files and is looking forward to join them?  Then, I hope this post will help you.

What is required?
ubuntu 9.10 Karmic

Install gpac packages to install MP4Box tools.

sudo apt-get install gpac

Once you’ve done it, you can use the Mp4Box command to concatenate the files together:

MP4Box -cat file_01.m4v -cat file_02.m4v -cat file_03.m4v -new final.m4v

This will create a merged m4v file ready do be used.

NOTE: MP4Box will be able to concatenate only 20 files at a time.

DISCLAIMER: The script helps in processing more files, which is handy.  However, note that I still find multiple tracks in the target (sporadically), which I presume is a bug in MP4Box.  Otherwise, most of the time, this script has helped me.

Here is the script that will handy to merge many files.

#!/bin/bash

##################################################################
# mergeM4V.sh
# Merges multiple m4v files
#
# USAGE: mergeM4V.sh -d "dir1 dir2"
#
# OUTPUT: final.m4v (override this with -o new_target_name.m4v)
#
# The tracks (audio and video) are processed separately,
# if you want to avoid this, use -i option to ignore such
# processing.
##################################################################

DIRS="."
OFILE=""
TARGET="final.m4v"
USE_PARAMS=1

while getopts "d:o:i" opt; do
	case $opt in
		d)
			DIRS=$OPTARG
		;;

		o)
			TARGET=$OPTARG
		;;

		i)
			USE_PARAMS=0
		;;

		*)
			echo "USAGE: $0 -d dir_list [-o output_file] [-i]"
			exit 1
		;;
	esac
done

MP4BOX_PARAMS=""
PARAMS_1="#1:fps=23.976"
PARAMS_2="#2"

MP4BOX_OPT=""

first=0
scale=4
page_size=10

listing=""
for dir in $DIRS; do
	listing="$listing $dir/*.m4v"
done

# convert to an array for easy access
count=1
for item in $listing; do
	array_listing[$count]=$item
	count=$((count + 1))
done

page_size=10
total_files=`echo $listing | wc -w`
page=1;
pages=$(($total_files / page_size))
last_items=$(($total_files % page_size))

# Work on the array
index=1

while [ $page -le $pages ]; do
	count=1
	mp4box_args=""
	while [ $count -le $page_size ]; do
		if [ $USE_PARAMS == 1 ]; then
			mp4box_args="$mp4box_args -cat ${array_listing[$index]}$PARAMS_1 -cat ${array_listing[$index]}$PARAMS_2"
		else
			mp4box_args="$mp4box_args -cat ${array_listing[$index]}"
		fi

		count=$((count + 1))
		index=$((index + 1))
	done

	OFILE="ofile_${page}.m4v"
	MP4Box $MP4BOX_PARAMS $mp4box_args -new $OFILE
	page=$((page + 1))
done

if [ $last_items -gt 0 ]; then
	count=1
	OFILE="ofile_${page}.m4v"
	mp4box_args=""

	while [ $count -le $last_items ]; do
		if [ $USE_PARAMS == 1 ]; then
			mp4box_args="$mp4box_args -cat ${array_listing[$index]}$PARAMS_1 -cat ${array_listing[$index]}$PARAMS_2"
		else
			mp4box_args="$mp4box_args -cat ${array_listing[$index]}"
		fi
		count=$((count + 1))
		index=$((index + 1))
	done

	MP4Box $MP4BOX_PARAMS $mp4box_args -new $OFILE
fi

mp4box_args=""
for ofile in `ls ofile*`; do
	if [ $USE_PARAMS == 1 ]; then
		mp4box_args="$mp4box_args -cat $ofile$PARAMS_1 -cat $ofile$PARAMS_2"
	else
	    mp4box_args="$mp4box_args -cat $ofile"
	fi
done

MP4Box $MP4BOX_PARAMS $mp4box_args -new $TARGET
rm ofile*.m4v

exit 0


Leave a comment

5 Minutes on Linux: eclipse 3.5.1 on Ubuntu

Buying into the hype of ubuntu, recently I moved away from openSUSE 11.1 to ubuntu (on a urge to use Empathy as my default IM client).  Migrated most of the data and things seem to be going well so far.

What I liked?

  • gwibber client (can finally work in one console for twitter and Facebook)
  • Empathy (need not switch to Skype for voice chat, I can now talk to my Gmail contacts).   This was a failure on OpenSUSE, didn’t work as expected.  Hopefully this is fixed in 11.2 and I can move back soon.
  • SBackup (works well, so far data has not got corrupted)
  • Evolution (works fine as before)
  • VirtualBox (the latest release is very stable, the performance is good.  So far the virtual image works like a charm).

What needed to be added explictly?

Thinkpad fingerprint reader was not enabled, had to install libpam-thinkfinger (used synaptic package manager).  OpenSUSE is been good at this, the integration of fingerprint reader with authentication is a seamless experience.

Refer http://www.thinkwiki.org/wiki/Installing_Ubuntu_9.10_%28Karmic_Koala%29_on_a_ThinkPad_T61 to enable fingerprint reader.

What’s buggy and annoying?

The major glitch I found is with Eclipse, the buttons in most of the dialog boxes became unresponsive and was unable to find out what was going on for a while.  Did few experiments and then found that using open jdk messed up things a little – some of the contextual menu items seemed to be missing (for importing the projects and few of the import sources missed), and this prompted me to move to SUN JDK, which got back the lost context menu and import source items.  However, the glitch continued with buttons in most of the dialog boxes.

Solution:

  • Focus the button with a mouse and then hit the good old keyboards “Return/Enter Key”
  • Launch eclipse with GTK+ client side windows enabled.  This flag when set, will let GDK create all windows as native windows. This can help applications that make assumptions about 1-1 correspondence between GDK windows and X11 windows.  (This is better than the first proposal)
export GDK_NATIVE_WINDOWS=true
eclipse&

Eclipse installed from ubuntu repo and eclipse downloads has been tried with these solutions.

Configuration: IBM Thinkpad T60p, Dual Core, 3GB RAM, Ubuntu lucid lynx