examples/image_convert.sh.example
branchtrunk
changeset 0 474a1293c3c0
child 40 31537cd8ec5e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/image_convert.sh.example	Sat Dec 29 14:47:40 2007 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +#!/bin/bash
     1.5 +#
     1.6 +# requires: ...topnm, pnmscale, pnmcomp, ppmntsc, ppmtoy4m, mpeg2enc
     1.7 +#
     1.8 +
     1.9 +# video format. pal or ntsc
    1.10 +FORMAT=pal
    1.11 +
    1.12 +# target image width/height (taking into account visible screen area)
    1.13 +if [ "$FORMAT" = "ntsc" ]; then
    1.14 +  TW=600
    1.15 +  TH=420
    1.16 +else
    1.17 +  TW=632
    1.18 +  TH=512
    1.19 +fi
    1.20 +
    1.21 +TMP=/tmp/image_convert.$$.pnm
    1.22 +IMG=$1
    1.23 +MPG=$2
    1.24 +
    1.25 +DIR=`dirname "$MPG"`
    1.26 +if [ ! -d "$DIR" ]; then
    1.27 +  mkdir -p "$DIR"
    1.28 +fi
    1.29 +#
    1.30 +# get the file type and set the according converter to PNM
    1.31 +#
    1.32 +FILE_TYPE=`file -i -L -b "$IMG" 2>/dev/null | cut -f2 -d/`
    1.33 +case "$FILE_TYPE" in
    1.34 +  jpg | jpeg)
    1.35 +  TO_PNM=jpegtopnm
    1.36 +  ;;
    1.37 +  tiff)
    1.38 +  TO_PNM=tifftopnm
    1.39 +  ;;
    1.40 +  bmp | x-bmp)
    1.41 +  TO_PNM=bmptoppm
    1.42 +  ;;
    1.43 +  png | x-png)
    1.44 +  TO_PNM=pngtopnm
    1.45 +  ;;
    1.46 +  Netpbm | pnm | x-portable-pixmap)
    1.47 +  TO_PNM=cat
    1.48 +  ;;
    1.49 +  gif)
    1.50 +  TO_PNM=giftopnm
    1.51 +  ;;
    1.52 +  *)
    1.53 +  echo "filetype '$FILE_TYPE' is not supported"
    1.54 +  exit 1
    1.55 +  ;;
    1.56 +esac
    1.57 +#
    1.58 +# 'chroma subsampling mode' mjpegtools >= 1.8.0
    1.59 +#
    1.60 +SUBSAMPLINGMODE=""
    1.61 +if ppmtoy4m -h | egrep -q "'420mpeg2'"; then
    1.62 +    SUBSAMPLINGMODE="-S 420mpeg2"
    1.63 +fi
    1.64 +#
    1.65 +# extract the image size & compute scale value
    1.66 +#
    1.67 +LANG=C # get the decimal point right
    1.68 +$TO_PNM "$IMG" >$TMP 2>/dev/null
    1.69 +S=`pnmfile $TMP | awk '{ printf "%d %d ",$4,$6 }'`
    1.70 +S=`echo $S $TW $TH | awk '{ sw=$3/$1; sh=$4/$2; s=(sw<sh)?sw:sh; printf "%.4f\n",(s>1)?1.0:s; }'`
    1.71 +#
    1.72 +# now run the conversion
    1.73 +#
    1.74 +if [ "$FORMAT" = "ntsc" ]; then
    1.75 +  pnmscale $S $TMP | \
    1.76 +    pnmpad -black -width 704 -height 480 | \
    1.77 +    ppmntsc | \
    1.78 +    ppmtoy4m -v 0 -n 1 -r -F 30000:1001 $SUBSAMPLINGMODE | \
    1.79 +    mpeg2enc -f 7 -T 90 -F 4 -nn -a 2 -v 0 -o "$MPG"
    1.80 +else
    1.81 +  pnmscale $S $TMP | \
    1.82 +    pnmpad -black -width 704 -height 576 | \
    1.83 +    ppmntsc --pal | \
    1.84 +    ppmtoy4m -v 0 -n 1 -r -F 25:1 $SUBSAMPLINGMODE | \
    1.85 +    mpeg2enc -f 7 -T 90 -F 3 -np -a 2 -v 0 -o "$MPG"
    1.86 +fi
    1.87 +#
    1.88 +# cleanup
    1.89 +#
    1.90 +rm $TMP