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