1 second stream latency is possible on Twitch. My mind is officially blown. Mixer may be gone,
but that doesn't mean low-latency streaming had to go away with it.
I'm EposVox, the Stream Professor, and today we're looking at some new findings
from Xaymar - the gentleman behind the StreamFX plugin and who has taken my
core VMAF testing concept and completely enhanced and automated the workflow for
video quality comparisons and so on - which we will hear more from soon.
I love having someone like Xaymar in my circle, because he has the workflow and the time to dive
into the deeper details of video encoding that I don't always have time for, and recently he's
stumbled into a discovery that's been under our noses the entire time.
Reducing latency, or lag or delay, of your stream getting from your streaming program
to Twitch has been a desire of many streamers. The disconnect of a streamer
trying to interact with chat, but on a 5 to 30 second delay can be super frustrating.
Mixer, Microsoft's acquired streaming platform and attempt at competing with Twitch utilized a
different streaming protocol called FTL - or Faster Than Light - which had near
sub-second latency and was honestly a wild experience to interact so quickly with chat
to where often questions felt like they were being answered as soon as
you hit the enter key. This was appealing to a lot of streamers.
Well, good news, it turns out that just by setting your KeyFrame Interval
to a second and a half - instead of the recommended 2 second interval - you can
potentially reach 1 second latency, as well! But it's not perfect.
What even is a "Keyframe interval"? Glad you asked!
No.. no, Ryan in the back, I know YOU didn't specifically ask...
that's not the point- You know what? Just get out of my classroom. Just go.
Keyframes in video encoding are actually called "i-frames" or "intra-frames" - that is to say,
a single frame in the video that contains the complete image. So if you had a completely raw,
uncompressed video feed and took a screenshot from it - like in JPG or BMP image formats. This
contains all of the information for the frame at that exact moment in time. These can help,
or hurt, video encoding algorithms as they serve as reference points to build the rest
of the frames, which typically contain only parts of the data that have changed from that keyframe.
Now, you can record completely i-frame based videos in many cameras, or even in your video
encoding settings with a keyframe interval of 1, and playing these back or scrubbing through
these clips on a video editing timeline is super smooth because there's no real
interpretation to be done. It's just an image sequence at that point.
The downside is that these are much harder to compress,
since they are the entire frame's worth of information,
rather than only the changes. The more information you have, the harder compression is.
These differ from P- and B-frames, as B-frames are "inter frames". B-frames,
which you have a setting for with the NVENC H264 encoder, save space by using
the differences between the current frame and the previous frame to determine its content.
Going back to Twitch specifically, the usual recommended setting for Keyframe Interval is
2 seconds. That means every other second, or once every 60 frames in a 30FPS stream or every
120 frames in a 60FPS stream, there will be a keyframe to build the rest of the frames from.
This seems to be a balancing act of both encoding performance and quality
within a limited bitrate - Twitch is notorious for their very restrictive
bitrates - and decoding performance for Twitch's side of the stream handling.
The more keyframes you have, the more information your video COULD contain,
but the harder (and slower) the encoding process will be. So if you're doing a mostly uncompressed
video feed, more keyframes is better. But if you're doing a very compressed video feed,
say streaming to Twitch for example, more is worse because they're harder to compress
compared to P- and B-frames, worsening quality and taking longer to encode.
Well, Xaymar was hunting around for encode settings that had an impact on
the latency between his stream and Twitch and found that... most settings had none.
Even setting NVENC to the Low-Latency or Zero-Latency mode - which people often
foolishly recommend for this despite me saying otherwise many times - had no impact here.
The one setting that made all the difference was the KeyFrame Interval. Setting it to 1 was
not useful, as the latency was still around 2.4 seconds for some reason,
but he tried a fractional latency - something only supported in X264 and his StreamFX plugin's
NVENC encoder and BAM, about 1 seconds of latency from his PC to Twitch. Which,
combined with the processing delays on his PC and etc. realistically ended up closer to 2 seconds.
I was able to re-create this and wanted to share my config, as it's
damn impressive. Let's talk about the exact setup after a word from this video's sponsor.
The EVGA XR1 brings quality audio and ease of routing to your game streams. Featuring a high
quality headphone amp, party chat capture, easy volume mixing right on the card, 4k passthrough
and uncompressed 1080p 60FPS capture - get your stream started today, fast and easy with the EVGA
XR1 capture card. Use affiliate code EPOSVOX at checkout to get up to 10% off at the link below.
First and foremost you do, of course, need to enable "Low
Latency" in Twitch's Dashboard and make sure it's enabled for your video player.
Next is to go to your output settings in OBS. This does need to be in Advanced mode. Not all
streaming software will let you control this granularly, we're focusing on OBS Studio here.
Let's cover both NVENC and X264 settings to make this happen. First,
if you're using NVENC you'll need to use the NVENC encoder provided by Xaymar's StreamFX plugin,
not the one that ships with OBS. Xaymar's provides way more options,
though it can be overwhelming to dig through. Here's the settings I used and he recommends,
but obviously adjust your bitrates according to what you usually stream at.
The important number here is the "Key Frames" section, setting Interval
Type to Seconds and Interval to "1.50 seconds."
If you're using X264, you can't actually manually type in a fractional keyframe interval,
so set it to 1, and then go down to the custom X264 arguments section and
type in "keyint=90" if you're streaming 60fps, or "keyint=45" for 30fps.
Again, it's 1.5 seconds, so 1.5 times your framerate.
Bam! Using R1ch's Twitch Test and choosing the lowest latency server to me I was able
to re-create this myself on my test account, though I did have to toggle "Low Latency"
on and off in the Twitch player preview sometimes to get it to grab the faster feed.
You will have some variance on this based on your routing from your ISP to Twitch,
the usage level of the Twitch ingest server you're using, and etc. so it won't work perfectly for
everyone - but this seems to be the best way to reduce your latency to Twitch while having
no significant impact on video quality or anything like that.
Did this work for you? Comment below. Hit the like button and subscribe for more tech
education. Join us on Discord to chat about this
or other streaming topics. I'm EposVox and I'll see you next time.