Infinite stream from a video file (in a loop)

Josef Zamrzla picture Josef Zamrzla · Jun 15, 2015 · Viewed 25.3k times · Source

Is there any way howto create an infinite h264 stream from a video file (eg. mp4, avi, ...). I'd like to use ffmpeg to transcode avi file to h264 but there's no loop option for output.

Answer

chovy picture chovy · Jul 25, 2016

You should be able to use the -stream_loop -1 flag before the input (-i):

ffmpeg -threads 2 -re -fflags +genpts -stream_loop -1 -i ./test.mp4 -c copy ./test.m3u8

The -fflags +genpts will regenerate the pts timestamps so it loops smoothly, otherwise the time sequence will be incorrect as it loops.