nathan@0: #!/bin/bash nathan@0: # nathan@0: # requires: ...topnm, pnmscale, pnmcomp, ppmntsc, ppmtoy4m, mpeg2enc nathan@0: # nathan@0: nathan@0: # video format. pal or ntsc nathan@0: FORMAT=pal nathan@0: nathan@0: # target image width/height (taking into account visible screen area) nathan@0: if [ "$FORMAT" = "ntsc" ]; then nathan@0: TW=600 nathan@0: TH=420 nathan@0: else nathan@0: TW=632 nathan@0: TH=512 nathan@0: fi nathan@0: nathan@0: TMP=/tmp/image_convert.$$.pnm nathan@0: IMG=$1 nathan@0: MPG=$2 nathan@0: nathan@0: DIR=`dirname "$MPG"` nathan@0: if [ ! -d "$DIR" ]; then nathan@0: mkdir -p "$DIR" nathan@0: fi nathan@0: # nathan@0: # get the file type and set the according converter to PNM nathan@0: # nathan@0: FILE_TYPE=`file -i -L -b "$IMG" 2>/dev/null | cut -f2 -d/` nathan@0: case "$FILE_TYPE" in nathan@0: jpg | jpeg) nathan@0: TO_PNM=jpegtopnm nathan@0: ;; nathan@0: tiff) nathan@0: TO_PNM=tifftopnm nathan@0: ;; nathan@0: bmp | x-bmp) nathan@0: TO_PNM=bmptoppm nathan@0: ;; nathan@0: png | x-png) nathan@0: TO_PNM=pngtopnm nathan@0: ;; nathan@0: Netpbm | pnm | x-portable-pixmap) nathan@0: TO_PNM=cat nathan@0: ;; nathan@0: gif) nathan@0: TO_PNM=giftopnm nathan@0: ;; nathan@0: *) nathan@0: echo "filetype '$FILE_TYPE' is not supported" nathan@0: exit 1 nathan@0: ;; nathan@0: esac nathan@0: # nathan@0: # 'chroma subsampling mode' mjpegtools >= 1.8.0 nathan@0: # nathan@0: SUBSAMPLINGMODE="" nathan@40: if ppmtoy4m -h 2>&1 | egrep -q "'420mpeg2'"; then nathan@0: SUBSAMPLINGMODE="-S 420mpeg2" nathan@0: fi nathan@0: # nathan@0: # extract the image size & compute scale value nathan@0: # nathan@0: LANG=C # get the decimal point right nathan@0: $TO_PNM "$IMG" >$TMP 2>/dev/null nathan@0: S=`pnmfile $TMP | awk '{ printf "%d %d ",$4,$6 }'` nathan@0: S=`echo $S $TW $TH | awk '{ sw=$3/$1; sh=$4/$2; s=(sw1)?1.0:s; }'` nathan@0: # nathan@0: # now run the conversion nathan@0: # nathan@0: if [ "$FORMAT" = "ntsc" ]; then nathan@0: pnmscale $S $TMP | \ nathan@0: pnmpad -black -width 704 -height 480 | \ nathan@0: ppmntsc | \ nathan@0: ppmtoy4m -v 0 -n 1 -r -F 30000:1001 $SUBSAMPLINGMODE | \ nathan@0: mpeg2enc -f 7 -T 90 -F 4 -nn -a 2 -v 0 -o "$MPG" nathan@0: else nathan@0: pnmscale $S $TMP | \ nathan@0: pnmpad -black -width 704 -height 576 | \ nathan@0: ppmntsc --pal | \ nathan@0: ppmtoy4m -v 0 -n 1 -r -F 25:1 $SUBSAMPLINGMODE | \ nathan@0: mpeg2enc -f 7 -T 90 -F 3 -np -a 2 -v 0 -o "$MPG" nathan@0: fi nathan@0: # nathan@0: # cleanup nathan@0: # nathan@0: rm $TMP