Created
June 19, 2015 12:34
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions:
0. Run
brew install ffmpeg
mkdir tmp
, and put all the glitched images in there.chmod a+x jpeg2mpg.sh
and press enter../jpeg2mpg.sh -s tmp -d . -n test.mpg -f 24 -v
-s
directive should point to a directory with the glitched images.-d .
means that the test.mpg file will bestored in the current directory.-n
directive says what the name of the resulting movie should be.