Skip to content

Instantly share code, notes, and snippets.

@abock
Last active February 4, 2020 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abock/3019cf30708463facce293207898c3c5 to your computer and use it in GitHub Desktop.
Save abock/3019cf30708463facce293207898c3c5 to your computer and use it in GitHub Desktop.
Timelapse Capture
#!/bin/bash -e
basedir=$1
capturetime="${2:-5}"
ffmpeg="${3:-ffmpeg}"
function usage {
echo "$0 BASEDIR [CAPTURE_TIME [FFMPEG_PATH]]"
exit 1
}
if [[ -z "$basedir" ]]; then
usage
fi
streams=(
back@rtsp://...
front@rtsp://...
driveway@rtsp://...
)
timestamp=$(date +"%Y-%m-%d_%H.%M.%S")
datepath=${timestamp%_*}
datepath=${datepath//-/\/}
waitpids=()
for stream in "${streams[@]}"; do
stream_name=${stream%@*}
stream_uri=${stream#*@}
outdir="${basedir}/${stream_name}/${datepath}"
outfile="${outdir}/${stream_name}-${timestamp}"
logfile="${outfile}.log"
outfile="${outfile}.mp4"
mkdir -p "$outdir"
echo "Recording ${capturetime}s to ${outfile}"
"$ffmpeg" \
-hide_banner \
-rtsp_transport tcp \
-i "$stream_uri" \
-c copy \
-flags +global_header \
-t "$capturetime" \
-reset_timestamps 1 \
"$outfile" \
&>"$logfile" \
&
waitpids+=($!)
done
for pid in "${waitpids[@]}"; do
wait "$pid"
done
*/10 * * * * root sudo -u aaron /var/services/homes/aaron/lathamview.sh /volume1/LathamViewData 5 /volume1/@appstore/ffmpeg/bin/ffmpeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment