I noticed that the recording jobs sometimes got interrrupted, since the streams were not completely reliable. If ffmpeg does not get any data delivered it gives up after some time and I do not see any parameter to configure that timeout. (Please let me know if you know about it…).
I came up with a fairly crude and simple, but working, let’s call it pragmatic solution, which is generic enough to share in a post like this.
The script that registers the recording at jobs does:
...
at -m ${FORMATTED_STARTTIME} <<!
bash /home/xxx/scripts/recordIptvRobust.sh ${SEC_LENGTH} ${CHANNEL_NO} ${START_TIME}
!
...
and the recordIptvRobust.sh bash (5.0 and later since it uses the convenient epochseconds variable) script does:
...
START_EPOCH=$EPOCHSECONDS
STOP_EPOCH=$(( "${START_EPOCH} + ${SEC_LENGTH}" ))
while (("${EPOCHSECONDS} < ${STOP_EPOCH}")); do
/usr/bin/ffmpeg -i "http://stream-url-here/${CHANNEL_NO}" -y -err_detect ignore_err -c:v copy -c:a copy -t $SEC_LENGTH /home/xxx/public_html/record/record_${STARTTIME//:}${CHANNEL_NO}${EPOCHSECONDS}.mkv
# Give the stream some time to restore order
sleep 10
done
# Merge segments with mkvmerge
/usr/bin/mkvmerge -o /home/xxx/public_html/record/record_${STARTTIME//:}${CHANNEL_NO}.mkv $(ls -1 /home/xxx/public_html/record/record${STARTTIME//:}${CHANNEL_NO}.mkv | paste -sd" " | sed 's/ / + /g')
...