./convert.sh /nfs-import/Bilder/Geiselwind/DSC06332.JPG DEBUG=yes + DEBUG=yes if test "$1" == ""; then echo "Error, no parameters given!";exit 1;else IMAGEFILE="$1";fi + test /nfs-import/Bilder/Geiselwind/DSC06332.JPG == '' + IMAGEFILE=/nfs-import/Bilder/Geiselwind/DSC06332.JPG if test "$2" == ""; then CONVERT_TEMPDIR="/tmp/image"; else CONVERT_TEMPDIR=$2; fi ; + test '' == '' + CONVERT_TEMPDIR=/tmp/image if test "$2" == "nocopy"; then NOCOPY=1;CONVERT_TEMPDIR="$1";IMAGEFILE="$3";else NOCOPY=0; fi + test '' == nocopy + NOCOPY=0 mkdir -p "$CONVERT_TEMPDIR" + mkdir -p /tmp/image CONVERT_LOGFILE=$CONVERT_TEMPDIR/convert.log + CONVERT_LOGFILE=/tmp/image/convert.log CONVERT_MPEGFILE=$CONVERT_TEMPDIR/image.mpg + CONVERT_MPEGFILE=/tmp/image/image.mpg USE_IDENTIFY="true" #anything but "true" will use verbose image decoding to detect pixel sizes, which is slow but removes ImageMagick from the dep's list + USE_IDENTIFY=true IDENTIFY="${IDENTIFY:-"identify"}" #this is from ImageMagick! useed to get x and y pixel sizes the fast way + IDENTIFY=identify BACKGROUND="$CONVERT_TEMPDIR/vdr-image.background" + BACKGROUND=/tmp/image/vdr-image.background [ ! -e "$BACKGROUND" ] && ppmmake rgb:0/0/0 704 576 >"$BACKGROUND" + '[' '!' -e /tmp/image/vdr-image.background ']' [ ! -e "$BACKGROUND" ] && echo -e "Error $BACKGROUND does not exist,\n it shoud be a 704x576 black pnm file" && exit 1 + '[' '!' -e /tmp/image/vdr-image.background ']' function logit () { #uncomment for syslog loggin (/var/log/messages) # logger "convert.sh: $IMAGEFILE" echo "$IMAGEFILE" >> $CONVERT_LOGFILE echo "$1" >> $CONVERT_LOGFILE return; } mkdir -p $CONVERT_TEMPDIR + mkdir -p /tmp/image DATE=`date +%d.%m.%y-%T` date +%d.%m.%y-%T ++ date +%d.%m.%y-%T + DATE=24.03.04-01:33:44 echo "$0: $DATE: startet ..." > $CONVERT_LOGFILE + echo './convert.sh: 24.03.04-01:33:44: startet ...' DIR=$(dirname "$IMAGEFILE") dirname "$IMAGEFILE" ++ dirname /nfs-import/Bilder/Geiselwind/DSC06332.JPG + DIR=/nfs-import/Bilder/Geiselwind FILE=$(basename "$IMAGEFILE") basename "$IMAGEFILE" ++ basename /nfs-import/Bilder/Geiselwind/DSC06332.JPG + FILE=DSC06332.JPG NEWDIR="${CONVERT_TEMPDIR}${DIR}" + NEWDIR=/tmp/image/nfs-import/Bilder/Geiselwind NEWFILE="${NEWDIR}/$FILE.mpg" + NEWFILE=/tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg CMDFILE="${NEWDIR}/$FILE.cnv" + CMDFILE=/tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.cnv PARFILE="${NEWDIR}/$FILE.par" + PARFILE=/tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.par logit "CMDFILE: $CMDFILE" + logit 'CMDFILE: /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.cnv' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'CMDFILE: /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.cnv' + return logit "PARFILE: $PARFILE" + logit 'PARFILE: /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.par' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'PARFILE: /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.par' + return logit "IMAGEFILE: $IMAGEFILE"; + logit 'IMAGEFILE: /nfs-import/Bilder/Geiselwind/DSC06332.JPG' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'IMAGEFILE: /nfs-import/Bilder/Geiselwind/DSC06332.JPG' + return logit "CONVERT_MPEGFILE: $NEWFILE"; + logit 'CONVERT_MPEGFILE: /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'CONVERT_MPEGFILE: /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg' + return ROTATE="NO" + ROTATE=NO ORIGINAL="NO" + ORIGINAL=NO if test "$3" == "Right"; then ROTATE="YES"; FLIP="-rotate270"; fi + test '' == Right if test "$3" == "Left"; then ROTATE="YES"; FLIP="-rotate90"; fi + test '' == Left if test "$3" == "Original"; then ORIGINAL="YES"; fi + test '' == Original if test "$3" == "nocopy"; then NOCOPY=1; fi + test '' == nocopy echo "$3" > "$CMDFILE" + echo '' FILE_DETECT=$(file -i -L -b "$IMAGEFILE" 2>/dev/null) file -i -L -b "$IMAGEFILE" 2>/dev/null ++ file -i -L -b /nfs-import/Bilder/Geiselwind/DSC06332.JPG + FILE_DETECT=image/jpeg FILE_TYPE=$(echo "$FILE_DETECT"|cut -f1 -d";"|cut -f1 -d"/") echo "$FILE_DETECT"|cut -f1 -d";"|cut -f1 -d"/" ++ echo image/jpeg ++ cut -f1 '-d;' ++ cut -f1 -d/ + FILE_TYPE=image FILE_SUB_TYPE=$(echo "$FILE_DETECT"|cut -f1 -d";"|cut -f2 -d"/") echo "$FILE_DETECT"|cut -f1 -d";"|cut -f2 -d"/" ++ echo image/jpeg ++ cut -f1 '-d;' ++ cut -f2 -d/ + FILE_SUB_TYPE=jpeg #cache browing code [hack?] # here we detect mpeg data, and if between 10 and 130 kb we copy it, # assuming its a mpeg2 still from our own cache case "$FILE_DETECT" in video/mpeg) logit "Mpeg2 still (cache browser) used, video/mpeg file type detected, no convert." MPEG_IN_SIZE=$(du -h -k "$IMAGEFILE"|awk '{ print $1 }') [ $MPEG_IN_SIZE -gt 10 -a $MPEG_IN_SIZE -lt 120 ] && rm -f "$CONVERT_MPEGFILE" && cp -f "$IMAGEFILE" "$CONVERT_MPEGFILE" | tee -a $CONVERT_LOGFILE && exit 0 logit "Error assuming copy of mpeg2 still did fail. Exit 1" exit 1 ;; esac #end cache browser code case "$FILE_TYPE" in image) logit "Image file type detected" ;; *) logit "Not an image file : "$IMAGEFILE"" exit 1 ;; esac + logit 'Image file type detected' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'Image file type detected' + return #moved up, info need in outer else branch (if file does exist in cache) case "$FILE_SUB_TYPE" in jpeg) TO_PNM=jpegtopnm ;; tiff) TO_PNM=tifftopnm ;; x-bmp) TO_PNM=bmptoppm ;; x-png) TO_PNM=pngtopnm ;; x-portable-pixmap) TO_PNM=cat ;; gif) TO_PNM=giftopnm ;; *) logit "File "$FILE_TYPE/$FILE_SUB_TYPE" is not of supported type , EXIT 1" exit 1 ;; esac + TO_PNM=jpegtopnm if test -f "$NEWFILE" && test "$ROTATE" == "YES" || test "$ORIGINAL" == "YES"; then rm -f "$NEWFILE"; fi + test -f /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg + test NO == YES if [ ! -f "$NEWFILE" ] #if mpg does not exist in cache then [ ! -d "$NEWDIR" ] && mkdir -p -v "$NEWDIR" | tee -a $CONVERT_LOGFILE logit "CONVERT: $FILE --> $NEWFILE"; logit "File will be converted using: $TO_PNM" ############ # code for getting pixel sizes using alternative slow verbose image decoding if [ "z$USE_IDENTIFY" = "ztrue" ] then TEMP1=`echo $IMAGEFILE | sed -e "s/\///g"` TEMP2=`identify "$IMAGEFILE" | sed -e "s/\///g"` GEOMETRY=`echo $TEMP2 | sed -e "s/$TEMP1//g" | cut -d" " -f3 | cut -d"+" -f1` X_RES_TMP=`echo $GEOMETRY | cut -d"x" -f1` Y_RES_TMP=`echo $GEOMETRY | cut -d"x" -f2 | cut -d"=" -f1` else TEMP2=$($TO_PNM -verbose "$IMAGEFILE" 1>/dev/null 2>/var/tmp/jpeg.tmp;grep height < /var/tmp/jpeg.tmp ) X_RES_TMP=$(echo $TEMP2|awk '{print $5}'|sed 's/[^[:digit:]]//g') Y_RES_TMP=$(echo $TEMP2|awk '{print $6}'|sed 's/[^[:digit:]]//g') rm -f /var/tmp/jpeg.tmp fi # end code for alternating pixel size detection ########### if test "$ORIGINAL" == "YES" then logit "Orignal" fi if test "$ROTATE" == "YES" then logit "Flip Image" X_RES=$Y_RES_TMP Y_RES=$X_RES_TMP else logit "don't Flip Image" X_RES=$X_RES_TMP Y_RES=$Y_RES_TMP fi logit "X-RES: $X_RES | Y-RES: $Y_RES" # new aspect calc's #calc for the asp corrector, if less than 1.25 it will be scaled to have _apropiate_ black bars # until now it only worked for 4/3 (3/4) photos to rotate... # BUT the new code adds borders to many pictures slowing down most convertings if [ "$((${X_RES}00 / ${Y_RES}))" -lt 125 ] then X_CALC=$((576000 / $Y_RES * $X_RES / 1000)) SCALE="pnmscale -xsize=$X_CALC -ysize=576" BG_GEN="pnmcomp -align=center - $BACKGROUND" elif [ "$((${X_RES}00 / ${Y_RES}))" -gt 133 ] then Y_CALC=$((704000 / $X_RES * $Y_RES / 1000)) SCALE="pnmscale -xsize=704 -ysize=$Y_CALC" BG_GEN="pnmpaste /dev/stdin 0 $(((576 - $Y_CALC) / 2)) $BACKGROUND" else SCALE="pnmscale -xsize=704 -ysize=576" BG_GEN="pnmcomp -align=center - $BACKGROUND" fi ####### ##### # new converting code, resulting from the changed aspect calc # if [ "$ROTATE" == "YES" ];then $TO_PNM "$IMAGEFILE" | pnmflip $FLIP | $SCALE | $BG_GEN | \ ppmntsc --pal | ppmtoy4m -F 25:1 -A 4:3 | mpeg2enc -f 7 -T 90 -F 3 -np -a 2 -o "$NEWFILE" | \ tee -a $CONVERT_LOGFILE else $TO_PNM "$IMAGEFILE" | $SCALE | $BG_GEN | \ ppmntsc --pal | ppmtoy4m -F 25:1 -A 4:3 | mpeg2enc -f 7 -T 90 -F 3 -np -a 2 -o "$NEWFILE" | \ tee -a $CONVERT_LOGFILE fi else logit "$NEWFILE exists! convert not required, initialising data" if [ "z$USE_IDENTIFY" = "ztrue" ] then #old code using identify TEMP1=`echo $IMAGEFILE | sed -e "s/\///g"` TEMP2=`identify "$IMAGEFILE" | sed -e "s/\///g"` GEOMETRY=`echo $TEMP2 | sed -e "s/$TEMP1//g" | cut -d" " -f3 | cut -d"+" -f1` X_RES_TMP=`echo $GEOMETRY | cut -d"x" -f1` Y_RES_TMP=`echo $GEOMETRY | cut -d"x" -f2 | cut -d"=" -f1` else #new code using the image decoder in verbose mode to get pixel sizes TEMP2=$($TO_PNM -verbose $T 1>/dev/null 2>/var/tmp/jpeg.tmp;grep height "$PARFILE" echo "$Y_RES_TMP">>"$PARFILE" fi + '[' '!' -f /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg ']' + '[' '!' -d /tmp/image/nfs-import/Bilder/Geiselwind ']' + logit 'CONVERT: DSC06332.JPG --> /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'CONVERT: DSC06332.JPG --> /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg' + return + logit 'File will be converted using: jpegtopnm' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'File will be converted using: jpegtopnm' + return + '[' ztrue = ztrue ']' echo $IMAGEFILE | sed -e "s/\///g" ++ echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG ++ sed -e 's/\///g' + TEMP1=nfs-importBilderGeiselwindDSC06332.JPG identify "$IMAGEFILE" | sed -e "s/\///g" ++ identify /nfs-import/Bilder/Geiselwind/DSC06332.JPG ++ sed -e 's/\///g' + TEMP2=nfs-importBilderGeiselwindDSC06332.JPG JPEG 1600x1200+0+0 DirectClass 8-bit 902.0kb 0.000u 0:01 echo $TEMP2 | sed -e "s/$TEMP1//g" | cut -d" " -f3 | cut -d"+" -f1 ++ echo nfs-importBilderGeiselwindDSC06332.JPG JPEG 1600x1200+0+0 DirectClass 8-bit 902.0kb 0.000u 0:01 ++ sed -e s/nfs-importBilderGeiselwindDSC06332.JPG//g ++ cut '-d ' -f3 ++ cut -d+ -f1 + GEOMETRY=1600x1200 echo $GEOMETRY | cut -d"x" -f1 ++ echo 1600x1200 ++ cut -dx -f1 + X_RES_TMP=1600 echo $GEOMETRY | cut -d"x" -f2 | cut -d"=" -f1 ++ echo 1600x1200 ++ cut -dx -f2 ++ cut -d= -f1 + Y_RES_TMP=1200 + test NO == YES + test NO == YES + logit 'don'\''t Flip Image' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'don'\''t Flip Image' + return + X_RES=1600 + Y_RES=1200 + logit 'X-RES: 1600 | Y-RES: 1200' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo 'X-RES: 1600 | Y-RES: 1200' + return + '[' 133 -lt 125 ']' + '[' 133 -gt 133 ']' + SCALE=pnmscale -xsize=704 -ysize=576 + BG_GEN=pnmcomp -align=center - /tmp/image/vdr-image.background + '[' NO == YES ']' + jpegtopnm /nfs-import/Bilder/Geiselwind/DSC06332.JPG jpegtopnm: WRITING PPM FILE + pnmscale -xsize=704 -ysize=576 + pnmcomp -align=center - /tmp/image/vdr-image.background + ppmntsc --pal + ppmtoy4m -F 25:1 -A 4:3 INFO: [ppmtoy4m] Command-line Parameters: INFO: [ppmtoy4m] framerate: 25:1 INFO: [ppmtoy4m] pixel aspect ratio: 4:3 INFO: [ppmtoy4m] interlace: none/progressive INFO: [ppmtoy4m] starting frame: 0 INFO: [ppmtoy4m] # of frames: all, until input exhausted INFO: [ppmtoy4m] chroma subsampling: 4:2:0, JPEG/MPEG-1, interstitial siting + mpeg2enc -f 7 -T 90 -F 3 -np -a 2 -o /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg INFO: [mpeg2enc] SETTING EXTENDED MMX for MOTION! INFO: [mpeg2enc] SETTING MMX for TRANSFORM! INFO: [mpeg2enc] SETTING EXTENDED MMX for PREDICTION! + tee -a /tmp/image/convert.log pnmcomp: Error reading magic number from Netpbm image stream. Most often, this means your input file is empty. ppmntsc: Error reading magic number from Netpbm image stream. Most often, this means your input file is empty. **ERROR: [ppmtoy4m] Failed to read first frame. **ERROR: [mpeg2enc] Could not read YUV4MPEG2 header: system error (failed read/write)! ## end new converting code #### if [ ! -f "$NEWFILE" ] then logit "$DATE: ERROR Convert Image-to-MPEG2-STILL not successfull for : $IMAGEFILE"; else logit "$DATE: successfull ..."; #kind a dirty break if we dont want to copy resulting file # but pregenrate a file (e.g. using at or cron [ $NOCOPY -eq 1 ] && exit 0 if [ $(wc -c "$NEWFILE"|sed 's/^ *//'|cut -f1 -d" ") -gt 100 ] then echo "doing the copy to $CONVERT_MPEGFILE from $NEWFILE" rm -f $CONVERT_MPEGFILE cp -f "$NEWFILE" $CONVERT_MPEGFILE | tee -a $CONVERT_LOGFILE else echo "Error generated mpeg is smaller than 100 byte, so not used!!" fi fi + '[' '!' -f /tmp/image/nfs-import/Bilder/Geiselwind/DSC06332.JPG.mpg ']' + logit '24.03.04-01:33:44: ERROR Convert Image-to-MPEG2-STILL not successfull for : /nfs-import/Bilder/Geiselwind/DSC06332.JPG' + echo /nfs-import/Bilder/Geiselwind/DSC06332.JPG + echo '24.03.04-01:33:44: ERROR Convert Image-to-MPEG2-STILL not successfull for : /nfs-import/Bilder/Geiselwind/DSC06332.JPG' + return