-
-
Save yalov/a8818cbbedadc5b5db03 to your computer and use it in GitHub Desktop.
A small bash script to make ffmpeg recording HLS streams (m3u8).
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 | |
for i in {1..168} # week | |
do | |
echo "ITERATION $i" | |
seconds=3600 #hour | |
# Date format for the recording file name | |
DATE=`date "+%y%m%d_%H%M%S"` | |
# start ffmpeg recording | |
ffmpeg -loglevel warning -hide_banner -re -i http://1.2.3.4/mystream.m3u8 -c copy -bsf:a aac_adtstoasc $DATE.mp4 & | |
# notification that recording has started | |
if [ "$(pgrep -P $$ 'ffmpeg')" ] | |
then echo -e "is recording now" | |
else echo -e "is not recording!" exit 42 | |
fi | |
# check every 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 | |
echo -e "is no longer running\n" | |
break | |
else | |
echo -e "steel running" | |
fi | |
sleep 60 | |
done | |
echo -e "recording finished" | |
# stop ffmpeg (using this because stopping ffmpeg via -t for duration turned out to be extremely unreliable) | |
kill $(pgrep -P $$ 'ffmpeg') | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment