#!/bin/sh

# If input movie is foooo.mp4, call with "./timeswap.sh foooo mp4"

if [ "$2" = "gif" ]
then
    convert -coalesce $1.$2 temp/$1.%05d.png
else
    avconv -i $1.$2 -f image2 temp/$1.%05d.png
fi

python ./timeswap.py $1 temp temp/$1.?????.png


for KIND in x.swap y.swap noswap
do
    PREFIX=$1.${KIND}
    if [ "$2" = "gif" ]
    then
        convert -delay 5 -loop 0 temp/${PREFIX}.?????.png html/${PREFIX}.gif
    else
        avconv -i temp/${PREFIX}.%05d.png -vcodec libx264 -crf 22 html/${PREFIX}.mp4
        avconv -i temp/${PREFIX}.%05d.png -vcodec libx264 -crf 22 html/${PREFIX}.flv
        avconv -i html/${PREFIX}.flv -vframes 1 -f image2 html/${PREFIX}.png
    fi
done