Finding the perfect recipe for quality in your live stream can be tricky. There are many ways to manipulate your settings in Wirecast to help boost or lower quality in order to take full advantage of your upload speeds, but even these can prove to be tricky as well. One variable in particular can take you one step closer to finding that perfect balance of quality and data usage: Key Framing
What are Key Frames?
Key frames at their most basic level are single frames within video that provide a reference point, similar to mile markers on a freeway. These special frames serve many purposes in video animation, non-linear editing, and in our case, video compression. In animation, key frames mark points at the beginning and end of a single animation, whereas in editing, they are used as markers for certain editing actions like volume changes. Key frames in video compression, though, are arguably more complicated.
In order to understand how a key frame helps to encode video, let’s first do a quick overview of the encoding process. Live HD video is too data intensive to be quickly and smoothly transferred over most networks, so Wirecast has built in encoding processes that allow the stream to be compressed to a more manageable size. In order to do this, the encoder will only store data that is seeing significant change frame by frame. For example, in a talking head video like you see here:
The only change to the video over the course of a 30 minute stream will be the movement of my mouth and a couple side by side movements of my head. Half of the shot is the background, which is static for the entire stream. Wirecast can recognize the difference between the static background and more dynamic foreground and will store only the data corresponding to the changes that occur frame by frame. This allows Wirecast to focus its energy on half of the video stream, allowing for a smaller file size.
Key frames are used to mark the basis for detecting these changes. Depending on where I put my key frames, Wirecast will use those specific frames as a starting point for encoding video in the least resource intensive manner, leading to a smaller and more manageable stream
How Can it Help?
Now that the concept is clear, how can we start to implement the practice? By setting a key frame rate. Similar to setting the frame rate of the video itself, we can set a key frame rate that will create a key frame every “x” frames. Remember, a key frame rate is different than the key frame itself. A high key frame rate actually means less key frames, as it refers to the interval between each one. The larger number used for the key frame rate results in more time between key frames.
Depending on the amount of movement you expect in your video, you can adjust the rate up or down. If you have very little movement, like the piano player to the left, you can get away with a longer interval between key frames, meaning a high key frame rate is possible. Conversely, if you are streaming something incredibly dynamic like the soccer/football game below, it is better to have a shorter interval between key frames in order to capture the constant movement, therefore necessitating a lower key frame rate.
While it is easy to boost or lower your key frame rate to match your subject matter, we still have bandwidth limitations to worry about. In sports, a low key frame rate (many key frames) is nice, but also very data intensive. Because we are creating numerous full data frames to base our movement off of, the overall stream size is increased. Make sure you spend some time exploring the best ratio of quality to resource usage in order to stay within the parameters set by your bandwidth.
How Can I Manipulate my Key Frames in Wirecast?
Adding key frames in Wirecast is simple. In the “Window” menu tab, open “Encoder Presets.” As long as you are using a h.264 or x264 encoder, which comprise a majority of the encoder options, there will be a box to add your key frame rate. Start with a low frame rate for video with constant movement, and see how high you can get it with more static video. There are no concrete guidelines to apply to your settings, so make adjustments as you see necessary. After a few tries, an adjusted key frame rate will help to keep your video quality high, while lowering the required bandwidth needed for a flawless stream.
An excellent reminder, thank you. While key framing may seem a little obvious, I admit I’m a little “set it and forget it” in my approach to broadcasting with Wirecast. Perhaps this is a testament to the quality of your software since it “just works.”
This blog post prompts me though, I should review my key frame settings again. If I can decrease CPU usage, reduce output filesize / stream size while maintaining a high level of quality, I’m very happy.
In our webcast studio, we indeed have a very static backdrop (it’s a muslin after all), so I’m going to review our settings and see what it does to our quality vs. resource usage ratios.
So now his leads us to a feature request – make it so a keyframe is not just captured at intervals, but that one is also captured every time a new shot is clicked. This would help avoid artifacting if we switch to a completely different scene and would improve shot transitions where the entire frame is replaced with a different scene.
Robbie Ferguson, Host
Category5 Techology TV
Good luck with your experiments! I hope it leads to some more manageable stream sizes. Let us know how it goes!
Can you give some concrete examples of how fiddling with key frame intervals can improve quality?
I mean, if I shoot talking heads and encode with H.264, 2 Mbps, 720p, 25 fps, 50 frames between key frames, what does this result in compared to the same settings but 200 frames between key frames?
Theoretically, it should decrease the overall data that needs to be streamed. By taking a key frame every 200 frames instead of 50 you are storing less information, meaning there is less data that needs to be transmitted. This should work just fine for a talking head video in particular, because there most likely is very small level of variance in the shot.
Keep in mind, though, no matter how much thought goes into it, the best way to see the effects of changing the key frame interval is through testing. Fiddle with the key frame interval, and see how it affects your stream size and quality.
“Theoretically, it should decrease the overall data that needs to be streamed.”
That theory doesn’t quite make sense, as regardless of key frame interval, Wirecast will always target a predefined average bit rate. In both cases we have chosen to stream in 2000 kbits/s, and increasing or decreasing the number of key frames is not going to change that.
Instead I would imagine that less keyframes would result in a greater share of the predefined bitrate dedicated for non-keyframes, which could – if motion is limited – result in better overall quality.