#!/bin/bash # stanimate: simple script to create stop motion videos. # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. # You can contact the original author at ns@metanohi.org echo echo if [[ $1 == "-h" || $1 == "--help" ]]; then echo " This script creates stopmotion videos." echo " Run this script in a folder with JPEG files. This script only accepts files that have the \".jpg\" suffix. If you want to create a stop motion video out of PNG files, this script is largely unnecessary. This script first converts all JPEGs into PNGs and then converts the PNGs into an OGV. It should be possible to create a stop motion video both easier and faster, but for some reason ffmpeg doesn't always seem to be best friends with both JPEGs or Theora. Take a look at http://metanohi.org/projects/img/ffmpeg-fail.png to see the problem. As a result, this script does not use ffmpeg at all. Converting JPEGs to PNGs is done by the (very slow) convert program found in the imagemagick package. Converting PNGs to OGV uses the theora_png2theora program, found in the libtheora-bin package. The first parameter decides how many frames per second (fps) your video will run at. 25 fps is the default. The second and third parametres can be used to specify the number of sizes to output video in, and if the aspect ratio should be 4:3. Specifying -4:3 as a parameter outputs the video in 4:3 instead of 16:9. By default, the stop motion video is output in the following sizes: [16:9] 1080p: 1980x1080 720p: 1280x720 576p: 1024x576 640w: 640x360 [4:3] 1080p: 1440x1080 720p: 960x720 576p: 768x576 640w: 640x480 However, by using either -a, -b or -c as a parameter, one is able to reduce the number of videos produced. Specifying -a as a parameter excludes 1080p. Specifying -b as a parameter excludes 1080p and 720p. Specifying -c as a parameter excludes 1080p, 720p and 576p. By default both 1080p, 720p, 576p and 640w versions are produced in 16:9. There is no support for sound. EXAMPLES: $ ./stanimate This will output a 16:9 film with 25 fps in all resolutions. $ ./stanimate 15 -4:3 This will produce a 4:3 video with 15 fps in all resolutions. $ ./stanimate 25 -4:3 -b This will create a 4:3 video in 640w and 576p formats with 25 fps. $ ./stanimate 10 -c This will create a 16:9 film with 10 fps in only one size (640x360). " exit elif [[ $1 == "-l" || $1 == "--license" ]]; then echo " This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more details. " echo echo exit # ----------------------- # # The program begins here # # ----------------------- # elif [ ! $1 ]; then fps=25 else fps="$1" fi echo "Film will be output in $fps fps." if [[ "$2" == "-4:3" || "$3" == "-4:3" ]]; then wa=1440 wb=960 wc=768 ha=480 else wa=1980 wb=1280 wc=1024 ha=360 fi if [[ "$2" == "-a" || "$3" == "-a" ]]; then wa=0 echo "Film will be output in three sizes:" echo "$wb"x720 echo "$wc"x576 echo 640x"$ha" elif [[ "$2" == "-b" || "$3" == "-b" ]]; then wa=0 wb=0 echo "Film will be output in two sizes:" echo "$wc"x576 echo 640x"$ha" elif [[ "$2" == "-c" || "$3" == "-c" ]]; then wa=0 wb=0 wc=0 echo "Film will be output in one size:" echo 640x"$ha" else echo "Film will be output in four sizes:" echo "$wa"x1080 echo "$wb"x720 echo "$wc"x576 echo 640x"$ha" fi echo echo "Conversion started on `date`" echo echo if [ "$wa" != 0 ]; then echo "1080p jpg to png conversion has started." mkdir "1080p" for file in *.jpg; do echo "$file => 1080p/$file.png" convert -format png -size "$wa"x1080 -resize "$wa"x1080 "$file" "1080p/$file.png" done #ffmpeg -i %03d.jpg -s "$wa"x1080 1080p/%03d.jpg.png echo "1080p jpg to png conversion has ended." echo "1080p png to ogv conversion has started." echo `theora_png2theora 1080p/%03d.jpg.png -v 5 -f $fps -o 1080p.ogv` echo "1080p png to ogv conversion has ended." echo fi if [ "$wb" != 0 ]; then echo "720p jpg to png conversion has started." mkdir "720p" for file in *.jpg; do echo "$file => 720p/$file.png" convert -format png -size "$wb"x720 -resize "$wb"x720 "$file" "720p/$file.png" done #ffmpeg -i %03d.jpg -s "$wb"x720 720p/%03d.jpg.png echo "720p jpg to png conversion has ended." echo "720p png to ogv conversion has started." echo `theora_png2theora 720p/%03d.jpg.png -v 5 -f $fps -o 720p.ogv` echo "720p png to ogv conversion has ended." echo fi if [ "$wc" != 0 ]; then echo "576p jpg to png conversion has started." mkdir "576p" for file in *.jpg; do echo "$file => 576p/$file.png" convert -format png -size "$wc"x576 -resize "$wc"x576 "$file" "576p/$file.png" done #ffmpeg -i %03d.jpg -s "$wc"x576 576p/%03d.jpg.png echo "576p jpg to png conversion has ended." echo "576p png to ogv conversion has started." echo `theora_png2theora 576p/%03d.jpg.png -v 5 -f $fps -o 576p.ogv` echo "576p png to ogv conversion has ended." echo fi echo "640w jpg to png conversion has started." mkdir "640w" for file in *.jpg; do echo "$file => 640w/$file.png" convert -format png -size 640x"$ha" -resize 640x"$ha" "$file" "640w/$file.png" done #ffmpeg -i %03d.jpg -s 640x"$ha" 640w/%03d.jpg.png echo "640w jpg to png conversion has ended." echo "640w png to ogv conversion has started." echo `theora_png2theora 640w/%03d.jpg.png -v 5 -f $fps -o 640w.ogv` echo "640w png to ogv conversion has ended." echo echo echo "Conversion ended on `date`"