Skip to content

Instantly share code, notes, and snippets.

@y-a-v-a
Created June 19, 2015 12:34
Show Gist options
  • Save y-a-v-a/940ab06b5b48f800c963 to your computer and use it in GitHub Desktop.
Save y-a-v-a/940ab06b5b48f800c963 to your computer and use it in GitHub Desktop.
Create an mpg movie from a set of jpg images.
#!/bin/bash
# see http://www.ffmpeg.org/faq.html 3.2 and 3.3
#!/bin/bash
# Argument = -t test -r server -p password -v
usage()
{
cat << EOF
Usage: $0 options
This script creates a movie from separate images.
OPTIONS:
-h Show this message
-s Source path for jpeg images
-d Destination path for movie
-n Movie name mymovie.mpg
-f Frames per second (24 or 12)
-v Verbose
EOF
}
SRC=
DEST=
NAME=
VERBOSE=
FPS=24
while getopts “hs:d:n:f:v” OPTION
do
case $OPTION in
h) usage exit 1 ;;
s) SRC=$OPTARG ;;
d) DEST=$OPTARG ;;
n) NAME=$OPTARG ;;
f) if [[ ! -z $OPTARG ]]
then
FPS=$OPTARG
fi ;;
v) VERBOSE=1 ;;
?) usage exit ;;
esac
done
if [[ ! -d $SRC ]] || [[ ! -d $DEST ]] || [[ -z $NAME ]]
then
usage
exit 1
fi
if [[ -f $DEST/$NAME ]]
then
echo "* File already exists. Exiting..."
exit 1
fi
SRC=`cd $SRC && pwd`
DEST=`cd $DEST && pwd`
IT=$(bc << EOF
scale = 0
24 / $FPS
EOF
)
if [[ ! -d $DEST/tmp ]]
then
echo '* create tmp dir in destination...';
mkdir $DEST/tmp;
fi
# make symlinks for images with name img00x.jpg to let ffmpeg create mpg of it
echo '* create symlinks...'
x=1;
for i in $SRC/*.jp*g
do
for ((a=1; a <= $IT ; a++))
do
counter=$(printf %03d $x);
ln -s "$i" $DEST/tmp/img"$counter".jpg;
x=$(($x+1));
done
done
# use something like this to create an mpg
# needs extension for fps, i guess
echo '* create movie...'
# -an = audio no (disable audio)
# -r = framerate
ffmpeg -r 24 -f image2 -i $DEST/tmp/img%03d.jpg -an $DEST/$NAME
rm $DEST/tmp/img*.jpg
rmdir $DEST/tmp
echo '* done'
# more on ffmpeg
# http://electron.mit.edu/~gsteele/ffmpeg/
exit 0;
# use this to create gif
# convert -delay 6 img13*jpg movie02.gif
# how to create an mp4 h264 from an mpeg file:
# ffmpeg -y -i movie.mpg -ar 44100 -ab 96k -vcodec libx264 -s 274x72 test02.mp4
# http://diveintohtml5.org/video.html
# http://ffmpeg.org/ffmpeg.html
@y-a-v-a
Copy link
Author

y-a-v-a commented Jun 19, 2015

Instructions:
0. Run brew install ffmpeg

  1. Download the above file to a directory.
  2. Create a directory within it, from Terminal: mkdir tmp, and put all the glitched images in there.
  3. Type chmod a+x jpeg2mpg.sh and press enter.
  4. Run ./jpeg2mpg.sh -s tmp -d . -n test.mpg -f 24 -v
  5. The -s directive should point to a directory with the glitched images.
  6. The -d . means that the test.mpg file will bestored in the current directory.
  7. The -n directive says what the name of the resulting movie should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment