To cap off the series of scripts for doing easy timelapse video on the Raspberry Pi, here’s a script to generate a H.264 video from the images.
#!/bin/bash INPUTFOLDER=$1 INPUTNAME=$2 OUTPUTNAME=$3 if [ -z $1 ] then echo "Raspberry Pi Timelapse Video Generator Script v1.0" echo "2015 Ben Thomson 2E0GXE" echo "This script will take an image folder created by the timelapse script & convert it into H.264 Video" echo "This script expects some options in the following format:" echo "./makevid.sh <Folder> <File Prefix> <Output Video File Name>" echo "<Folder>" echo "The folder name with all the images" echo "<File Prefix>" echo "The file prefix before the frame number. Do not include the underscore before frame number." echo "<Output Video File Name>" echo "The output file name. The .mp4 file extension will be added by the script." echo "Running this script on the Raspberry Pi itself is likely to be very slow. Recommend running on a fast" echo "PC with a multicore CPU for high framerate." exit 0 fi avconv -r 10 -i ./$INPUTFOLDER/"$INPUTNAME"_%d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 $OUTPUTNAME.mp4 echo $INPUTNAME echo $INPUTFOLDER echo $OUTPUTNAME
This should be run on a powerful PC rather than the Pi – generating video on the Pi itself is likely to be very slow indeed.
I have also done a quick update to the timelapse generator script to generate images of the correct size. This helps save disk space & the video generation doesn’t have to resize the images first, saving CPU cycles.
#!/bin/bash INPUTFILE="$1" INPUTFILE+="_%d" FRAME_INTERVAL="$2" FRAME_INTERVAL_MIN="1250" RUNTIME="2073600000" DATE=$(date +"%T_%m-%d-%y") if [ -z $1 ] then echo "Raspberry Pi Timelapse Script v1.2" echo "2015 Ben Thomson 2E0GXE" echo "Images will be taken in 1920x1080 format for transcoding into video." echo "This script expects some options in the following format:" echo "./timelapse.sh <File Prefix> <Frame Interval>" echo "<File Prefix> The script will prepend this name to every image as a unique capture session identifier." echo "A sequential number is appended to the end of the filename for frame identification." echo "<Frame Interval> This is the interval between frames, in milliseconds. Minimum 1250." echo "This minimum is required to retain stability & prevent dropped frames." echo "Every time the program is started, a new folder with the current date & time is created for the images." exit 0 fi if [ $FRAME_INTERVAL -lt $FRAME_INTERVAL_MIN ] then echo Frame Interval Too Low! echo This will cause dropped frames! Exiting! exit 0 fi mkdir -p ./$DATE-$1 echo Image Folder $DATE-$1 Created echo Image Capture Interval $FRAME_INTERVAL ms echo Starting Timelapse Capture... CTRL+C To Exit... raspistill -k -n -ex auto -awb auto -mm average -w 1920 -h 1080 -o ./$DATE-$1/$INPUTFILE.jpg -tl $FRAME_INTERVAL -t $RUNTIME echo Timelapse Complete! echo File Prefix: $INPUTFILE echo Frame Interval: $FRAME_INTERVAL ms echo Folder Name: $DATE-$1
[download id=”5595″]
73s for now!