Skip to content

Instantly share code, notes, and snippets.



Forked from John07/
Created Apr 27, 2017
What would you like to do?
A small script to make recording http live streams (HLS, those streams that work on iOS devices) nicer on a Mac. Script records the stream for a defined period of time and sends the user notifications if anything goes wrong and once it's done.
# required: ffmpeg (e.g. from homebrew), terminal-notifier from
# you can schedule this with launchd to run e.g. weekly
# Specify in seconds how long the script should record (default here is 1 hour).
# Date format for the recording file name
DATE=`date "+%d-%m-%y_%H-%M"`
# start ffmpeg recording
ffmpeg -re -i -c copy -bsf:a aac_adtstoasc recording_$DATE.mp4 &
# notification that recording has started
if [ "$(pgrep -P $$ 'ffmpeg')" ]
/Applications/ -title 'ffmpeg' -message "is recording now" -sender ''
/Applications/ -title 'ffmpeg' -message "is not recording!" -sound Funk -sender ''
exit 42
# check every 30 seconds for $seconds to make sure ffmpeg is still running
START=`date +%s`
while [ $(( $(date +%s) - $seconds )) -lt $START ]; do
if [ -z "$(pgrep -P $$ 'ffmpeg')" ]
/Applications/ -title 'ffmpeg' -message "is no longer running" -sound Funk -sender ''
sleep 30
# notification when time is up
/Applications/ -title 'ffmpeg' -message "recording finished" -sound default -sender ''
# stop ffmpeg (using this because stopping ffmpeg via -t for duration turned out to be extremely unreliable)
kill $(pgrep -P $$ 'ffmpeg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment