3 # requires: ...topnm, pnmscale, pnmcomp, ppmntsc, ppmtoy4m, mpeg2enc
6 # video format. pal or ntsc
9 # target image width/height (taking into account visible screen area)
10 if [ "$FORMAT" = "ntsc" ]; then
18 TMP=/tmp/image_convert.$$.pnm
23 if [ ! -d "$DIR" ]; then
27 # get the file type and set the according converter to PNM
29 FILE_TYPE=`file -i -L -b "$IMG" 2>/dev/null | cut -f2 -d/`
43 Netpbm | pnm | x-portable-pixmap)
50 echo "filetype '$FILE_TYPE' is not supported"
55 # 'chroma subsampling mode' mjpegtools >= 1.8.0
58 if ppmtoy4m -h 2>&1 | egrep -q "'420mpeg2'"; then
59 SUBSAMPLINGMODE="-S 420mpeg2"
62 # extract the image size & compute scale value
64 LANG=C # get the decimal point right
65 $TO_PNM "$IMG" >$TMP 2>/dev/null
66 S=`pnmfile $TMP | awk '{ printf "%d %d ",$4,$6 }'`
67 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; }'`
69 # now run the conversion
71 if [ "$FORMAT" = "ntsc" ]; then
73 pnmpad -black -width 704 -height 480 | \
75 ppmtoy4m -v 0 -n 1 -r -F 30000:1001 $SUBSAMPLINGMODE | \
76 mpeg2enc -f 7 -T 90 -F 4 -nn -a 2 -v 0 -o "$MPG"
79 pnmpad -black -width 704 -height 576 | \
81 ppmtoy4m -v 0 -n 1 -r -F 25:1 $SUBSAMPLINGMODE | \
82 mpeg2enc -f 7 -T 90 -F 3 -np -a 2 -v 0 -o "$MPG"