Tuesday, September 25, 2012

Transcoding to play for DLNA capable TV

I have a Canon camera (Power Shot ELPH 310 HS). It produces good enough HD videos. I also have a DLNA server built using Open WRT+minidlna.
minidlna does not do transcoding. And somehow the MOV files produced by the Canon camera can not be played by any of the DLNA players that I have. I know you would say I deserve it, since DLNA is a deliberately crippled spec, but right now I want to play my home videos.

Finally I found a solution using Arista Transcoder (http://www.transcoder.org/).
I created this profile called "SamsungTV" on a device named dlna. You can download it here and install in Arista. Then use the UI or command line to do the format conversion.

$arista-transcode -v -p SamsungTV  -d dlna  -o tmp.MP4  ../../inbox/MVI_0648.MOV

The resulting MP4 can be played in following DLNA players.
Samsung 3D TV , Sony BlueRay player BDP  500 and Samsung BlueRay player.

Note: I had to restart and rebuild  the database for my dlna server for some reason after I added a bunch of files.

#/etc/init.d/minidlna stop; /usr/bin/minidlna -R -f /tmp/minidlna.conf

Thursday, September 20, 2012

Bluetooth mouse too fast

I recently got a Bluetooth key and mouse pair to clean up my desk. The mouse, I found was way too fast compared to the wired one. After some  research I found this program (xinput) to be useful in this case.

My input devices:

-->
First I listed my input devices:
user@box:$ xinput --list --short
Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Wacom ISDv4 E2 Finger touch id=10 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)]
⎜ ↳ TPPS/2 IBM TrackPoint id=13 [slave pointer (2)]
⎜ ↳ Logitech Logitech USB Optical Mouse id=15 [slave pointer (2)]
⎜ ↳ Dell BT Mouse id=18 [slave pointer (2)]
⎜ ↳ Dell BT Keyboard id=19 [slave pointer (2)]
Virtual core keyboard id=3 [master keyboard (2)]
Virtual core XTEST keyboard id=5 [slave keyboard (3)]
Power Button id=6 [slave keyboard (3)]
Video Bus id=7 [slave keyboard (3)]
Sleep Button id=8 [slave keyboard (3)]
Integrated Camera id=9 [slave keyboard (3)]
AT Translated Set 2 keyboard id=11 [slave keyboard (3)]
ThinkPad Extra Buttons id=14 [slave keyboard (3)]
BTC USB Multimedia Keyboard id=16 [slave keyboard (3)]
BTC USB Multimedia Keyboard id=17 [slave keyboard (3)]

Then I checked the properties for my mouse:
user@box:$ xinput --list-props "Dell BT Mouse"
Device 'Dell BT Mouse':
Device Enabled (131): 1
Coordinate Transformation Matrix (133): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
Device Accel Profile (249): 0
Device Accel Constant Deceleration (250): 1.000000
Device Accel Adaptive Deceleration (251): 1.000000
Device Accel Velocity Scaling (252): 10.000000
Evdev Axis Inversion (311): 0, 0
Evdev Axes Swap (313): 0
Axis Labels (314): "Rel X" (141), "Rel Y" (142)
Button Labels (315): "Button Left" (134), "Button Middle" (135), "Button Right" (136), "Button Wheel Up" (137), "Button Wheel Down" (138), "Button Horiz Wheel Left" (139), "Button Horiz Wheel Right" (140), "Button Side" (546), "Button Extra" (547), "Button Forward" (548), "Button Back" (549), "Button Task" (550), "Button Unknown" (310), "Button Unknown" (310), "Button Unknown" (310), "Button Unknown" (310)
Evdev Middle Button Emulation (316): 0
Evdev Middle Button Timeout (317): 50
Evdev Wheel Emulation (318): 0
Evdev Wheel Emulation Axes (319): 0, 0, 4, 5
Evdev Wheel Emulation Inertia (320): 10
Evdev Wheel Emulation Timeout (321): 200
Evdev Wheel Emulation Button (322): 4
Evdev Drag Lock Buttons (323): 0


And then I adjusted the velocity scaling:
user@box:$xinput --set-float-prop "Dell BT Mouse" 252 1.0



Tuesday, September 11, 2012

Creating a repository of Photos

Over the years I have been taking digital photographs and now have many Gigs worth (?) of them.

A few problem that I typically face,
1) Finding duplicates. I mean multiple copies of the same picture scattered all over.
2) Finding one from a particular time, like Feb 08
3) Preventing overwrites. Some how all the camera's like to have common prefixes for naming pictures. And some are even worse, every time you change the memory card, they reset the sequence. So I end up seven of them having DSC0001.JPG and each one is a different picture.


To get handle on the situation I wrote a script that looks at the picture, finds date and time and md5 hash. Then organizes them in separate folder names by year and month and names each picture by the time it was taken. If it finds a new pictures with same date time then it names later one also using the md5 hash.
Here is the script.


user@yux:/tmp$ cat ~/bin/photoRepository.sh
#!/bin/bash

if [ $# -eq 0 ];then
usage
echo "find /pictures -iname *.jpg -type f -exec $0 {} \\;"
exit
fi

findCameraModel(){
echo `exifprobe -L $1| grep -w "JPEG.APP1.Ifd0.Model" | sed "s/'//g"| awk '{print $3 "_" $4 "_" $5}'`
}

TEST=echo
FILE_NAME=$1
EXT=`echo ${FILE_NAME/*./}`
BASE_NAME=`basename $FILE_NAME .$EXT`
#echo $BASE_NAME $EXT

# see if we have already processed this file
if [ ! x$RESUME_RUN == x ]; then
grep "$FILE_NAME" cumulative_log.txt
if [ $? -eq 0 ]; then
echo $FILE_NAME has already been processed.
exit
fi
fi

# Now find the date
DATE_TIME=`exifprobe -L $FILE_NAME| grep -w DateTime | sed "s/'//g"`
DATE=`echo $DATE_TIME | awk '{print $3;}'`
TIME=`echo $DATE_TIME | awk '{print $4;}'`

FOLDER=`echo $DATE | awk 'BEGIN { FS = ":" } ; { print $1 "_" $2 }'`

if [ "x$FOLDER" == "x_" ];then
echo No DATE info in $FILE_NAME, using UNKNOWN as folder
MD5=`md5sum $FILE_NAME | awk '{print $1}'`
CAMERA=`findCameraModel $FILE_NAME`
if [ "x$CAMERA" == "x" ];then
CAMERA=UNKNOWN_CAMERA
fi
FOLDER=$CAMERA/UNKNOWN/`echo $MD5 | cut -c 1 `
NEW_NAME=${CAMERA}_$MD5
else
NEW_NAME=`echo ${DATE}_${TIME} | sed "s/:/_/g"`
fi

if [ ! -d $FOLDER ]; then
echo folder $FOLDER will be created
mkdir -p $FOLDER
fi


FULLPATH=$FOLDER/$NEW_NAME.$EXT

if [ -f $FULLPATH ]; then
echo -n file $FULLPATH already exists

MD5SUM1=`md5sum $FILE_NAME | awk '{print $1}'`
MD5SUM2=`md5sum $FULLPATH | awk '{print $1}'`
if [ $MD5SUM1 == $MD5SUM2 ]; then
echo , and they have same checksum $MD5SUM1 so you need to delete $FILE_NAME
echo rm $FILE_NAME \# $MD5SUM2 $FULLPATH >> cumulative_log.txt
exit
else
FULLPATH=$FOLDER/${NEW_NAME}_${MD5SUM1}.$EXT
echo , This file will be copied as $FULLPATH
sleep 2
fi
fi

touch $FULLPATH
if [ $? -eq 0 ]; then
if [ ! -s $FULLPATH ]; then
rm $FULLPATH
fi
#$TEST mv $FILE_NAME $FOLDER/$NEW_NAME.$EXT
echo cp -v $FILE_NAME $FULLPATH \# $MD5SUM2 >> cumulative_log.txt
cp -v $FILE_NAME $FULLPATH
fi

Mounting SD card from Epson printer on a Linux machine.

Mounting SD card from Epson printer on a Linux machine.

I have my workstation that I need to copy pictures on, from my Camera. Hooking the SD card using a SD card adapter is a choice, but I am too lazy to do it. I also have a EPSON Workforce 545 which has SD card slot and wifi. I use it a scanner as well. When working as scanner it creates images on the SD card.

I am not sure if there are drivers for Linux or not, but who cares? I just pop in the SD card in the printer and turn it on. Then use this script to mount the SD card on my Linux workstation.
The method should work on any printer that exposes the SD card over network as SMB share.

Linux version:

user@yux:~/tmp$ uname -a
Linux yux 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

The script to do mounting:

user@yux:/tmp$ cat ~/bin/mountEpson.sh
#!/bin/bash
REPOSITORY=/home/krishna/Documents/epson
EPSON_MOUNT=/tmp/epson/
PRINTER_MAC=0026AB5FCDF9
SUBNET=192.168.11.0/24

mountEpson()
{
echo Discovering Epson printer, it may take a while.
#nmap -oG /tmp/nmap.txt -p 80,9100,631,445 192.168.11.0/24 > /tmp/nmap.verbose.txt
nmap -oG /tmp/nmap.txt -p 631 $SUBNET > /tmp/nmap.verbose.txt
PRINTER_IPS=`grep open /tmp/nmap.txt | grep -v closed | awk '{print $2 ;}'`
if [ "x$PRINTER_MAC" == "x" ]; then
echo Printer MAC Adress not defined, first found printer will be used.
PRINTER_IP=`echo $PRINTER_IPS | tr [:blank:] "\n" | head -1`
echo Using printer with IP $PRINTER_IP , Name `findPrinterModel $PRINTER_IP` and MAC `findMacAddress $PRINTER_IP`
else
for ONE_IP in `echo $PRINTER_IPS`
do
mac=`findMacAddress $ONE_IP`
if [ "x$mac" == "x$PRINTER_MAC" ]; then
echo Printer with IP $ONE_IP \($mac\), `findPrinterModel $ONE_IP` is our printer.
PRINTER_IP=$ONE_IP
else
echo Printer with IP $ONE_IP \($mac\), `findPrinterModel $ONE_IP` is not our printer.
fi
done
if [ "x$PRINTER_IP" == "x" ]; then
echo Could not find our printer with MAC Address of $PRINTER_MAC
fi
fi
echo Trying to unmount existing mount
umount $EPSON_MOUNT

echo " "

if [ ! -d $EPSON_MOUNT ]; then
mkdir -p $EPSON_MOUNT
fi

echo Now trying to mount the SD Card
mount -t smbfs //$PRINTER_IP/MEMORYCARD $EPSON_MOUNT -o username=defaults,password=defaults
if [ $? -eq 0 ]; then
echo mounted epson sd card at $EPSON_MOUNT
if [ ! -d $EPSON_MOUNT ]; then
mkdir $REPOSITORY
fi
else
echo Failed to mount SD card.
fi

}

findMacAddress()
{
snmpget -v1 -c public $1 iso.3.6.1.2.1.2.2.1.6.1 2> /dev/null | cut -f 2 --delimiter=':' | sed 's/ //g'
}
findPrinterModel()
{
snmpget -v1 -c public $1 iso.3.6.1.2.1.25.3.2.1.3.1 2> /dev/null | cut -f 2 --delimiter=':'
}

mountEpson

Sunday, June 10, 2012

Clearwire with OpenWRT

The Clearwire USB devices allow you to connect upto 6 wireless devices on wi-fi network. If you want more what to do? Add your own router behind it.
You can use OpenWRT based router to do this easily.
I have a buffalo WZR-HP-AG300H which  has a USB port. I hooked my clear wire device to this USB port and it comes up as a typical USB to Ethernet device. After install OpenWRT in my Buffalo router just telnet and install few packages and some configuration...
1) Install OpenWRT: Download the sqashfs image and locally (openwrt-ar71xx-generic-wzr-hp-ag300h-squashfs-factory.bin). Then use firmware upgrade page on Buffalo router to upgrade the firmware.
2) After the router reboots it will get an IP  of 192.168.1.1 so you need to assign yourself 192.168.1.2 or something like that. Then telnet into the router. No ssh, just telnet.
3) I set my PC to act as a router by using the nat.sh script and then made my PC as default gateway on Buffalo router. Also edited /etc/resolve.conf on Buffalo router to use 8.8.8.8 as DNS server.
4) The use opkg on Buffalo router to install required packages.
opkg update ;
opkg install kmod-usb-net kmod-usb-net-cdc-ether luci kmod-ide-core usbutils
5) Then just start http server.
/etc/init.d/uhttpd start

6) Reboot the router
7) Now plugin the clearwire device. It will register as usb0.

8) Login into the router GUI. If you can't access the GUI then login using telnet and start the http server (step 5). Please note that you can not login using ssh unless there root password is set.

9) Add an interface using the GUI and connect the interface.
Thats it. Done. Now you can hook as many devices as you want behind Buffalo/OpenWRT .

Thursday, March 8, 2012

Command line email with attachment

The problem: How to send an email with attachment using CLI?

Solution: Use mutt.
I am assuming that you have a SMTP server from your ISP that you can use. If you don't know what is a SMTP server then this is definitely the case. Typically the smtp server's host name is smtp.youisp.net, so if you are a comcast customer your smtp server is smtp.comcast.net

To use this smtp server you have to add an entry in ~/.muttrc file. Edit this file so that it contains something like:

set smtp_url="smtp://smtp.comcast.net:587/"
set smtp_pass="yourpassword"

Then execute mutt like this:
echo "All the text that I want in Body of the message" | mutt -a -s "Picture $name" -- youemail@yourdomain.com



For example the line below send all the pictures as attachment to my email:

for name in `ls -1 *.JPG` ; 
do 
echo "Here is the picture $name" | mutt -a $name -s "Picture $name" -- to_email@domain.com; 
echo send $name; 
done


Thats it! 

Note: 
If you need to change the from address in the email then set EMAIL environment variable to desired email address


Many ISPs are not supporting port 25 anymore and also requiring user name and password. Please see for doing all that:
http://nixtricks.wordpress.com/2010/05/05/mutt-configure-mutt-to-receive-email-via-imap-and-send-via-smtp/

Thursday, March 1, 2012

Seraching the text data on clipboard

Sometimes I need to use grep command on the certain text that I am looking at in an editor. Most of them do not have good grepping facility and even if they have there is not way to feed the results to some other process for further processing.
I ended up using a tool from nirsoft called nircmd to dump the clipboard contents in a text file and then use grep from cygwin. Here is a small 3 line script that I put in my bin folder along with the nircmd tool.

$ cat /cygdrive/c/cygwin/bin/clipGrep.sh
#!/bin/bash
MY_TMP_FILE=/cygdrive/c/tmp/UIUHUTGGUYGUhhjshjhasj_
rm $MY_TMP_FILE
nircmd.exe clipboard addfile `cygpath -w $MY_TMP_FILE`
cat $MY_TMP_FILE | grep $*
Now I can take any text on clip board and just execute this to filter what I want want. For example I selected all the text on Yahoo finance and took on clipboard (Ctrl-C) then searched for word "sell"

$ clipGrep.sh  -i sell
    Sell in March and Go Away?Matt Nesto

May not be a bad advice!