Skip to content

Instantly share code, notes, and snippets.

@andrejacobs
Created July 12, 2019 23:14
Show Gist options
  • Save andrejacobs/1f847f4d6a306221e52330772384416a to your computer and use it in GitHub Desktop.
Save andrejacobs/1f847f4d6a306221e52330772384416a to your computer and use it in GitHub Desktop.
Create a video from today's photos taken from the Rasperry Pi Timelapse rig
#!/bin/bash
# Creates a timelapse video of today's photos
# Author: Andre Jacobs
# Overview:
# I am using a Raspberry Pi Zero W with the Camera V2 module to take timelapse photography
# The idea came from:
# https://blog.alexellis.io/raspberry-pi-timelapse/
# https://github.com/alexellis/phototimer
# Today's timelapse directory (e.g. 2019/7/12)
TODAY_DIR=`date +"%Y/%-m/%-d"`
TEMP_DIR="/tmp/timelapse"
BASE_DIR=`pwd`
mkdir -p ${TEMP_DIR}
pushd ./ > /dev/null
echo "Creating sequenced filenames"
# Loop through the sequence 0 to 23 (for possible hours)
x=1
for d in `seq 0 23`; do
# Check if a directory for the hour exists
HOUR_DIR=${TODAY_DIR}/${d}
if [[ -d "${HOUR_DIR}" ]]; then
# For each jpg image
for i in ${HOUR_DIR}/*.jpg; do
FULL_PATH=${BASE_DIR}/${i}
counter=$(printf %06d $x)
x=$(($x+1))
# Create a symlink
ln -s "${FULL_PATH}" "${TEMP_DIR}/img$counter.jpg"
done
fi
done
echo "Creating timelapse"
cd ${TEMP_DIR}
TODAY_VID=`date +"%Y-%m-%d_timelapse.mp4"`
TODAY_VID_PATH=${BASE_DIR}/${TODAY_VID}
ffmpeg -r 24 -i img%06d.jpg -s hd1080 -vcodec libx264 ${TODAY_VID_PATH}
popd > /dev/null
rm -rf ${TEMP_DIR}
@andrejacobs
Copy link
Author

I am currently syncing the timelapse photos from the Raspberry Pi to my Mac using rsync:

rsync -av pi@timelapse.local:/var/image/ ./

and then I run the makevid.sh script.

The next iteration would be to get my Linux server up and running and then have the Pi rsync every hour or so to my server.
The server will then run a cron job at the end of everyday to create the video of the day.

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