This is a quick tutorial for looping a VoD file as a live stream, using ffmpeg
.
In order to loop a video file, you need to convert it into the .ts
format. Use this command:
ffmpeg -i input.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts output.ts
In order to loop the video, you will need to run this ffmpeg command in a bash script. This command ensures the timestamp properly increments during looping. Be sure to put in your own stream key.
#!/bin/bash
function mixem {
while : ; do cat output.ts ; done
}
mixem | ffmpeg -f mpegts -re -i - -c:v h264 -b:v 2m -x264opts "keyint=50:min-keyint=50:no-scenecut" -c:a aac -preset veryfast -g 50 -map 0:v -map 0:a -f flv rtmp://rtmp.livepeer.com/live/{stream-key}
There are many tools available to concatinate multiple video files. One option is to use the follow commands:
cat input1.ts input2.ts input3.ts > all_input.ts
ffmpeg -i all_input.ts -vf scale=w=1280:h=720:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -b:a 128k -c:v h264 -profile:v main -crf 20 -g 50 -keyint_min 50 -sc_threshold 0 -b:v 2500k -maxrate 2675k -bufsize 3750k -f mpegts all_output.ts
These commands makes sure the files are merged with uniform settings like resolution, frame rate, etc. The output can be put into the looping script.