Last active
April 21, 2016 14:47
-
-
Save JayGoldberg/a511f4bfef87f1cf37e582ce67201d86 to your computer and use it in GitHub Desktop.
A Bash script to create timelapse videos from JPEGs in directories
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 | |
#title :timelapse_create.bash | |
#description :scans a directory for JPEGs and makes a timelapse .mov | |
#author :"Jay Goldberg" <jaymgoldberg@gmail.com> | |
#url : | |
#license :Apache 2.0 | |
#requirements :avconv | |
#usage :./timelapse_create.bash [all,hourly,daily] | |
#======================================================================= | |
##Notes | |
#defined dirs do not have a trailing slash | |
#structure of JPEGs must be <camname>/<date 0000-00-00>/<hour>/00_00_00.jpg | |
CAMCAP="/mnt/nfs/camshots" | |
KBPS=${KBPS:-2000} | |
CAMERAS=${CAMERAS:-$(ls $CAMCAP)} | |
OUTDIR="$HOME/Videos/timelapse" | |
FSP=${FPS:-20} | |
set -u | |
all () { | |
OUTDIR="$OUTDIR/yearly" | |
HOUR=${HOUR-08} | |
MIN=${MIN-15} #start here and take $PERDAY forward, by minute | |
PERDAY=${PERDAY-2} | |
MAX=$(( $MIN + $PERDAY )) | |
for camera in $CAMERAS; do | |
outfile="${OUTDIR}/${camera}-${HOUR}_${MIN}-timelapse.mov" | |
echo Outputting to $outfile | |
if [[ ! -e $outfile ]]; then | |
for date in $(ls ${CAMCAP}/${camera}); do | |
if [[ $(ls ${CAMCAP}/${camera}/${date}/${HOUR}/${HOUR}_${MIN}_*) ]]; then # at least the photos exist | |
for shot in $(eval echo "{$MIN..$MAX}"); do | |
cat ${CAMCAP}/${camera}/${date}/${HOUR}/${HOUR}_${shot}_* # 2 photos in one min will be random order | |
done | |
fi | |
done | avconv -f image2pipe -c:v mjpeg -i - -r 24 -b ${KBPS}k "$outfile" | |
else | |
echo "file $outfile already exists" | |
fi | |
done | |
} | |
hourly () { | |
#which hours | |
#all frames? | |
OUTDIR="$OUTDIR/hourly" | |
for camera in $CAMERAS; do | |
outfile="${OUTDIR}/${camera}-${HOUR}-timelapse.mov" | |
echo Outputting to $outfile | |
if [[ ! -e $outfile ]]; then | |
for date in $(ls ${CAMCAP}/${camera}); do | |
for hour in $(ls ${CAMCAP}/${camera}/${date}); do | |
cat ${CAMCAP}/${camera}/${date}/${hour}/* | |
done | |
done | avconv -f image2pipe -c:v mjpeg -i - -r 24 -b ${KBPS}k "$outfile" | |
else | |
echo "file $outfile already exists" | |
fi | |
done | |
} | |
daily () { | |
OUTDIR="$OUTDIR/daily" | |
#MODE: entire day or between hours | |
#every frame? | |
ISDATE="2014-07-11" | |
DATE=${DATE:-${ISDATE}} | |
HOURSTART=${HOURSTART-08} | |
HOUREND=${HOUREND-19} | |
for camera in $CAMERAS; do | |
outfile="${OUTDIR}/${camera}-${DATE}-timelapse.mov" | |
echo Outputting to $outfile | |
if [[ ! -e $outfile ]]; then | |
for hour in $(ls ${CAMCAP}/${camera}/${DATE}); do | |
for jpeg in $(ls ${CAMCAP}/${camera}/${DATE}/${hour}); do | |
cat ${CAMCAP}/${camera}/${DATE}/${hour}/${jpeg} | |
done | |
done | avconv -f image2pipe -c:v mjpeg -i - -r 24 -b ${KBPS}k "$outfile" | |
else | |
echo "file $outfile already exists" | |
fi | |
done | |
} | |
# this script can be included and also be executed | |
# TODO: is there a need to source this file ever? | |
if [ ! -z $1 ]; then | |
# execute the function | |
"$@" | |
else | |
: #echo usage TODO | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment