2020-09-22 02:33:25 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-09-22 19:58:01 +02:00
|
|
|
# A recent version of ffmpeg is required for the loop of the provided videos
|
|
|
|
# to repeat indefinitely.
|
2020-09-24 02:32:44 +02:00
|
|
|
# Example: ./test/ocTestStream.sh ~/Downloads/*.mp4 rtmp://localhost/live/abc123
|
2020-09-22 19:58:01 +02:00
|
|
|
|
2022-12-26 04:17:13 +01:00
|
|
|
if ! [[ $1 ]]
|
2020-09-22 02:33:25 +02:00
|
|
|
then
|
|
|
|
echo "ocTestStream is used for sending pre-recorded content to a RTMP server."
|
2020-09-24 02:32:44 +02:00
|
|
|
echo "Will default to localhost with the stream key of abc123 if one isn't provided."
|
|
|
|
echo "./ocTestStream.sh *.mp4 [RTMPDESINATION]"
|
2022-12-26 04:17:13 +01:00
|
|
|
exit
|
2020-09-22 02:33:25 +02:00
|
|
|
fi
|
|
|
|
|
2020-09-24 02:32:44 +02:00
|
|
|
# Make the destination optional and point to localhost with default key
|
2022-12-26 04:17:13 +01:00
|
|
|
if [[ ${*: -1} == *"rtmp://"* ]]; then
|
|
|
|
echo "RTMP server is specified"
|
|
|
|
DESTINATION_HOST=${*: -1}
|
|
|
|
FILE_COUNT=$(( ${#} - 1 ))
|
2020-09-24 02:32:44 +02:00
|
|
|
else
|
2022-12-26 04:17:13 +01:00
|
|
|
echo "RTMP server is not specified"
|
2020-09-24 02:32:44 +02:00
|
|
|
DESTINATION_HOST="rtmp://localhost/live/abc123"
|
2022-12-26 04:17:13 +01:00
|
|
|
FILE_COUNT=${#}
|
2020-09-24 02:32:44 +02:00
|
|
|
fi
|
2020-09-22 02:33:25 +02:00
|
|
|
|
2022-12-26 04:17:13 +01:00
|
|
|
if [[ FILE_COUNT -eq 0 ]]; then
|
|
|
|
echo "ERROR: ocTestStream needs a video file for sending to the RTMP server."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
CONTENT=${*:1:${FILE_COUNT}}
|
|
|
|
|
2020-09-22 02:33:25 +02:00
|
|
|
# Delete the old list of files if it exists
|
|
|
|
if test -f list.txt; then
|
|
|
|
rm list.txt
|
|
|
|
fi
|
|
|
|
|
|
|
|
for file in $CONTENT
|
|
|
|
do
|
|
|
|
echo "file '$file'" >> list.txt
|
|
|
|
done
|
|
|
|
|
2020-10-20 06:42:52 +02:00
|
|
|
function finish {
|
|
|
|
rm list.txt
|
|
|
|
}
|
|
|
|
trap finish EXIT
|
|
|
|
|
2022-12-26 04:17:13 +01:00
|
|
|
echo "Streaming a loop of ${FILE_COUNT} videos to $DESTINATION_HOST."
|
|
|
|
if [[ FILE_COUNT -gt 1 ]]; then
|
|
|
|
echo "Warning: If these files differ greatly in formats transitioning from one to another may not always work correctly."
|
|
|
|
fi
|
|
|
|
echo "$CONTENT"
|
|
|
|
echo "...press ctl+c to exit"
|
2020-09-22 02:33:25 +02:00
|
|
|
|
2022-12-26 04:17:13 +01:00
|
|
|
ffmpeg -hide_banner -loglevel panic -stream_loop -1 -re -f concat -safe 0 -i list.txt -vcodec libx264 -profile:v high -g 48 -r 24 -sc_threshold 0 -b:v 1300k -preset veryfast -acodec copy -vf drawtext="fontfile=monofonto.ttf: fontsize=96: box=1: boxcolor=black@0.75: boxborderw=5: fontcolor=white: x=(w-text_w)/2: y=((h-text_h)/2)+((h-text_h)/4): text='%{gmtime\:%H\\\\\:%M\\\\\:%S}'" -f flv "$DESTINATION_HOST"
|