I will start by explaining what we are doing right now.
We are broadcasting 4 live channels and one of them is a News network. The video uploaders are used to clipping the Noon News and upload them immediately without waiting for the internal workflow to provide the clips.
We tried Wowza but apart from this feature, with nginx-rtmp +ffmpeg we get a lot more flexibility (and reliability).
So we started by testing Jess’s approach to Live recordings and found a fundamental difference. It is designed for live events but not for a continuous stream.
So we proceeded this way:
- Instead of using the nginx-rtmp native live flv recording, we decided to record directly an mp4 source and make it available as a VOD entry.
- We added this exec line to the transcoding part of the live hls setting (it can also be done with an ffmpeg tee):
exec /usr/bin/ffmpeg -i rtmp://localhost:1935/$app/$name -g 60 -vprofile baseline -pix_fmt yuv420p -c:v libx264 -c:a aac -b:v 1600k -b:a 96k -vf “scale=1280x720” -tune zerolatency -preset veryfast -flags +global_header -f segment -segment_time 60 -segment_format_options movflags=+faststart -reset_timestamps 1 /opt/kaltura/web/content/recordedtmp/$name%d.mp4;
If any part of this line is wrong, please let me know. We cheated, of course !
With this, we record and segment the live stream into 1m mp4 segments, knowing that we can’t just use an mp4 file that doesn’t have the correct metadata (moov) to edit or play it.
- We setup a cron script that concats the last live segment to a temp mp4 and rewrites the entry source every minute. The recording is delayed but the actual file is a playable mp4.
This is what we have so far:
TOTAL=$(ls -1 $FILE*mp4 |wc -l)
TOPE=$(expr $TOTAL - 2)
if [ $TOTAL -eq 2 ]
cp “$FILE"0.mp4 “$DEST””$FILE".mp4
if [ $TOPE -ge 1 ]
echo “file '”$DEST$FILE".mp4’" > file1.lst
echo “file '”$TMPDIR$FILE$TOPE".mp4’" >> file1.lst
ffmpeg -f concat -safe 0 -i file1.lst -c copy “$DEST"temp.mp4
mv “$DEST"temp.mp4 “$DEST””$FILE”.mp4
This performs an old fashioned file count, finds the oldest-1 newsx.mp4 segment and appends it to the entry mp4 source file. We still need to perform some checks like validating that the stream is available and/or skip any discontinuities without overriding the current recording but it works so far.
- What I’m missing:
- Provisioning (via API) the VOD entry pointing to the news.mp4 source and make it available on the KMC.
- Calling the API for updating the mp4 Duration so it is consistent with the added chunk
We are woking on that and that’s we want to share. I have to say that the nginx-ffmpeg is a lot more reliable by far than the java solution. The tedious lip-sync problems that bothered us all the time have become very rare.
We are working on the last part and any ideas or comments will be appreciated.