-
-
Save rewida17/86f45721da733476d16cf04e48c220d5 to your computer and use it in GitHub Desktop.
A small script to make recording http live streams ( HLS ) on a Linux. Script records the stream for a defined period of time and sends the user notifications if anything goes wrong and once it's done.
This file contains hidden or 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 | |
# required: ffmpeg notify-send or zenity ;) | |
# 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). | |
seconds=3600 | |
#Specify in miliseconds notify timeout | |
notify=3000 | |
# Date format for the recording file name | |
DATE=`date "+%d-%m-%Y_%H-%M"` | |
# start ffmpeg recording | |
ffmpeg -re -i http://website.com/playlist.m3u8 -c copy -bsf:a aac_adtstoasc recording_$DATE.mp4 & | |
# notification that recording has started | |
if [ "$(pgrep -P $$ 'ffmpeg')" ] | |
then | |
notify-send -t "$notify" "is recording now" | |
else | |
notify-send -t "$notify" "is not recording!" | |
exit 42 | |
fi | |
# 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')" ] | |
then | |
notify-send -t "$notify" "is no longer running" | |
fi | |
sleep 30 | |
done | |
# notification when time is up | |
notify-send -t "$notify" "recording finished" | |
# 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