#!/bin/bash

if test -z "`which ffmpeg2theora`"; then
    echo "ppm2theora: error: could not find 'ffmpeg2theora'" > /dev/stderr
    exit 1
fi

# command="ffmpeg -f image2pipe -vcodec ppm -i - -f avi -vcodec libtheora -vb 1800K"
command="ffmpeg2theora -f image2pipe pipe:.ppm -K 8 -v 10 --artist Gerris -o /dev/stdout"
while test $# -gt 0; do
    command="$command $1"
    shift
done

if test -d "$TMPDIR" ; then
  log=`mktemp $TMPDIR/ppm2theora.XXXXXX`
else
  log=`mktemp /tmp/ppm2theora.XXXXXX`
fi

if $command 2> $log; then :
else
    cat $log > /dev/stderr
    rm -f $log
    exit 1
fi
rm -f $log

exit 0
