Zibbp / ganymede

Twitch VOD and Live Stream archiving platform. Includes a rendered and real-time chat for each archive.
https://github.com/Zibbp/ganymede
GNU General Public License v3.0
457 stars 24 forks source link

The screen flickers during live recordings #252

Closed TheFrodo closed 1 year ago

TheFrodo commented 1 year ago

Hello all,

I have installed Ganymede on my new server and made it available to the public. Now I have the problem that during the livestreams that are recorded directly, the video flickers. This is not the case with the archived videos.

I also have a Youtube video here where I recorded the whole thing: https://youtu.be/985RdzinQzQ

Here is the link to the video at the Ganymede instance: https://vodarchiv.net/vods/ca4d81ed-20d9-11ee-aef4-0242ac130004

it is a bit strange. I had changed the server to have more storage space but somehow it does not cope with the live recordings.

Zibbp commented 1 year ago

I see the flickering in the video but when I go to watch the Video on your instance I do not get any flickering at all. Do you see flickering if you try a different browser, or a different device? If you have Nvidia GSYNC enabled, that could be causing the flickering but not entirely sure.

TheFrodo commented 1 year ago

So for me and my friends it's the same with Chrome, OperaGX. The problem does not occur with Edge & Firefox. Nvidia GSync is also not activated.

Zibbp commented 1 year ago

I tried with Chrome and also get the issue. I downloaded the HLS playlist and used ffmpeg to reconstruct the mp4 and that played without any flickering so it must be something with how the HLS playlist is being generated. Off the top of my head it could be keyframe issues as the video is not being re-encoded, rather copied to save time/processing power. I'm assuming this is happening because of the ads during a livestream. The ads that are shown have different audio sample rates and now I guess something with the video differs as well. From my previous encounters with this, only specific ads cause this issue which makes recreating the issue difficult.

While I do some more debugging, I would disable converting the video to HLS for now. This will unfortunately increase initial load times of playback but at least it's not flickering. As for your existing archives, you can try converting them back to MP4 and seeing if it still flickers.

ffmpeg -i https://cdn.vodarchiv.net/vods/thefrodode/2023-07-12-39756784485-ca4d81ed-20d9-11ee-aef4-0242ac130004/39756784485-video_hls/39756784485-video.m3u8 -c:a copy -c:v copy out.mp4

The MP4 can then be re-encoded which will properly set the keyframes. This will take some CPU power as it's re-encoding the video.

ffmpeg -i out.mp4 -c:a copy -force_key_frames 'expr:gte(t,n_forced*10)' -sc_threshold 0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls out.m3u8

I may look into supporting one of the many proxy servers which proxies the HLS playlist from Twitch through a country that doesn't have active ad campaigns. Ultimately the HLS conversion step will probably need the above re-encoding to properly fix it.

TheFrodo commented 1 year ago

Okey, I have now disabled HLS and will keep you posted if this happens again.

TheFrodo commented 1 year ago

Hey,

I tried this again and the flickering is gone with disabling HLS. i will leave HLS disabled then.

Zibbp commented 1 year ago

Good to hear that the flickering is gone without using HLS. I'm working on adding proxy support which I believe would fix the flickering issue as the proxy would serve an ad-free stream. https://github.com/Zibbp/ganymede/pull/253. The only other fix I can think of is a complete re-render of the video which is slow.