Skip to content

Instantly share code, notes, and snippets.

@AdamBrouwersHarries
Created January 25, 2017 13:26
Show Gist options
  • Save AdamBrouwersHarries/897504cec6d361cb3b8133fcb74cf0df to your computer and use it in GitHub Desktop.
Save AdamBrouwersHarries/897504cec6d361cb3b8133fcb74cf0df to your computer and use it in GitHub Desktop.
#!/bin/sh
# Get the final framerate for the timelapse as a command line option
FR=$1
# Create a file to hold the list of clips that we create
touch "files-$FR.txt"
# Write a header into it
echo "# $FR FPS timelapse files" > "files-$FR.txt"
# Iterate over everything in this directory
for f in $(ls); do
# if it's a directory, recurse in and build a timelapse from the pictures in it
if [ -d $f ]
then
pushd $f
if [ -a $FR-timelapse.mp4 ]
then
# if the file already exists, don't rebuild it (we could use a makefile for this)
echo "File $f/$FR-timelapse.mp4 already exists!"
else
# otherwise, use ffmpeg to turn all the pictures into a videoclip
# we just use a glob pattern instead of iterating over numeric image names, as
# for some folders we might not start at IMG_0001.jpg
# this is quite hacky, and might not work if the glob pattern doesn't put the
# jpeg images in the right order. If you know the format of the filenames
# and you know they'll start at 0001, then append "-i IMG_%04d.JPG" after "-i '*.jpog"
ffmpeg -r $FR -pattern_type glob -i '*.JPG' -s hd1080 -vcodec libx264 -crf 18 -preset slow $FR-timelapse.mp4
fi
popd
# Write the filename to the list of clips
echo "file $f/$FR-timelapse.mp4" >> "files-$FR.txt"
echo "Completed file from folder $f";
fi
done
# Use ffmpeg to concatenate together the clips we just created from each folder
# Read the list of filenames from the file we wrote them to
ffmpeg -f concat -safe 0 -i files-$FR.txt -c copy full_timelapse-$FR.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment