How Video Streaming Works 00:00:01 A school play on a moving train Asha films the school play. On stage, a paper fox chases a red kite. At home the picture is sharp. On the train, Sam sees the same kite turn slightly fuzzy as the carriage enters a tunnel. The fox keeps running. How did the player change the picture without losing a single moment of the story? Asha recorded ten minutes at thirty frames a second. At full H D, a raw picture with three eight-bit color channels takes just over six million bytes. Multiply by eighteen thousand frames and you get roughly one hundred twelve billion bytes. The file from her phone is only four hundred million bytes. Follow the kite for two frames. An encoder can predict the new kite from a patch in the previous reconstructed picture, describe the motion, and encode the remaining difference. Quantization rounds some detail away. A keyframe supplies its own starting picture so the decoder can begin afresh. 00:01:01 Make four versions on one clock One encoded size would force a phone on a weak link to catch up with a television. Transcode the play at four video rates: point four, one point two, two point four, and four point eight megabits per second. All four versions must show the same stage action at the same presentation time. Here the encoder starts a closed group of pictures every two seconds. At thirty frames per second that is sixty frames. The packager cuts every four seconds, at shared independently decodable boundaries. Four seconds of any rendition covers the very same one hundred twenty pictures. Encoding workers can process pieces and renditions in parallel. Give every job its source range and rendition. If the middle-quality job for the second piece fails, retry that exact job, verify its timestamps and outputs, then publish the playlist. Publishing a link first lets the audience ask for a file that has not arrived. 00:01:59 Read actual playlists and land on a frame Watch our miniature stage clip become real segmented video. The upper playlist names the available renditions. A media playlist points to an initialization file carrying the decoder configuration, then names each media fragment and its duration. In the scrolling excerpt you can see a four-second entry followed by the actual fragment filename. Jump back to the ten-minute play. Sam drags the scrubber to five minutes and seven seconds. Call the first segment zero and keep the four-second boundaries. Which numbered segment should the player request, and at what time does that segment begin? Five minutes seven is three hundred seven seconds. Four fits seventy-six whole times. Segment seventy-six starts at three hundred four seconds. Our next keyframe is at three hundred six. Decode forward for one second, thirty frames, before displaying the target. An application using Media Source Extensions can append the appropriate initialization and media data to its source buffer. 00:03:02 Choose the next rendition The high rung carries four point eight megabits per second of video. Four seconds at that rate contains nineteen point two megabits. Suppose the train link now delivers one point six megabits per second. Ignoring overhead and audio, this one segment takes twelve seconds to download. The old speed estimate did not warn Sam about the tunnel. Sam has twenty seconds already buffered when the twelve-second download begins. Playback consumes that reserve in real time, and the new file contributes four more seconds only when it finishes. Will the fox freeze? How much playable time remains? Eight seconds remain just before the download completes. Add four, leaving twelve. No freeze. Now replay that download with only seven point three seconds buffered. This time the wait is four point seven seconds after the buffer empties. A large screen and a fast previous request cannot make up that missing time. Deeper in the tunnel, five seconds are ready and the link falls to half a megabit per second. Pick the lowest rung. Four seconds at point four megabits per second takes three point two seconds to arrive. Five minus three point two plus four leaves five point eight seconds. The image softens and playback continues. Climb back a rung at a time when measurements and buffer agree. 00:04:29 Share the premiere and measure the ending Three hundred parents each watch all one hundred fifty video segments. That makes forty-five thousand video requests. Suppose each of three regional caches serves three renditions, and each distinct file stays warm after one fetch. One hundred fifty times three is four hundred fifty cold files per edge. The three edges together send thirteen hundred fifty requests upstream. A shared shield keeps the same four hundred fifty distinct files. The origin therefore serves four hundred fifty segment fetches, one percent of viewer requests. If two parents ask for the same missing file simultaneously, request collapsing lets their edge wait for one fill. Check access before serving the cached bytes. Sam arrives at the finale. Measure the time to the first displayed frame, the duration of stalls, the delivered quality and playback errors. Each answers a different question. A streaming service makes a timed ladder, publishes aligned pieces, and shares them through caches. The player keeps choosing the next piece it can deliver before the audience runs out of story.