I am currently working on a web application that uses a video as the background for the landing page. The video itself is rather short at about 10 seconds, but that does not matter as the content has been edited to loop seamlessly. When I play the video in VLC, it is almost impossible to detect where the video restarts, unless I focus closely. I say this to assure you that the video itself is not the problem.
Instead, the problem arises when I convert the video into an HLS stream. I have tried various options and parameters, but the ones that have worked out the best so far are: ffmpeg -i video.mp4 -codec: copy -hls_time 1 -hls_list_size 0 -hls_segment_filename 'segment%1d.ts' -f hls stream.m3u8. The reason for why I cannot simply attach the video as a source in my application is because the file is somewhat large at about 15MB. I know that this is not great for mobile data and poor connections, but the client insisted that the quality cannot be compromised. This is where I had the idea of streaming the video in chunks, so that playback can occur as soon as the first chunk is received. The alternative would be to look at a poster image for quite a while before playback would occur. I am really happy with the implementation so far, however, there is this problem with the seamless loop.
Every time the video restarts, there is a minimal delay that is noticable enough to ruin the seamless loop. This was not an issue if I just attached the original video as the source, but when I play the stream, the delay is there.
Question: Is it possible to optimize the stream in way that reduces or perhaps even removes the delay?
I could perhaps provide a small demonstration of the problem if that is necessary, but that would involve some JavaScript code. I figured that the problem is not with the code, as I have tinkered with other HLS streams that I did not create myself, which could be looped seamlessly in the current application.
Update: After some more testing, I managed to reduce the delay slightly by adding -force_key_frames expr:'gte(t,n_forced*1)' to my initial command. It is still not perfect, but definitely better than before.