Mike’s Linux Desktop Experiences

August 22, 2008

Galleries, Dreamhost, mencoder and ImageMagick

Filed under: Uncategorized — Mr. Mike @ 1:11 am

Over the past couple months, I’ve been trying to create regular blog entries about travel. The trouble is that I rarely have time to sit down and write, and writing does take time.

So one thought I had was that if I could post all my photos and videos in nearly-real time, they can supplement the writing very well and very easily. They’d also be a better way to blog… in a way.

A huge impediment to regularly posting photos and video is that the video files, or even just the photographs, are huge. It’s rare that I come upon a high speed uplink, and it’s rude if I visit a cafe and upload a few hundred MB while sipping a coffee.

The trick here, is to compress the files on my machine, and not only that, because there are so many, it needs to be automated. Manual processes are error-prone, tedious and difficult to tweak after the fact.

For automatic conversion, the graphic files are easy. In the Windows world, Irfanview or even Cygwin with ImageMagick can do this without any trouble. The video files are more complex.

During the LBW, a friend of mine, Andi, he tipped me off that mencoder from the Mplayer suite works fine to transcode video into smaller sizes from the command line and to convert video files into flv format.

Fortunately, mencoder, along with mplayer and ImageMagick are indeed all available on Windows. Unfortunately, mencoder was compiled for the windows CMD shell, which means that the cygwin paths don’t work as parameters. This makes life a little more complex, but not as complex as dual booting my Ubuntu distro just to convert photos and videos.

So here’s the 0.1 version of the conversion script. Note the hardcoded paths and other awful things. It works, but it’s not beautiful. I need to create a posting script too, that might be hard because Zenphoto on Dreamhost does not seem to be all that inviting for automated posts.

#!/bin/bash

sourcedir=/cygdrive/g/Photos
targetdir=/cygdrive/g/webgallery
dostempdir=g:\\webgallerytemp
mplayerconvertbat=/cygdrive/g/webgallerytemp/mplayerconvert.bat
mencoderoptions="-of lavf -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3"

OFS=$IFS
IFS='
'

for i in `find $sourcedir -iname *.JPG`
do
if [ ! -e "$targetdir/$i" ]
then
printf "$i"...
mkdir -p "$targetdir/`dirname $i`"
convert -resize 1024 -quality 80 "$i" "$targetdir/$i"
if [ "$?" -eq "0" ]; then echo ... done; fi
fi
done

for i in `find $sourcedir -iname *.MOV`
do
if [ ! -e "$targetdir/$i" ]
then
# create a batch file for each command
cat <$mplayerconvertbat
@ECHO OFF
EOF
filepath=$i
dirname=`dirname $filepath`
basename=`basename $filepath`

IFS="/"
set -- $dirname
# get rid of cygdrive and assign drive letter
shift; shift
dosdir="$1:"

# replace slashes with backslashes
while [ "$1" != "" ]
do
shift
dosdir="$dosdir\\$1"
done

echo "$i"...

echo c:\\utils\\mplayer\\mencoder \"$dosdir\\$basename\" -o \"$dostempdir\\out.flv\" $mencoderoptions >> /cygdrive/g/webgallerytemp/mplayerconvert.bat
u2d /cygdrive/g/webgallerytemp/mplayerconvert.bat
cmd /c g:\\webgallerytemp\\mplayerconvert.bat

mv /cygdrive/g/webgallerytemp/out.flv "$targetdir/$i"
fi

IFS='
'

done
IFS=$OFS

Does anyone have any hints about mass-posts to Zenphoto on Dreamhost? Particularly of files >7MB?

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: