Tests streams are served locally using Python HTTP server and ffmpeg for playlist generation.
Streams are served from the Streams
folder when running Scripts/test-streams-start.sh
.
Test streams are generated from local files using ffmpeg to address various use cases.
Local media files used for stream generation should have fixed closed GOPs so that HLS streams generated from them have segment durations hls_time
equal to a multiple of the GOP size.
Test streams should also be silent for convenience but stripping audio using ffmpeg -na
flag does not work with unit tests. For some reason AVPlayer
namely fails to move time forward with silent streams played in unit test suites, though such streams play fine in the simulator or on device. As a workaround we can reduce the volume of the audio to zero without stripping it, though.
With these constraints in mind we can use ffmpeg to prepare a local media file with fixed GOP size and a volume reduced to zero. Our current 4-second video source is created from the Nyan Cat video, downloaded using yt-dlp and cut into a nicely looping silent 4-second clip out with a GOP size of 2:
yt-dlp --format=mp4 -o nyan_cat_original.mp4 https://www.youtube.com/watch\?v\=QH2-TGUlwu4
ffmpeg -i nyan_cat_original.mp4 -ss 10 -t 4 -force_key_frames "expr:if(isnan(prev_forced_n),1,eq(n,prev_forced_n+2))" -filter:a "volume=0" nyan_cat.mp4
ffmpeg -stream_loop -1 -i source.[mp4|mov] -t 120 -vcodec copy -acodec copy -f hls -hls_time 4 -hls_list_size 0 master.m3u8
ffmpeg -stream_loop -1 -re -i source.[mp4|mov|...] -vcodec copy -acodec copy -f hls -hls_time 4 -hls_list_size 3 -hls_flags delete_segments master.m3u8
ffmpeg -stream_loop -1 -re -i source.[mp4|mov|...] -vcodec copy -acodec copy -f hls -hls_time 4 -hls_list_size 20 -hls_flags delete_segments master.m3u8
ffmpeg -stream_loop -1 -re -i source.[mp4|mov|...] -vcodec copy -acodec copy -f hls -hls_time 4 -hls_playlist_type event master.m3u8