<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zen</title>
    <description>The latest articles on DEV Community by Zen (@master_of_zen).</description>
    <link>https://dev.to/master_of_zen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F589146%2F0491274a-7ea4-4a9e-a112-40075a771b91.png</url>
      <title>DEV Community: Zen</title>
      <link>https://dev.to/master_of_zen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/master_of_zen"/>
    <language>en</language>
    <item>
      <title>Per-speed rdo-lookahead-frames optimization</title>
      <dc:creator>Zen</dc:creator>
      <pubDate>Wed, 03 Mar 2021 08:21:42 +0000</pubDate>
      <link>https://dev.to/master_of_zen/per-speed-rdo-lookahead-frames-optimization-5ai2</link>
      <guid>https://dev.to/master_of_zen/per-speed-rdo-lookahead-frames-optimization-5ai2</guid>
      <description>&lt;p&gt;This is the third story about how we made rav1e up to 2x fast in 3 weeks. For the first one go &lt;a href="https://dev.to/barrbrain/video-encoder-rollback-optimization-in-rav1e-4d5k"&gt;here&lt;/a&gt; for the second go &lt;a href="https://dev.to/luzero/temporal-rdo-update-optimization-2pf1"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Speed levels
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;rav1e&lt;/strong&gt; have 11 speed levels, 0 to 10, each tuned to give reasonable quality to speed trade-off for each use-case.&lt;/p&gt;

&lt;p&gt;Previously, by default, all speed levels had &lt;code&gt;--rdo-lookahed-frames&lt;/code&gt; set to 40, which at the time was a reasonable decision as it gave the encoder plenty of lookahead to make coding decision on.&lt;/p&gt;

&lt;p&gt;In recent benchmarking of encoder settings, we discovered that the high and constant value of lookahead is excessive for higher speeds. Relative time spends on rdo lookahead increase with increasing encoding speed preset and gains decrease.&lt;/p&gt;

&lt;h2&gt;
  
  
  Speed, Quality, BD-rate
&lt;/h2&gt;

&lt;p&gt;In changing encoder presets we need to balance 2 things: Speed Gain and Quality Decrease.&lt;/p&gt;

&lt;p&gt;As speed gain, we took the average difference of encoding time between baseline and different &lt;code&gt;--rdo-lookahed-frames&lt;/code&gt; settings, in a range from 30 to 10.&lt;/p&gt;

&lt;p&gt;The quality difference was measured by BD-rate (Bjontegaard rate). It allows measurement of bitrate difference between codecs or features of codec at the same quality, for used metric. The rate change is computed as the average percent difference in rate over a range of qualities.&lt;/p&gt;

&lt;p&gt;In simple terms, how much more bits encoder needs to achieve the same quality, on average. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Negative&lt;/strong&gt; values of BD-rate: bit-rate saves, &lt;strong&gt;better&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Positive&lt;/strong&gt; values do BD-rate: bit-rate expenses, &lt;strong&gt;worse&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Per-speed level rdo lookahead
&lt;/h2&gt;

&lt;p&gt;This graph shows what average speed difference is expected by changing &lt;code&gt;--rdo-lookahed-frames&lt;/code&gt; from default 40.&lt;br&gt;
&lt;a href="https://camo.githubusercontent.com/332e03cd46b1bd8676ec57b1b523f835f8cc6153d522397dc061bc85e21dff13/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3639363834393937343636363938353439342f3831313633393235363037373639373037342f323032315f30325f31375f31385f34345f33302e77656270" class="article-body-image-wrapper"&gt;&lt;img src="https://camo.githubusercontent.com/332e03cd46b1bd8676ec57b1b523f835f8cc6153d522397dc061bc85e21dff13/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3639363834393937343636363938353439342f3831313633393235363037373639373037342f323032315f30325f31375f31385f34345f33302e77656270" alt="image alt"&gt;&lt;/a&gt;&lt;br&gt;
As we can see, the biggest change occurs at speed 10, around 12% for &lt;code&gt;--rdo-lookahed-frames&lt;/code&gt; 10, after that speed up is steady for speeds 9 to 5 and after that decrease for speeds 4 to 1.&lt;/p&gt;

&lt;p&gt;Now, let's look at the quality trade-off.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://camo.githubusercontent.com/0dadf99588bb6d5e34986a2a3317ff6b9c047ea826336433a7a216a25e617c6e/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3639363834393937343636363938353439342f3831313633383537373333303931333332302f323032315f30325f31375f31375f32335f30302e77656270" class="article-body-image-wrapper"&gt;&lt;img src="https://camo.githubusercontent.com/0dadf99588bb6d5e34986a2a3317ff6b9c047ea826336433a7a216a25e617c6e/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3639363834393937343636363938353439342f3831313633383537373333303931333332302f323032315f30325f31375f31375f32335f30302e77656270" alt="image alt"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, speeds 10 and 9 have the lowest impact on quality, for speed 9 data even show that &lt;code&gt;--rdo-lookahed-frames 30&lt;/code&gt; have a negative BD-rate, which is of course just noise of data. Given this, it's reasonable to set &lt;code&gt;--rdo-lookahed-frames 10&lt;/code&gt; for speeds 10 and 9.&lt;/p&gt;

&lt;p&gt;After speed 9 BD-rate difference increase, especially for the lowest value of 10, and ~1% of BD-rate difference is a sensible trade-off, we found it reasonable to set &lt;code&gt;--rdo-lookahed-frames 20&lt;/code&gt; for speeds 8,7,6. Speeds lower than 6 are high-quality presets and it's important to make them faster but also make them good, so we decided to set &lt;code&gt;--rdo-lookahed-frames 30&lt;/code&gt; for speeds 5,4,3 as it gives small speed up with the marginal difference in BD-rate, and left the highest quality presets unchanged.&lt;/p&gt;

&lt;p&gt;Final values:&lt;br&gt;
For speeds 10,9  -- &lt;code&gt;--rdo-lookahed-frames 10&lt;/code&gt;&lt;br&gt;
For speeds 8,7,6 - &lt;code&gt;--rdo-lookahed-frames 20&lt;/code&gt;&lt;br&gt;
For speeds 5,4,3 - &lt;code&gt;--rdo-lookahed-frames 30&lt;/code&gt;&lt;br&gt;
For speeds 2,1,0 - &lt;code&gt;--rdo-lookahed-frames 40&lt;/code&gt;&lt;/p&gt;

</description>
      <category>rav1e</category>
      <category>tuning</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
