Skip to content

Instantly share code, notes, and snippets.

@jwise77
Created November 28, 2021 23:06
Show Gist options
  • Save jwise77/5250224d9e3359ff31a7d472a5c1669e to your computer and use it in GitHub Desktop.
Save jwise77/5250224d9e3359ff31a7d472a5c1669e to your computer and use it in GitHub Desktop.
bash function to create mp4 from an image sequence
function movie() {
if [ $# -lt 3 ]; then
echo "usage: movie output_movie FPS files"
kill -INT $$
fi
tmpdir=`mktemp -d`
output=$1
fps=$2
shift 2
files="$@"
count=0
suffix=`echo $1 | cut -f2 -d.`
width=`identify -format "%w" $1`
height=`identify -format "%h" $1`
# Make sure that the width is even (yuv420p format for QT)
width=`expr $width \/ 2 \* 2`
height=`expr $height \/ 2 \* 2`
cwd=`pwd`
for f in $files; do
fn=`echo $count $suffix | gawk '{printf "img%06d.%s", $1, $2}'`
ln -s $cwd/$f ${tmpdir}/${fn}
count=`expr $count + 1`
done
ffmpeg -framerate $fps -f image2 -i ${tmpdir}/img%06d.${suffix} -vcodec libx264 -pix_fmt yuv420p \
-s ${width}x${height} -crf 25 -y $output
rm -r $tmpdir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment