On average, YouTube streams 4 billion hours of video per month. That's a lot of video, but it's only a fraction of the larger online-streaming ecosystem. For video-streaming services, making sure clips always load properly is extremely challenging, and a new study reveals that it's important to video providers, too.

Maybe this has happened to you: You're showing a friend some hilarious video that you found online. And right before you get to the punch line, a little loading dial pops up in the middle of the screen.

Buffering kills comedic timing, and according to a study published by University of Massachusetts professor Ramesh Sitaraman, it kills attention spans, too

"What we found was that people are pretty patient for up to two seconds," Sitaraman says. "If you start out with, say, 100 users — if the video hasn't started in five seconds, about one-quarter of those viewers are gone, and if the video doesn't start in 10 seconds, almost half of those viewers are gone."

If a video doesn't load in time, people get frustrated and click away. This may not come as a shock, but until now it hadn't come as an empirically supported fact, either.

"This is really the first large-scale study of its kind that tries to relate video-streaming quality to viewer behavior," Sitaraman says.

The study looked at close to 6.7 million viewers who watched almost 23 million videos play. That's around 216 million minutes of video time.

The threshold of unbearable loading time depends on the device.

"We found that people who had a lot of connectivity had also a lot of expectation potentially, and so they abandoned much sooner," Sitaraman says.

For about half of the people who used a high-speed, fiber-optic connection, five seconds is too long. Mobile users will wait longer. For a business that serves an ad base of 800 million people a month, every second counts — the more users who click away, the bigger the problem.

"When we started to look into this problem, we found that the existing player we had was not up to the task," says Andy Berkheimer, an engineering manager for YouTube.

For the past two years, Berkheimer's team has been working on a project to make sure that those punch lines are delivered without the pauses.

"We had to rewrite our whole player to give us more flexibility in how we handled network conditions," Berkheimer says.

The problem, for YouTube and video providers alike it, has to do with bandwidth. Think of streaming video as being like a stream of liquid information. Bandwidth is the size of the pipe.

"No matter where you are, no matter what type of device you're using, no matter what type of network you're on — at any time while you're watching a video, bandwidth can change," Berkheimer says.

So if that bandwidth, or pipe, constricts too much, the video stops playing. To solve this problem, YouTube's engineers chop the video into a bunch of tiny pieces. From moment to moment, depending on how much bandwidth is available, they swap these pieces in and out as the video streams.

If there's a ton of bandwidth, a high-definition piece flows down the pipe. But if that pipe constricts, even for a second, a lower-quality piece is swapped in.

Switching around different versions of video shortens load time, Berkheimer says. And less load time means more video, more eyeballs and more money for ads. But what's the cost?

Some films aren't always seen in their best light. Filmmaker Gregory Wilson used state-of-the-art camera equipment to film a cheetah running full speed in superslow motion. HD captures every stunning detail of the cat's fluid motion. But when you watch his video online, who knows how it will look?

"I would hope that the quality could be the best that it could be and that it would be more on par with what I had originally captured," Wilson says.

Since businesses need that video to run no matter what it looks like, the rest of us will likely see grainy cheetahs rather than stuttering punch lines.

Copyright NPR 2020.