<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stefan Kaiser on Medium]]></title>
        <description><![CDATA[Stories by Stefan Kaiser on Medium]]></description>
        <link>https://medium.com/@stefan-kaiser?source=rss-a33a202d746a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*L6sOMMTQuTGAXhIghPL7LA.jpeg</url>
            <title>Stories by Stefan Kaiser on Medium</title>
            <link>https://medium.com/@stefan-kaiser?source=rss-a33a202d746a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 22:23:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stefan-kaiser/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SSAI as an encoding challenge?]]></title>
            <link>https://medium.com/zattoo_tech/ssai-as-an-encoding-challenge-cdcb980e2b29?source=rss-a33a202d746a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdcb980e2b29</guid>
            <category><![CDATA[ott]]></category>
            <category><![CDATA[server-side-ad-insertion]]></category>
            <category><![CDATA[dynamic-ad-insertion]]></category>
            <category><![CDATA[live-streaming]]></category>
            <category><![CDATA[video-encoding]]></category>
            <dc:creator><![CDATA[Stefan Kaiser]]></dc:creator>
            <pubDate>Fri, 13 Feb 2026 13:58:49 GMT</pubDate>
            <atom:updated>2026-02-13T13:58:49.196Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Learnings from 10 years SSAI on live linear signals.</strong></h4><p>No matter wether you work at a broadcaster, a streaming service, or an ad tech company, wether you’ve ever dealt with Server-Side Ad Insertion (SSAI) on live linear signals, you know that everyone makes it sound easy. Replace some content, make money, done. But after 10 years of running SSAI in production at Zattoo (being a OTT distributor of live broadcast TV content), one thing is clear: the devil is in the details, and some of those details are actually encoding challenges. Here’s the story:</p><p><strong>Once upon a time…</strong></p><p>Back in 2016, walking around at IBC, every second booth was talking about SSAI on live linear signals. The idea was simple: substitute the linear ad break with unique-per-user ads. Finally fully personalized commercial breaks in broadcast content. In the US, some companies were already deploying that to some degree. At IBC, you could only find good demos. But when you asked around, no one seemed to really run it in production, in front of actual users.</p><p>But it is the easiest thing ever:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ZMj1EG8hT2pwxyMR0mphQ.png" /><figcaption>Figure 1: Linear signal with SCTE-35 markers</figcaption></figure><p>Step 1: You get your linear signal, and it contains SCTE-35 markers pointing to the exact frames where the ad break starts and the original content begins again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pqLUEkTpYNVS8a92h-vEuA.png" /><figcaption>Figure 2: Personalized ad replacement per user</figcaption></figure><p>Step 2: When creating a stream for a specific user, you fetch some ads and replace the old ad break with new, personalized ads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*hRayxs5k1deboVWVnuVgrQ.png" /></figure><p>Step 3: Money for everyone!</p><p>So let’s do it!</p><h4><strong>The protocol zoo</strong></h4><p>As we are still in 2016, let’s quickly revisit how the technical OTT landscape looked like for streaming protocols:</p><pre>+ - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - +<br>| Protocol          | Platforms                                 | Format  |<br>+ - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - +<br>| HLS               | Apple devices, some Smart TVs             | MPEG-TS |<br>| DASH              | Web platforms, gaining on Android         | fMP4    |<br>| HDS               | Flash Player (yes, still around in 2016)  | fMP4    |<br>| Smooth Streaming  | Xbox, Windows Apps, Smart TV (for DRM)    | fMP4    |<br>+ - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - +</pre><p>So there was a bit of a zoo of devices and protocols to support if you wanted to cover all your users. Additionally on the HLS part, there were new versions coming up regularly, that we had to support in parallel to continue serving legacy platforms in addition to introducing new features. There was a time with three HLS versions to be operated in parallel, v3 (legacy), v5 (Fairplay) and v7 (fMP4 fragments).</p><h4>Let’s talk about “the other” SSAI</h4><p>When we started thinking about doing ads with streaming in general, client-side ad insertion was of course an option and in place for pre-roll ads. But doing it on client-side for ad break substitution as well would mean implementation effort on all the different applications. Additionally, it would not be frame-accurate, which wasn’t acceptable in a linear TV experience that tries to convince users that OTT streaming is a proper alternative to traditional DVB broadcast TV.</p><p>On the server-side, there were two approaches flying around: <em>Manifest Manipulation</em> and <em>Fragment Stitching</em>.</p><p>Manifest manipulation sounded promising. You splice your content on a timeline, separate the ad break from the rest of the content, and then exchange the content period of ads with personalized ads. But when we looked at the player landscape in 2016, we saw a different picture. Support for it only existed on some MSE (W3C Media Source Extension) players, which left out the majority of our revenue potential (basically all native apps). Nowadays this is practically the default way of doing SSAI.</p><p>But times were different back then, so we had a closer look at a fragment stitching approach.</p><h4>The implementation details</h4><p>We already had on-the-fly packaging in place, which we did directly on the edge nodes. This brought us to the idea that we could also substitute the content on the edge nodes before we created our streaming fragments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cAzOVwwVxsSTCoYK0vJULQ.png" /><figcaption>Figure 3: High-level Fragment stitching architecture</figcaption></figure><p>The architecture we ended up: The Transcoder produces the encoded content. On the Edge Node, the Provider component fetches from upstream Transcoder and content arrives in an intermediate MKV format. Provider also contains all the stitching logic. It knows about SCTE-35 markers, which ad to substitute at which time for each specific request. And we actually did this frame by frame, replacing one frame of content with exactly one frame of new ads. The Packager then takes this merged fragment and packages it into whatever streaming format the client needs (HLS, DASH, Smooth Streaming, etc.). The beauty of this approach is that both the Packager and the Player are completely SSAI-agnostic.</p><p>But was it really that easy? Of course not.</p><h3>Learning 1: The SCTE-35 marker myth</h3><p>Everyone loves SCTE-35 markers! They point exactly to the first frame of the ad break, right?</p><p>We thought so too. Until we started to run our solution with the first broadcasters. Somehow it was stitching content a bit too early, or a bit too late. The first thought was of course: where is the bug in our stitching solution? But after looking at it for a while, we accepted that it was totally free of bugs ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TbXSMQzsozG8Ty0rIMfwxA.png" /><figcaption>Figure 4: SCTE-35 markers that point to an early frame</figcaption></figure><p>So we checked the incoming signal again in order to verify the markers themselves, which is a really tedious act:</p><ul><li>Recording a snippet of live source content where we expect the presence of a marker</li><li>Searching for markers and storing them somewhere</li><li>Parsing SCTE-35 to figure out the PTS that it is signalling</li><li>Rendering the frame at that PTS to verify if it’s the correct one (first of ad break or first of content after ad break)</li></ul><p>We had to introduce an easier solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ehexws_7e2BpmvZQNfPYHQ.png" /><figcaption>Figure 5: Visual marker</figcaption></figure><p>On the ingest side we extended our encoder options. When configuring to scan for SCTE markers, we added a flag that will add a visual marker directly on the frame that is signalled in SCTE-35. We used a small red square on the top left corner. The person configuring the ingest for a channel could then easily verify if we are off from the intended ad break start.</p><p>After confirming that the marker is already off in the source signal, we could either solve it by talking to the broadcaster to let them fix it. Or we were lucky and it’s a static offset for all markers. Then we could configure an offset in the marker processing to correct it.</p><p>The truth is, we have only seen one, exactly one, broadcaster so far that really delivered exact markers. So it’s a general issue that lies somewhere in the production and tooling pipelines of broadcasters, between scheduling systems and encoders, between SCTE-104 and SCTE-35. The SCTE-35 standard being “exact” is more of a theoretical promise than a practical reality.</p><h3>Learning 2: The decoder artefact problem</h3><p>We are at a point where we merged the fragments properly and also the markers are working now. Now we can see the ad break is starting with personalized ads and playing well. As a user we are very drawn to what we see and immediately want to buy whatever is advertised to us.</p><p>Then the ad break ends. We switch back into the original live linear content and get… decoder artefacts.</p><p>That’s a clear case for everyone, I guess?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1N29ctEUSEE4VgqBjbwlA.png" /><figcaption>Figure 6: GOP structure and decoder error</figcaption></figure><p>Let me walk you through what’s happening here. In the diagram, you can see the frame sequence: the Content GOP2 (starting with an I-frame, continuing with P and B frames), then AD GOP101 starting with an I-frame, followed by its P and B frames. AD GOP102 also starts cleanly with an I-frame. But look at what happens when we cut back to the live content, it resumes at a P-frame. There’s no previous-frame reference for the decoder to work with.</p><p>The decoder sees this P-frame and tries to reconstruct it based on a reference frame it never received. The result in practice: this shows up as visual artefacts and blocky corruption until the next keyframe arrives.</p><p>What can we do here? We don’t know when the ad break will end for a specific user on the ingest side. Every user might have a different ad break length depending on ad sales, availability and targeting of ads on the ad server. We can’t just add one keyframe at a point derived from the SCTE marker into the content during the initial encoding step.</p><p>To our advantage, we didn’t only have on-the-fly packaging in place; we also had on-the-fly transcoding. So we extended the on-the-fly transcoder API with a keyframe PTS parameter to inject a keyframe exactly where needed for each user’s stream.</p><p>You might wonder if that added load to our transcoder pool? Yes, it did.</p><p>It didn’t really overload from the keyframe injection, but we saw an impact, of course. We have multiple caching layers in this whole on-the-fly packager/transcoder architecture. So we tried to minimize the impact by adding the keyframe PTS to the various cache keys.</p><p>While investigating the keyframe issue, we found another issue that was causing additional transcoder load. As we piped all the ads through our VOD encoding pipeline, they were naturally encoded with the VOD profile, which comes with a lower frame rate, typically 24fps or 25fps, while our live profiles target 50fps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CKqOZXo6bKSNB74Xg0_SGw.png" /><figcaption>Figure 7: Mismatch in profiles of live vs. ads caused transcoder load</figcaption></figure><p>The diagram shows what happens: Live content at 50fps flows through the transcoder pool cleanly. But ad content at 25fps with a VOD profile? It needs to be re-encoded from 25fps to 50fps to match the live stream, causing again some extra load on the transcoder pool. As our transcoders implicitly did the conversion on every request, it worked well from the beginning. It only showed up as an issue, when looking at the transcoder load in detail.</p><p>The fix was easy enough: we tweaked the ingest path for ad assets to use the live encoding profiles from the start, so they match the frame rate and encoding parameters of the live content. No more re-encoding at stitching time due to that.</p><h3>Learning 3: The neglected friend strikes again</h3><p>In video streaming, we often care a lot about video. But as I mentioned in my previous article about <a href="https://medium.com/zattoo_tech/the-definitive-guide-for-picking-a-fragment-length-617f75b9ccf3">picking the right fragment length</a>, let’s not forget about audio. And here we are again, audio is attracting attention :)</p><h4><strong>Chapter 1: Silence</strong></h4><p>When everything worked on the video side, we let it run for a bit and monitored how it was going. But then we got user complaints: no audio during the ad break. We tried to reproduce it, but everything was fine. As an engineer you try to test “efficiently”, quickly grabbing Chrome on a random debug player you have at hand. But everything works, sound is coming out also during the ad break.</p><p>Digging deeper, we figured out that this was happening on channels that came with an E-AC3 5.1 track, which users could choose instead of stereo. The diagram shows the problem clearly: Main content audio has six channels (Front L, Front R, Center, LFE, Surround L, Surround R), but the ad audio? Stereo only — just Left and Right.<br>This was not reproducible on Chrome, as there is no 5.1 support available. Our tests always defaulted to the Stereo track.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EPS7B8gdFfv7NOOHfz1_sw.gif" /><figcaption>Figure 8: Audio channel mismatch between content and ads</figcaption></figure><p>Advertisers don’t produce too much surround sound these days. So there was suddenly no audio content during the ad break — the 5.1 track simply didn’t exist in the ad. Which led our stitching implementation to, more or less silently, add silence on the 5.1 track.</p><p>Stereo-only ad breaks are a normal thing, but with an SSAI solution that only kicks in after the initial encode, you skip all existing measures to deal with it. So again, we had to touch our ingest pipeline to enforce an upmix from stereo to 5.1 for all ads in order to continue audio during the stitched ad breaks.</p><h4><strong>Chapter 2: Loudness</strong></h4><p>After no audio at all, yet another problem occurred: Too much audio!</p><p>Advertisement has the annoying habit of being too loud too often. The visualization shows it: the linear stream has a normal loudness level, but the moment an ad starts — the levels spike way above normal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gv4SFxUjswl-oJalM91-XA.png" /><figcaption>Figure 9: Loudness spikes during ad breaks</figcaption></figure><p>Merging it into the linear stream was creating peaks in loudness for the user. So we thought, let’s apply loudness normalization, as we do for the linear signals. How does it look now?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gq3fMZ8kVSIhhfF3xa1ijg.png" /><figcaption>Figure 10: Loudness normalization with spike zone in the beginning</figcaption></figure><p>Almost. There is just a small problem with small files like ads, being only 20 or 30 seconds long. The loudness normalizer needs a bit of buffer for its loudnorm logic to be effective. FFmpeg officially needs 300ms, but practically still takes a few seconds to stabilize.</p><p>You can see in the diagram what happens: even with normalization applied, there’s a “spike zone” of about 2–3 seconds at the start of the ad where the loudness is still elevated. The normalizer needs time to analyze the incoming audio and settle into its target level. For a 30-second ad that often starts with sound immediately, giving the first 2–3 seconds to a loudness spike is noticeable. And if it happens with every ad during the ad break, it’s annoying!</p><p>To fix that, we touched our ad ingest pipeline yet another time. We duplicated some audio content and prepended it at the beginning of the input buffer to give the normalizer time to settle. Then we read the normalized audio content only after the duplicated part. A bit of a hack, but it works.</p><p>Finally, we can start montetizing now!</p><h3>Would we build it the same way today?</h3><p>It’s now 2026 — ten years since we started this journey. Would we build it the same way today?</p><p>There is still a certain beauty in doing a fragment stitching approach. It works across all our streaming protocols, doesn’t require client-side changes, and handles the edge cases we’ve discovered over the years. No ad blocker is able to differentiate ads from original content. The fragment stitching approach even has proven to be robust and scalable for us.</p><p>But manifest manipulation has matured since 2016, most players are supporting multi-period DASH, and there is now agreement in the industry as to how to create manifests for it. Scalability with manifest manipulation is definitely higher, as we move the stitching burden from the “heavy” part of stitching fragments to a “lightweight” part of stitching manifest files. Still there is some need for custom-length fragments to start and end different content periods. Additionally we could even extend our use cases of SSAI to cover classic client-side ad insertion cases like pre-rolls for live content as well as pre/mid/post rolls for non-linear/VOD content.</p><p><strong>The encoding challenges I’ve described?</strong><br>They’re not specific to our approach. Independent of whether you do manifest manipulation or fragment stitching, you’ll run into the same issues:</p><ul><li>SCTE-35 markers are rarely frame-accurate in practice: build tooling to verify and compensate.</li><li>Keyframe injection is needed when cutting back to live content: your architecture needs to support this. For manifest manipulation this means creating custom-length fragments to have a new fragment starting with a keyframe at that point.</li><li>Encoding profiles must match between ads and live content to avoid potential side effects on the client side, we can’t control the decoder!</li><li>Audio channel configurations must be consistent, plan for upmixing stereo to 5.1.</li><li>Loudness normalization requires special handling for short-form content — the normalizer needs time to settle.</li></ul><h4>Take away?</h4><p>What else to take away from this post? It turned out that SSAI has a huge impact on the encoding pipeline. But of course there is much more to it than the encoding aspects, something for a future blog post. If you’re just starting out: don’t trust those SCTE-35 markers. Build the red square.</p><p>Other than that, let’s raise a glass:</p><blockquote>Happy 10th anniversary to Zattoo SSAI 🎉</blockquote><p>A technology formerly known as DAI / Dynamic Ad Insertion, more recently known as DAS / Dynamic Ad Substition, industry also calls it SSAI / Server-side Ad Insertion. Pick your battles :)</p><h4>Acknowledgement</h4><p>This blog post was inspired by my tech talk at the Montevideo Tech Day 2026, which was part of the <a href="https://montevideotech.dev/about-summer-week/">Montevideo Summer Week</a> organised by Qualabs. <a href="https://medium.com/u/b5e682ecc1fe">Juan Pablo Saibene</a> was asking me to talk about something in the area of Encoding, which sparked my idea of talking about the encoding challenges in SSAI, which are typically not emphasised widely. Thanks for the opportunity to do this talk! I don’t want to leave anyone without this nice view over Montevideo while watching a tech talk, great place :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VsJos8oe2tyc6gcPuK6_GQ.png" /><figcaption>Montevideo Tech Days 2026</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdcb980e2b29" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zattoo_tech/ssai-as-an-encoding-challenge-cdcb980e2b29">SSAI as an encoding challenge?</a> was originally published in <a href="https://medium.com/zattoo_tech">Zattoo’s Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Smart Buffering — and the two types of player configurations]]></title>
            <link>https://medium.com/zattoo_tech/smart-buffering-and-the-two-types-of-player-configurations-9cb052d34828?source=rss-a33a202d746a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cb052d34828</guid>
            <category><![CDATA[low-latency]]></category>
            <category><![CDATA[ott]]></category>
            <category><![CDATA[buffer]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[playback]]></category>
            <dc:creator><![CDATA[Stefan Kaiser]]></dc:creator>
            <pubDate>Thu, 24 Jun 2021 11:37:32 GMT</pubDate>
            <atom:updated>2021-06-24T11:37:32.974Z</atom:updated>
            <content:encoded><![CDATA[<h3>Smart Buffering — and the two types of player configurations</h3><p>The term end-to-end latency already implies that there is not just one end when it comes to latency reduction. In fact, low latency always comes with two sides being involved. There is of course the server-side, which was discussed in <a href="https://medium.com/zattoo_tech/how-to-go-low-latency-without-special-tricks-37c69db027bb">the previous blog post</a>. But to leverage the full potential of low latency, while still keeping a stable playback, you need to understand the playback side and also tweak it accordingly.<br>Our way of doing low latency was by reducing the fragment length. After doing the server-side change, we also looked at the impact on the client-side. This revealed two categories of players; more precisely two categories of player configurations. Depending on the type of player configuration we had to do different adjustments to maintain lower the latency.<br>But lowering the latency at the cost of the player buffer always comes with a trade-off on stable playback. So we thought about that situation and came up with what we call Smart Buffering to overcome this.</p><h3>Two types of player configurations</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62J-uvyUf2SNTV9aQo7GyQ.jpeg" /></figure><p>You wouldn’t think that there are fundamental differences in a player configuration for adaptive streaming. Especially if you are only changing something on the server-side, would you expect a huge difference in the playback behaviour between player A and player B if you didn’t touch the player configuration at all?<br>Well, you will definitely learn that this is happening if you change the fragment length significantly. In our case, some players suddenly operated on buffer levels that were less than half of the size than before the server-side change —our overall strategy for latency reduction likes that, but our aim for stable playback doesn’t like that this happened “uncontrolled”, without us explicitly reducing the buffer size.</p><p>Before going deeper, let’s quickly define what we consider as “the buffer” in the following article. With the player buffer, we mean the forward buffer, which is the amount of media a player is supposed to keep in a ready-to-play state while playing a stream. We don’t talk about the stream startup buffer, which is typically lower than the forward buffer and can be defined independently on some players.</p><h4>Player configuration with number of fragments</h4><p>The first type of player configuration is specifying the buffer level with a number of fragments. If your fragment length is changing, this will directly impact your buffer levels.</p><p>Let’s put down a quick example of specifying player buffers with number of fragments:</p><pre>+-------------------------------+--------------+<br>| Forward buffer configuration: |  <strong>3 <em>fragments</em></strong> |<br>| Fragment length:              |  4 seconds   |<br>| <strong>Effective buffer</strong>:             |  <strong>12 seconds</strong>  |<br>+-------------------------------+--------------+</pre><p>What happens after changing the fragment size to e.g. 1.6 seconds?</p><pre>+-------------------------------+--------------+<br>| Forward buffer configuration: |  <strong>3 <em>fragments</em></strong> |<br>| Fragment length:              |  1.6 seconds |<br>| <strong>Effective buffer</strong>:             |  <strong>4.8 seconds</strong> |<br>+-------------------------------+--------------+</pre><blockquote>Wondering where the 1.6 seconds come from? Please follow up on another recent blog post, <a href="https://medium.com/zattoo_tech/the-definitive-guide-for-picking-a-fragment-length-617f75b9ccf3">Definitive guide for picking a fragment length</a>.</blockquote><p>This reduces your buffer by more than half! And you didn’t even change something on the client-side.</p><h4>Player configuration with seconds</h4><p>The second type of player configuration is, in contrast to the first one, expecting seconds in the configuration. It’s pretty clear what happens, but for the sake of completeness let’s write it down as well.</p><p>Example of specifying player buffers with seconds:</p><pre>+-------------------------------+--------------+<br>| Forward buffer configuration: |  <strong>12 <em>seconds</em></strong>  |<br>| Fragment length:              |  4 seconds   |<br>| <strong>Effective buffer</strong>:             |  <strong>12 seconds</strong>  |<br>+-------------------------------+--------------+</pre><p>Let’s change the fragment length again to 1.6 seconds:</p><pre>+-------------------------------+--------------+<br>| Forward buffer configuration: |  <strong>12 <em>seconds</em></strong>  |<br>| Fragment length:              |  1.6 seconds |<br>| <strong>Effective buffer</strong>:             |  <strong>12 seconds</strong>  |<br>+-------------------------------+--------------+</pre><p>Effectively, nothing happened.</p><p>There we are with two significantly different effects on our latency goal. With the first configuration type, buffer in number of fragments, we are already on low latency on both sides, server-side and client-side. The client-side latency reduction here comes with a somewhat uncontrolled client-side buffer reduction if you are not fully aware of the configuration type of your players. If you want to take it step-by-step, you need to change the player configuration before doing the server-side change. But sometimes that’s not even possible, for example on AVPlayer where the buffering behaviour is part of the protocol specification and black box player implementation.</p><p>With the second type, buffer in seconds, we still have high client-side latency. To reduce the client-side latency for the second type we need to update the player configuration for all affected clients.</p><p>To know which clients are falling in which category, let’s have a look at what we know from the platforms we support at Zattoo:</p><pre>+--------------------------------+--------------------------+<br>| Buffer in number of fragments  | Buffer in seconds        |<br>+--------------------------------+--------------------------+<br>| AVPlayer                       | Exoplayer                |<br>| (iOS, tvOS)                    | (Android, FireTV)        |<br>|                                |                          |<br>| STB ABox42                     | Bitmovin Web             |<br>|                                | (Web Browser: Chrome /   |<br>| Bitmovin Web (Safari)          | Firefox / Edge, Samsung  |<br>|                                | Tizen, LG)               |<br>|                                |                          |<br>|                                | Microsoft                |<br>|                                |                          |<br>|                                | Chromecast               |<br>|                                |                          |<br>|                                | Panasonic                |<br>|                                |                          |<br>+--------------------------------+--------------------------+</pre><p>Now we know the different categories of player configurations. We also know what impact a server-side change could have on each platform. And we get the feeling that there needs to be a proper strategy to balance the player difference with a mode that aims for low latency but sets the buffer to a value that still assures stable playback. The open question now is: what is the right buffer value?</p><h3>Choosing the right buffer value</h3><h4>Three’s a party?</h4><p>We need to come up with some number for the buffer settings that will make us happy on the latency part, but also on the part of the stable playback. A classic rule of thumb is that a buffer level of three times the fragment length is typically a good choice — there it is: The recommended buffer configuration with number of fragments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PdLfH0ukss65XtLAm3ul9A.jpeg" /></figure><p>With that, we are actually on a good track with the players that work with this type of configuration. If the configuration specified seconds, we are rather overcommitting on the stability after changing the fragment length from 4 seconds to 1.6 seconds. As mentioned before, to achieve low latency, this leads us to needed changes on the client-side.</p><h4>But is it that simple?</h4><p>Our goal might be low latency, but this should not be achieved at the cost of playback stability! By reducing the fragment length from 4 seconds to 1.6 seconds, we would reduce the buffer size from 12 seconds to 4.8 seconds.<br>Before the change, we could, theoretically, cover network outages of almost 12 seconds, while keeping the playback running. Now it’s only 4.8 seconds. Full network outages are of course the extreme case, but make it clear that the time to react to network conditions is drastically decreased. Even in case you are operating in a managed network environment, there will always be users that experience network drops and bandwidth limitations. To not expose those users to playback issues due to our low buffer settings, we thought about a way of dynamically changing the buffer settings. That’s what we call Smart Buffering.</p><h3>Smart Buffering</h3><p>At Zattoo we are operating a Live TV streaming service, where users are typically zapping around to find content. People stick to content while it’s on, but they can also very quickly switch between channels (e.g. during an ad break). The focus of low latency, and the tuned buffer configurations that come with it, is on live content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q-d2Ty8aHQe1EP_aKUMjLQ.jpeg" /></figure><p>To avoid playback issues due to low buffer settings, we want to be able to dynamically change the buffer configuration for a user. Due to the nature of our expected user behaviour on live content, we assume that new streams are being requested rather frequently. This allows us to keep the granularity of changing the buffer config on the level of stream requests, without the need of changing the configuration while playing content. This scope limitation significantly reduces the amount of work needed on the one side, on the other side it avoids running into technical limitations, as some players will not even support on-the-fly configuration changes out of the box.</p><h4>Data needed to make smart decisions</h4><p>There is basically one playback metric that is ubiquitous when it comes to playback stability. Of course, it’s the BUFFERING event. This event is, for the user, more annoying than a quality switch or longer startup time. It’s also highly related to the buffer setting of the player, and is the ultimate metric you look at if you want to make playback more stable in case of varying network conditions.</p><p>That’s the reason we chose the BUFFERING event to be the main lever for triggering buffer configuration changes. We implemented a set of playback telemetry events that can be accessed by the player itself to make smarter decisions.</p><h4>When to change the buffer?</h4><p>Excellent question! The general assumption is that the user has good network conditions — which means, we are starting with a buffer configuration that is appropriate for low latency streaming. In our case, that is three times our current fragment length of 1.6 seconds = 4.8 seconds. We don’t go lower as this will satisfy our primary latency goal already.</p><p>But even with the three fragment lengths, we know that we will have more users with playback issues than before, where the buffer was more than twice the amount in seconds. As mentioned, we can change the buffer configuration on each stream start. Also, we know about BUFFERING events that are happening for each user.</p><p>With that knowledge we introduced three buckets of buffer configuration that reflect the buffer values over different time spans:</p><ul><li>Last playback — the buffer value used for the last stream configuration</li><li>Current user session — the average of all buffer values during the current user session</li><li>Global user device — the average of all buffer values that a user started on this device</li></ul><p>Those three buckets can be put into an algorithm to decide the recommended buffer value for the upcoming stream start. Of course, each bucket can be weighted differently.</p><p>In addition to the buffer recommendation based on past knowledge, the decision algorithm takes into account the knowledge about BUFFERING events that happened during the last playback. The simplest way to incorporate this would be:</p><ul><li>Increase buffer value, if there was at least one BUFFERING event in the last playback session</li><li>Decrease buffer value, if there was no BUFFERING event in the last playback session</li></ul><p>This will make playback more stable if it turns out that the initial low latency setting is too aggressive for the user’s playback conditions.<br>If the buffer value was already increased before, this way will also try to reduce it again once we reached a stable playback — intending to get the least latency while keeping playback stable. Due to the weighted algorithm of past buffer values, this buffer selection logic will stabilise itself over time to a value that works well for the user.</p><h3>Summary</h3><p>We identified two different types of player configurations and discussed how they react in case the fragment length changes. Our overall goal was to reduce the end-to-end latency for live TV streaming on our service. With this article, we showed what’s needed on the client-side to achieve that, and proposed a simple Smart Buffering logic that helps to reduce the latency while keeping playback stable.</p><p>This is the third part of a blog article trilogy that covers all aspects of our journey to low latency streaming.<br>The first part is about choosing a fragment size as the fragment size plays a crucial role in our low latency attempts: <a href="https://medium.com/zattoo_tech/the-definitive-guide-for-picking-a-fragment-length-617f75b9ccf3">The definitive guide for picking a fragment length</a>.<br>The second part describes our general concept for reducing the latency of live streams and goes into detail on the server-side changes we did, as well as how end-to-end latency can be measured in an OTT streaming service: <a href="https://medium.com/zattoo_tech/how-to-go-low-latency-without-special-tricks-37c69db027bb">How to go low latency, without special tricks</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cb052d34828" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zattoo_tech/smart-buffering-and-the-two-types-of-player-configurations-9cb052d34828">Smart Buffering — and the two types of player configurations</a> was originally published in <a href="https://medium.com/zattoo_tech">Zattoo’s Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to go low latency, without special tricks]]></title>
            <link>https://medium.com/zattoo_tech/how-to-go-low-latency-without-special-tricks-37c69db027bb?source=rss-a33a202d746a------2</link>
            <guid isPermaLink="false">https://medium.com/p/37c69db027bb</guid>
            <category><![CDATA[ott]]></category>
            <category><![CDATA[mpeg-dash]]></category>
            <category><![CDATA[hls]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[low-latency]]></category>
            <dc:creator><![CDATA[Stefan Kaiser]]></dc:creator>
            <pubDate>Wed, 23 Jun 2021 10:17:16 GMT</pubDate>
            <atom:updated>2021-06-24T18:15:02.470Z</atom:updated>
            <content:encoded><![CDATA[<p>Every two years it’s hitting video streaming services in Europe — and for other occasions even yearly worldwide. Either the FIFA World Cup or the UEFA European Championship is coming up. This makes companies like Zattoo think about their end-to-end latency every once in a while. And this time we tackled it. Let’s talk about what needs to be done to lower the latency and how we did it without any special tricks — fully compatible to legacy devices and without losses in scalability by keeping our cacheable streaming architecture in place.</p><h4>What’s the problem?</h4><p>Every time, both media and users are questioning how far away from “live” they are when watching a stream. They are wondering if they will be alerted about a goal by screaming neighbours, a dozen push notifications, or by actually seeing the goal on their own screen.</p><p>We all know satellite TV; it’s the benchmark as it is available almost everywhere. Even if you need specific hardware to access the content aired on SAT, it’s the most common way to watch TV.<br>But there is also the Internet. And now everyone has some device that can access the Internet. The majority of the content that is defining Internet traffic is video, not only due to its size but also its importance. And then there is TV streaming being the big alternative to satellite TV.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zsvw_wpkBWoB5qaO8AVoQ.jpeg" /></figure><p>With the TV signal from the satellite, your satellite dish will catch a broadcasted TV signal and your satellite receiver will immediately decode it to display the images on your TV screen. This comes with a slight delay, technically about a quarter of a second for the transmission to/from the satellite. Additionally, there is a negligible delay in the transmission between the receiver and your TV. But there is a further delay in your TV’s decoder to wait for the next incoming keyframe that contains the first full picture to show and also some content buffering. In total this typically ends up with a couple of seconds to what is happening live.</p><p>On the other hand, TV streaming is being transmitted over HTTP nowadays, like any other website. This assumes the availability of the content on a web server. In turn, this means that there is a pre-processing happening on the server-side to make this content available. This pre-processing is similar to what the TV does with the broadcast signal. Actually, the source of most TV streams is in fact a satellite signal, which makes SAT the main reference for comparing latency. Additionally to the decoding part, pre-processing is also encoding the content again into a format that is formatted for being shared via an HTTP streaming protocol. Once the content is available, this content needs to be fetched by a streaming client, which could be a TV again, or any other Internet-connected device in this case. And there we are with the decoder step again, but due to the nature of HTTP, the delay introduced here is typically much longer than for the case of broadcast signals. Without any low latency advances, you end up with a delay of around 30 seconds or more for TV streaming.</p><h4>What is end-to-end delay in streaming?</h4><blockquote><strong>End-to-end latency:</strong> The timespan between the moment one frame was received at the server-side and the moment the same frame is displayed to the user with the player in state playing.</blockquote><p>The processing of a signal to be streamed via HTTP contains multiple steps, each introducing some amount of delay. Our idea of end-to-end latency considers the beginning of the latency of a specific frame as the time when we first receive this frame. The contribution source of TV signals varies depending on the broadcaster and the technical availability of signals. Some signals can be received via IP multicast, potentially being the source with the least contribution latency. But many signals still come only via satellite, the same way in which they would reach the end-user as well. In the worst case, a TV signal is made available via HTTP streaming and has a huge delay on its way for contribution already.</p><p>The situation that TV streams are technically delayed to broadcast signals is a well-known topic. This is not only concerning pure TV streaming services, but also the broadcasters themselves. Typically a broadcaster has an online offer in addition to its broadcast product. With that, the broadcaster is competing with its own product portfolio and running into the same competitive disadvantages on the streaming part. In the German broadcast/streaming market, we recently saw developments of broadcasters that probably delay their TV signal on the play-out to different contribution paths. This would allow them to align the delays of Internet streaming and satellite signal reception.</p><figure><img alt="Steps covered in the measurement of end-to-end latency for live TV streaming." src="https://cdn-images-1.medium.com/max/678/1*UqDTGjcGviOsnJXEm_IxbQ.png" /><figcaption>Steps covered in the measurement of end-to-end latency for live TV streaming</figcaption></figure><p>No matter what the source of the signal is, our measurement for end-to-end latency considers the time a frame arrives at our server. We are processing the frame, encoding it, potentially transcoding it, packaging it into some streaming format, and make it available on the CDN. From that point on this frame can be fetched by a client and put into the player buffer. Depending on the buffer configuration this introduces more or less additional delay. Once the player displays the frame we are measuring and is also in state <em>playing</em>, we take this as the other end of our latency measurement.</p><h4>Technical implementation of end-to-end delay measurement</h4><p>We are talking about low latency and how to reduce it. This only makes sense if you also measure it! We thought about the technical possibilities to automatically measure end-to-end latency and came up with a solution that works across most of our platforms.</p><p>There are two main streaming formats we currently support as state of the art: MPEG-DASH and HLS in version 7. This results in fragments being served in ISO-BMFF format.<br>Of course, there are multiple (more or less) legacy formats we also support, but it’s always about catching the majority. And the majority is updating their apps and uses modern devices.</p><p>In the ISO 23009 (Amendment 1) we have a great extension to the ISO-BMFF specification, which is this awesome ‘<strong>emsg</strong>’ atom that allows you to specify payload that should be emitted as an event on a specific media time.<br>In this article, we always talked about specific frames of which we want to track the end-to-end latency. To simplify the implementation we reduce this to the first frame of each fragment. This keeps a significant granularity to detect changes, but also doesn’t overload the metadata for the purpose of latency measurement.<br>Glueing that together we have an event on every first frame of a fragment that tells us the current time of this frame on this device. The payload of the event contains server-side data about the timings this fragment was encoded and packaged. Together with a quick clock-drift estimation to adjust the client-side timings we have all data available to report as latency measurement telemetry regularly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ygyaFCQgly7NxFJl40H4og.jpeg" /></figure><p>This allows us to automatically track latency across many devices and also reveals interesting insights into the differences of various platform-player architectures. But for our topic of reducing the end-to-end latency, this builds the major benchmark and foundation to progress further with the actual changes to reduce the latency.</p><h4>What do we want to achieve?</h4><p>We are users as well. And of course, we use TV streaming to watch the UEFA European Championship, so our goal from the user’s perspective is simple:</p><blockquote>We want to reduce the end-to-end delay for the user to such a low value that the user experience in case of live events can not be disturbed by external influences.</blockquote><h3>Possibilities for low latency streaming?</h3><p>Our streaming infrastructure serves HTTP streaming formats like MPEG-DASH, HLS, or Smooth Streaming. We even serve HLS in three different protocol versions (v1, v5, v7). It is built explicitly for live streaming and performs at scale by leveraging multiple caching layers. With this bouquet of streaming protocols, we reach every device on the market, legacy or cutting edge. Typically you don’t change a working streaming architecture completely for a single reason, even if it is low latency streaming. That means we want to consider all possibilities carefully and check each pro and con for feasibility and also have an eye on potential reach.<br>So, what are technologies that could be used for low latency streaming?</p><ul><li>Exposing MPEG-TS via HTTP</li><li>RTMP</li><li>LL-HLS / LL-CMAF</li><li>Plain DASH / HLS (currently in use)</li></ul><p>MPEG-TS via HTTP Chunked Transfer Encoding. This is actually possible, but you will have a very limited number of clients supporting this. Without special hacks, that will probably be limited to Android. That doesn’t help us much with our current player ecosystem, which is much bigger. The main objection, however, is the fact that this is not scalable like typical HTTP streaming.</p><p>RTMP. Yeah, back to the 2000s. Flash is dead, isn’t it? As huge as its usage was 15 years ago (<a href="https://www.youtube.com/watch?v=5Rv50RCwqo8&amp;ab_channel=Demuxed">interesting talk</a> from one of the creators), it’s currently a contribution format rather than a distribution format. Limited client-side support nowadays in addition to the fact that it’s also not scalable makes it also drop from the list.</p><p>LL-HLS / Chunked CMAF. We were talking about the fact that we currently use HLS and DASH, so LL-HLS and Chunked CMAF doesn’t seem to be far off what we want. That’s true. But what does it mean to move from plain HLS to LL-HLS? On the one side, we need a client that supports this new format, the same for Chunked CMAF. That’s even possible for LL-HLS to find; for Chunked CMAF it’s getting more tricky. Widespread and stable client-side support for that is still not in a state I see being present. Then there’s the server-side; both variants assume that we can announce the availability of fractions of the content, even before the full fragment is finished. Unfortunately, this doesn’t work out with our architecture without a major rework as we rely on the presence of full fragments to be picked up by on-the-fly transcoding and packaging processes. With those arguments, we also realised that LL-HLS and LL-CMAF is not a viable option for us at the moment.</p><p>All of that makes one thing clear: We want to reuse our current streaming infrastructure as it is already scalable and has the reach we need. Also, it is significantly backwards compatible. So what can be done with plain DASH and HLS to reduce the latency significantly?</p><h4>Latency reduction with plain DASH and HLS</h4><p>Looks like no tech could help us out on its own. So we stick with plain HTTP streaming —but what can we do with that to lower the latency anyway?</p><p>There is one question unanswered so far: where does our current latency come from exactly?<br>We measured end-to-end latency to get the full picture. But we also added some steps in between to find indications. Additionally, we analysed our architecture in detail to find the spots where delays are introduced. In the end, we could pinpoint the introduction of most delays to be tightly coupled to the fragment length. Most delays are introduced because we finish, store, process, prefetch or buffer a specific number of fragments. Even the obvious categorisation of dividing the end-to-end delay into server-side and client-side leads to correlations with the fragment length for each case.</p><p>For the server-side path, we consider everything from the initial encoding to potential transcoding and packaging and making it available for client requests. The client-side in the player is basically buffering and loading/starting the stream. Our fragment length has been four seconds since forever. A rough calculation would lead us to the following numbers:</p><pre>+-----------------+--------------+----------------+<br>| Fragment length |           4 seconds           |<br>+-----------------+--------------+----------------+<br>| Encoding delay  |  4 fragments |  16 seconds    |<br>| Random spread   |  0-3 seconds |  0-3 seconds   |<br>| Player buffer   |  3 fragments |  12 seconds    |<br>| <strong>Total</strong>           |              |  <strong>28-31 seconds</strong> |<br>+-----------------+--------------+----------------+</pre><p>With that, we were wondering how far we could get down by just reducing the fragment length. Actually changing the fragment length was one of the things we had in our backlog for a while, as the current value of four seconds is not optimal, <a href="https://medium.com/zattoo_tech/the-definitive-guide-for-picking-a-fragment-length-617f75b9ccf3">the reasons are explained in a previous blog post</a>. In that post, we also identified a set of different fragment lengths that are valid for all types of content. The lowest reasonable fragment length from that investigation is 1.6 seconds. So, let’s have a look what the impact of only changing this parameter would be:</p><pre>+-----------------+------------------+----------------------+<br>| Fragment length |              1.6 seconds                |<br>+-----------------+------------------+----------------------+<br>| Encoding delay  |  4 fragments     |  6.4 seconds         |<br>| Random spread   |  0 - 1.6 seconds |  0 - 1.6 seconds     |<br>| Player buffer   |  3 fragments     |  4.8 seconds         |<br>| <strong>Total</strong>           |                  |  <strong>11.4 - 12.8 seconds</strong> |<br>+-----------------+------------------+----------------------+</pre><p>During the process of analysing our ingest architecture, we found a few additional spots that we could tweak to reduce the end-to-end latency by refactoring our codebase. Basically, those things are related to buffering settings of the ingest signal that were set higher than needed. In the end, this can lead to another two fragment length of latency reduction:</p><pre>+-----------------+------------------+----------------------+<br>| Fragment length |              1.6 seconds                |<br>+-----------------+------------------+----------------------+<br>| Encoding delay  |  2 fragments     |  3.2 seconds         |<br>| Random spread   |  0 - 1.6 seconds |  0 - 1.6 seconds     |<br>| Player buffer   |  3 fragments     |  4.8 seconds         |<br>| <strong>Total</strong>           |                  |  <strong>8 - 9,6 seconds</strong> |<br>+-----------------+------------------+----------------------+</pre><p>Here we are! 10 seconds end-to-end latency with plain DASH and HLS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fffAjoAqCKHw6YgzznljKQ.jpeg" /></figure><h4>Side effects</h4><p>Besides the latency reduction, we also see two side effects from our change to a fragment length of 1.6 seconds.</p><p>As elaborated in detail in our article about fragment lengths, we had a rather bad choice with a fragment length of 4 seconds. In fact, we ended up having a different fragment length for video and audio for DASH. This was 4 seconds for video and 3.2 seconds for audio to match exact frame numbers and block sizes per fragment. The consolidation to 1.6 seconds for everything also makes life easier from the perspective of handling code fragmentation now.</p><p>The player will most likely also honour the smaller fragment length with a smaller stream start-up time. The threshold to start playback is typically not the same value that is configured as the target playback buffer; it’s actually much lower. Let’s run through an example where we have a player buffer configuration of 12 seconds. The start-up buffer in this example is just 2 seconds. In the case of 4-second fragment lengths, this will lead to requesting 4 seconds of content. In the case of 1.6-second fragment lengths, this will lead to requesting 3.2 seconds of content which should, in turn, be downloaded and displayed faster.</p><h3>Follow up</h3><p>With that being said, even though we are not using any special cutting-edge technology or inefficient protocols, this effort was still massive. It was impacting the full chain from ingesting, over encoding, transcoding, packaging, to playback on all major devices. The playback part also has a significant take on latency reduction and comes with its own challenges. Those are described in an upcoming article: <a href="https://medium.com/zattoo_tech/smart-buffering-and-the-two-types-of-player-configurations-9cb052d34828">Smart Buffering — and the two types of player configurations.</a></p><p>This is the second part of a blog article trilogy that covers all aspects of our journey to low latency streaming.<br>The first part is about choosing a fragment size as the fragment size plays a crucial role in our low latency attempts: <a href="https://medium.com/zattoo_tech/the-definitive-guide-for-picking-a-fragment-length-617f75b9ccf3">The definitive guide for picking a fragment length</a>.<br>The third part deals with the client-side changes needed when approaching low latency streaming: <a href="https://medium.com/zattoo_tech/smart-buffering-and-the-two-types-of-player-configurations-9cb052d34828">Smart Buffering — and the two types of player configurations.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37c69db027bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zattoo_tech/how-to-go-low-latency-without-special-tricks-37c69db027bb">How to go low latency, without special tricks</a> was originally published in <a href="https://medium.com/zattoo_tech">Zattoo’s Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The definitive guide for picking a fragment length]]></title>
            <link>https://medium.com/zattoo_tech/the-definitive-guide-for-picking-a-fragment-length-617f75b9ccf3?source=rss-a33a202d746a------2</link>
            <guid isPermaLink="false">https://medium.com/p/617f75b9ccf3</guid>
            <category><![CDATA[low-latency]]></category>
            <category><![CDATA[mpeg-dash]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[ott]]></category>
            <category><![CDATA[hls]]></category>
            <dc:creator><![CDATA[Stefan Kaiser]]></dc:creator>
            <pubDate>Tue, 22 Jun 2021 16:13:07 GMT</pubDate>
            <atom:updated>2021-06-24T18:17:04.206Z</atom:updated>
            <content:encoded><![CDATA[<p>No matter if you are using MPEG-DASH, HLS, Smooth Streaming, or CMAF, if you are just beginning to learn about streaming or working for a company that is pushing a single-digit percentage of overall internet traffic to users across the world, there is one thing that will haunt you for the duration of your journey in video tech.</p><blockquote>The Fragment Length</blockquote><p>Yes, it’s that small detail that will be the first question you have about when you run an FFmpeg command to generate a MPEG-DASH stream out of your MP4.</p><p>If you are aiming for a streaming protocol like HLS (Apple) or Smooth Streaming (Microsoft), you might have read their recommendations on the fragment length. Those two protocols are driven by a single company, which is also giving out proposed values to use:</p><ul><li>HLS currently recommends 6-second fragments [1] (by the way <a href="https://medium.com/u/2c1727d2d4a2">Stefan Lederer</a>, 10 seconds are outdated in [2])</li><li>Smooth Streaming’s default is 2 seconds</li></ul><p>They both have the same goal but are recommending a significantly different value here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fk0eMIfwQzJ3TOAimXWQ-Q.jpeg" /></figure><h3>Short vs. Long</h3><p>There are also a few articles around that talk about different fragment sizes and their impact.</p><p>The executive summary on what the Internet (e.g. [2, 3, 4]) says about pro arguments for the different fragment categories is:</p><p>Short fragments:</p><ul><li>faster adaptation / prevent stalls</li><li>lower latency</li><li>faster encoding</li></ul><p>Long fragments:</p><ul><li>fewer files</li><li>smaller playlist size</li><li>better encoding efficiency/quality</li></ul><p>How serious are those arguments?</p><p>Of course: it depends. It depends completely on your encoding and streaming infrastructure and your use case.</p><p>As this post is coming out of Zattoo, let’s assume we are building a live TV streaming service. Additionally, let’s assume we have on-the-fly transcoding and on-the-fly packaging in place:</p><ul><li>Faster adaptation is key in a live streaming scenario where you don’t have the possibility to buffer huge amounts of media in advance.</li><li>Lower latency gets a significantly higher weight as well due to the live streaming situation.</li><li>Faster encoding is something that we also like for live encoding as we need to meet a real-time constraint.</li><li>In our case, we can skip “fewer files”. There are of course still more files to some degree, but our storage architecture is built to serve exactly that purpose.</li><li>For playlists, gzip compression can be used, so you don’t need to care too much about the playlist size anymore. There is also a good mechanism in DASH with template URLs to avoid bloated playlists. For HLS there is also something useful available since the rather new version 10, called HLS Playlist Delta Updates.</li><li>For live streaming, the goal of encoding is not better encoding efficiency anymore; it’s faster encoding speed to meet the real-time constraint in the first line. From that on you can add up encoding efficiency.</li></ul><p>Seeing this, it looks like we should go for the category of short fragments for the Zattoo live streaming case.<br>On the other hand, if you want to go purely VOD, the result may differ. Maybe you want to avoid building and maintaining an on-the-fly transcoding/packaging infrastructure and rather go for a pre-encoded bitrate ladder. This could easily turn your choice into longer fragments being the better fit.</p><p>After all, we end up with many pros for short fragments, but basically still need to evaluate one specific counterargument: lower latency vs. encoding quality. More on that later on in this article.</p><p>Why encoding quality is impacted by the fragment size is described well enough in [2] and [3]. In short: The need for a more dense keyframe interval steals bitrate from the temporal prediction (B-/P-frame) and with that lowers the overall quality.</p><p>The counterpart is your encoding latency. You need to encode the full fragment (be it, for example, 2 or 6 seconds) until you can expose it. In case you are streaming live content, this means that the fragment length directly impacts your latency.</p><p>But there are also already solutions to solve the encoding latency problem. Chunked CMAF and Low-Latency HLS are aiming to help out. Both protocols allow exposing parts of the fragment before it was fully finished by the encoder. But on the player side, you still need a keyframe to start playback, so stream startup time will depend on your keyframe cadence, and your latency on the length of the fragment parts exposed.</p><h3>Valid fragment lengths</h3><p>The generic decision on the length category of a fragment is only one part of the journey to pick the right fragment length. Another important step is to find the exact fragment length that is valid in all circumstances for your content. Some pitfalls need to be avoided.</p><p>At Zattoo we used to run streams with a fragment length of 4 seconds. Company history says this was due to the protocol recommendation of the first streaming protocol we used: HTTP Dynamic Streaming (HDS) for the Flash player. And it stuck even after introducing HLS in version 1, Smooth Streaming, MPEG-DASH, HLS in version 5, and also during the latest addition; another HLS variant, version 7.</p><p>With those 4 second fragments, we eventually ran into issues. Issues that are not related to latency or encoding quality. We faced A/V sync issues on some devices — and we knew the reason.</p><h4>Video</h4><p>With a fragment length you want to cover a specific amount of time, and in the streaming protocol specification you typically see references to video GOP sizes. This might be a rather easy pick if you only have video with a single frame rate, but that’s typically not the reality. As a live TV service, you potentially want to serve streams with 50 frames per second (fps) in your highest quality levels, but lower-quality levels might be 25 fps only. In our case, we even go lower than 25 for a few very low-resolution quality levels and provide them with 12.5 fps or 5 fps.</p><p>That looks good considering our 4 seconds fragment length, we have an even number of frames to put into one fragment:</p><pre>+------+------------------------+<br>|      |  fragment length in ms |<br>| FPS  |                   4000 |<br>+------+------------------------+<br>|   50 |                    200 |<br>|   25 |                    100 |<br>| 12.5 |                     50 |<br>|    5 |                     20 |<br>+------+------------------------+</pre><p>The way of using 50/25 frames is a European thing, leading back to the PAL TV standard. What about going abroad and taking the US market into account, while still maintaining your existing infrastructure? NTSC is your history pal. The exact frame rate would be 60000/1001 and 30000/1001 if you follow the traditional standard. But to simplify your life as an OTT operator, you might want to tweak your HTTP streams to be delivered with more even frame rate numbers. In our case we ended up with 60/30 fps for the US case. Also we added low frame rate qualities to the bouquet again, explicitly 15 fps and 5 fps.</p><pre>+------+------------------------+<br>|      |  fragment length in ms |<br>| FPS  |                   4000 |<br>+------+------------------------+<br>|   60 |                    240 |<br>|   30 |                    120 |<br>|   15 |                     60 |<br>|    5 |                     20 |<br>+------+------------------------+</pre><h4>Audio</h4><p>Okay, that also works. So what’s the problem we were talking about?<br>It’s the neglected friend of the video streaming scene: <strong>Audio</strong>!<br>The classic audio codec in streaming media is typically AAC in 48 kHz with a block size of 1024 samples.</p><pre>+-----------------+------------------------+<br>| codec /         |  fragment length in ms |<br>| block size      |                   4000 |<br>+-----------------+------------------------+<br>| AAC / 1024      |                  187.5 |<br>+-----------------+------------------------+</pre><p>There it is. The 0.5 that makes the difference. You end up with an uneven number of audio fragments per 4-second fragment. With that, you need to place 187 audio samples in even fragment numbers, and 188 audio samples in odd fragment numbers. This flapping audio sample will potentially blow your manifests/playlists and distract the players. In a better case, it’s hidden in a manifest that is not exactly accurate, but most likely works. But if it doesn’t work, you might run into A/V sync issues as your player is not recognizing this correctly. Before that, you already ran into a server-side effort of flapping the number of audio samples between odd and even fragment numbers.</p><p>The fun thing is, there is not only AAC around; there are more audio codecs with different block sizes. In our case we also need to deal with Dolby Digital Plus / E-AC-3:</p><pre>+-----------------+------------------------+<br>| codec /         |  fragment length in ms |<br>| block size      |                   4000 |<br>+-----------------+------------------------+<br>| E-AC3 / 1536    |                    125 |<br>+-----------------+------------------------+</pre><p>Luckily in the case of 4 seconds, this is not causing extra trouble. Still, we know that 4 seconds is not the perfect match for us and we need to find a proper fragment length.</p><h4>Finding the sweet spot</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wQkcVRQT_etccONwGxarWQ.jpeg" /></figure><p>Thinking about fragment lengths and what’s recommended on the Internet, we see values between 1 and 10 seconds. Let’s put all of those into one table to compare by calculating the numbers with the various frame rates and sample sizes we discussed so far. We see that there is basically one match that fits all with a fragment length of 8 seconds.</p><pre>+------------+---------+-------+---------+-------+---------+<br>| FPS or     |                       fragment length in ms |<br>| block size |    1000 |  2000 |    3000 |  4000 |    5000 |<br>+------------+---------+-------+---------+-------+---------+<br>| video:                                                   |<br>| 50         |      50 |   100 |     150 |   200 |     250 |<br>| 25         |      25 |    50 |      75 |   100 |     125 |<br>| 12.5       |    12.5 |    25 |    37.5 |    50 |    62.5 |<br>| 5          |       5 |    10 |      15 |    20 |      25 |<br>| 60         |      60 |   120 |     180 |   240 |     300 |<br>| 30         |      30 |    60 |      90 |   120 |     150 |<br>| 15         |      15 |    30 |      45 |    60 |      75 |<br>| 5          |       5 |    10 |      15 |    20 |      25 |<br>| audio:                                                   |<br>| 1024       |  46.875 | 93.75 | 140.625 | 187.5 | 234.375 |<br>| 1536       |   31.25 |  62.5 |   93.75 |   125 |  156.25 |<br>+------------+---------+-------+---------+-------+---------+</pre><pre>+------------+--------+---------+-------+---------+--------+<br>| FPS or                             fragment length in ms |<br>| block size |   6000 |    7000 |  <strong>8000</strong> |    9000 |  10000 |<br>+------------+--------+---------+-------+---------+--------+<br>| video:                                                   |<br>| 50         |    300 |     350 |   <strong>400</strong> |     450 |    500 |<br>| 25         |    150 |     175 |   <strong>200</strong> |     225 |    250 |<br>| 12.5       |     75 |    87.5 |   <strong>100</strong> |   112.5 |    125 |<br>| 5          |     30 |      35 |    <strong>40</strong> |      45 |     50 |<br>| 60         |    360 |     420 |   <strong>480</strong> |     540 |    600 |<br>| 30         |    180 |     210 |   <strong>240</strong> |     270 |    300 |<br>| 15         |     90 |     105 |   <strong>120</strong> |     135 |    150 |<br>| 5          |     30 |      35 |    <strong>40</strong> |      45 |     50 |<br>| audio:                                                   |<br>| 1024       | 281.25 | 328.125 |   <strong>375</strong> | 421.875 | 468.75 |<br>| 1536       |  187.5 |  218.75 |   <strong>250</strong> |  281.25 |  312.5 |<br>+------------+--------+---------+-------+---------+--------+</pre><p>That means, 8 seconds would be the clear winner. The comparison also shows that typical recommendations of 2 or 6 seconds are not resulting in valid numbers for common types of content!</p><p>But we also wanted to go for a short fragment length, and 8 seconds definitely counts into the longer category. So what’s the actual common denominator? 8 seconds? 800 milliseconds? Let’s put it on the table again, and maybe try also 1600 milliseconds while we’re at it ;)</p><pre>+------------+--------+---------+-------+<br>| FPS or          fragment length in ms |<br>| block size |    800 |    <strong>1600</strong> |  <strong>8000</strong> |<br>+------------+--------+---------+-------+<br>| video:                                |<br>| 50         |     40 |      <strong>80</strong> |   <strong>400</strong> |<br>| 25         |     20 |      <strong>40</strong> |   <strong>200</strong> |<br>| 12.5       |     10 |      <strong>20</strong> |   <strong>100</strong> |<br>| 5          |      4 |       <strong>8</strong> |    <strong>40</strong> |<br>| 60         |     48 |      <strong>96</strong> |   <strong>480</strong> |<br>| 30         |     24 |      <strong>48</strong> |   <strong>240</strong> |<br>| 15         |     12 |      <strong>24</strong> |   <strong>120</strong> |<br>| 5          |      4 |       <strong>8</strong> |    <strong>40</strong> |<br>| audio:                                |<br>| 1024       |   37,5 |      <strong>75</strong> |   <strong>375</strong> |<br>| 1536       |     25 |      <strong>50</strong> |   <strong>250</strong> |<br>+------------+--------+---------+-------+</pre><p>Turns out that it’s not 800 but 1600 milliseconds which makes the common denominator for the content specs we aim for ( EU/US frame rates + AAC/E-AC-3 audio). This exercise didn’t lead to a single perfect value for a fragment length, but it led to a set of possible fragment lengths that you can choose from, depending on your use case. You can choose between the shorter and longer fragments to balance the trade-off between latency, quality, and potential infrastructural decisions. Considering that 8 seconds might be the maximum you would consider, we end up with a set of five fragment lengths:</p><pre>+------------+--------+---------+-------+---------+--------+<br>| FPS or                             fragment length in ms |<br>| block size |   1600 |    3200 |  4800 |    6400 |   8000 |<br>+------------+--------+---------+-------+---------+--------+<br>| video:                                                   |<br>| 50         |     80 |     160 |   240 |     320 |    400 |<br>| 25         |     40 |      80 |   120 |     160 |    200 |<br>| 12.5       |     20 |      40 |    60 |      80 |    100 |<br>| 5          |      8 |      16 |    24 |      32 |     40 |<br>| 60         |     96 |     192 |   288 |     384 |    480 |<br>| 30         |     48 |      96 |   144 |     192 |    240 |<br>| 15         |     24 |      48 |    72 |      96 |    120 |<br>| 5          |      8 |      16 |    24 |      32 |     40 |<br>| audio:                                                   |<br>| 1024       |     75 |     150 |   225 |     300 |    375 |<br>| 1536       |     50 |     100 |   150 |     200 |    250 |<br>+------------+--------+---------+-------+---------+--------+</pre><h3>What did we choose?</h3><p>Our goal was to achieve low latency. That also initiated the intense search for a proper fragment length. We eventually decided for going with 1.6 seconds from now on.</p><p>At the beginning of this article, we discussed the trade-off on encoding quality that comes with it. After implementing the new fragment length, we evaluated its impact. The result was a measurable decrease of the MOS metric of around 0.03. Even though this is measurable in data, this change is not visible. [5] states that “an absolute difference of less than 0.05 (up to 0.07 if confidence bounds are taken into consideration) in MOS value can be considered insignificant since it cannot be perceived by users”.</p><h3>Summary</h3><p>Check your current content specs (frame rate, audio codecs) and what you might have planned for the future. Then do the math to find your matching fragment lengths and decide if you want to go for a shorter or longer variant, depending on your use cases. Everything else will lead you into trouble at some point.</p><p>This is the first part of a blog article trilogy that covers all aspects of our journey to low latency streaming.<br>The second part describes our general concept for reducing the latency of live streams and goes into detail on the server-side changes we did, as well as how end-to-end latency can be measured in an OTT streaming service: <a href="https://medium.com/zattoo_tech/how-to-go-low-latency-without-special-tricks-37c69db027bb">How to go low latency, without special tricks</a>.<br>The third part deals with the client-side changes needed when approaching low latency streaming: <a href="https://medium.com/zattoo_tech/smart-buffering-and-the-two-types-of-player-configurations-9cb052d34828">Smart Buffering — and the two types of player configurations.</a></p><h3>References</h3><p>[1] <a href="https://developer.apple.com/documentation/http_live_streaming/hls_authoring_specification_for_apple_devices">https://developer.apple.com/documentation/http_live_streaming/hls_authoring_specification_for_apple_devices</a></p><p>[2] <a href="https://bitmovin.com/mpeg-dash-hls-segment-length/">https://bitmovin.com/mpeg-dash-hls-segment-length/</a></p><p>[3] <a href="https://streaminglearningcenter.com/blogs/choosing-the-optimal-segment-duration.html">https://streaminglearningcenter.com/blogs/choosing-the-optimal-segment-duration.html</a></p><p>[4] <a href="https://blog.zazu.berlin/internet-programmierung/mpeg-dash-and-hls-adaptive-bitrate-streaming-with-ffmpeg.html">https://blog.zazu.berlin/internet-programmierung/mpeg-dash-and-hls-adaptive-bitrate-streaming-with-ffmpeg.html</a></p><p>[5] <a href="https://link.springer.com/article/10.1007/s41233-018-0019-8">https://link.springer.com/article/10.1007/s41233-018-0019-8</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=617f75b9ccf3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zattoo_tech/the-definitive-guide-for-picking-a-fragment-length-617f75b9ccf3">The definitive guide for picking a fragment length</a> was originally published in <a href="https://medium.com/zattoo_tech">Zattoo’s Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>