<story><title>Video codec in 100 lines of Rust</title><url>https://blog.tempus-ex.com/hello-video-codec/</url></story><parent_chain><item><author>Lerc</author><text>Naive Image and video codecs are quite fun to make, I have done a bunch of them over the years and it&amp;#x27;s quite easy to get within cooee of established formats.  And even surpass them under certain conditions.  I made a lossy image format that achieves 20-25 PSNR at around 200:1 compression,  which is better than most lossy formats because that&amp;#x27;s in a quality&amp;#x2F;data-size that most image formats consider out of scope.&lt;p&gt;QOI &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;qoiformat.org&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;qoiformat.org&amp;#x2F;&lt;/a&gt;  is a good example of a practically useful simple format.&lt;p&gt;It&amp;#x27;s still quite a leap to get to the best new codecs, suddenly you are in a world of head hurty math.&lt;p&gt;It&amp;#x27;s also worth noting that it is easy to beat the old formats all-round with off-the-shelf parts, both JPEG and PNG can be bested by changing the outer level of compression for something that was invented after the formats were made.  For instance using LZMA or zstd as the final stage.  Quite often that&amp;#x27;s enough to put them on a par with more radically different newer formats.</text></item></parent_chain><comment><author>bob1029</author><text>&amp;gt; It&amp;#x27;s also worth noting that it is easy to beat the old formats all-round with off-the-shelf parts, both JPEG and PNG can be bested by changing the outer level of compression for something that was invented after the formats were made.&lt;p&gt;The heart of JPEG is in The DCT and its energy compaction properties.&lt;p&gt;One crazy thing about the DCT is that it doesn&amp;#x27;t just let you make trade-offs for high&amp;#x2F;low frequency features. It also lets you make tradeoffs for &lt;i&gt;horizontal&lt;/i&gt; and &lt;i&gt;vertical&lt;/i&gt; features. If you customize your quantization matrix to your specific application, you can potentially achieve compression ratios far exceeding anything available today - even if you leave in the crusty old RLE+Huffman coding.&lt;p&gt;If you want to get up to your elbows in this sort of thing, there is an entire book on it by Rao &amp;amp; Yip that is about as comprehensive as it gets - &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.abebooks.com&amp;#x2F;products&amp;#x2F;isbn&amp;#x2F;9780125802031&amp;#x2F;31198865463&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.abebooks.com&amp;#x2F;products&amp;#x2F;isbn&amp;#x2F;9780125802031&amp;#x2F;3119886...&lt;/a&gt;</text></comment>
<story><title>Video codec in 100 lines of Rust</title><url>https://blog.tempus-ex.com/hello-video-codec/</url></story><parent_chain><item><author>Lerc</author><text>Naive Image and video codecs are quite fun to make, I have done a bunch of them over the years and it&amp;#x27;s quite easy to get within cooee of established formats.  And even surpass them under certain conditions.  I made a lossy image format that achieves 20-25 PSNR at around 200:1 compression,  which is better than most lossy formats because that&amp;#x27;s in a quality&amp;#x2F;data-size that most image formats consider out of scope.&lt;p&gt;QOI &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;qoiformat.org&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;qoiformat.org&amp;#x2F;&lt;/a&gt;  is a good example of a practically useful simple format.&lt;p&gt;It&amp;#x27;s still quite a leap to get to the best new codecs, suddenly you are in a world of head hurty math.&lt;p&gt;It&amp;#x27;s also worth noting that it is easy to beat the old formats all-round with off-the-shelf parts, both JPEG and PNG can be bested by changing the outer level of compression for something that was invented after the formats were made.  For instance using LZMA or zstd as the final stage.  Quite often that&amp;#x27;s enough to put them on a par with more radically different newer formats.</text></item></parent_chain><comment><author>userbinator</author><text>&lt;i&gt;For instance using LZMA or zstd as the final stage. Quite often that&amp;#x27;s enough to put them on a par with more radically different newer formats.&lt;/i&gt;&lt;p&gt;If you do that with a video codec, you lose the ability to seek within the stream, which makes it useless for streaming video. For images, the amount of memory required to decompress may become excessive.&lt;p&gt;It&amp;#x27;s similar to why zip (deflate) is still widely used, but is far from optimal in compression efficiency; everything that does better (in some cases much better) is going to be slower, bigger, or both. See &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;en.wikipedia.org&amp;#x2F;wiki&amp;#x2F;PAQ&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;en.wikipedia.org&amp;#x2F;wiki&amp;#x2F;PAQ&lt;/a&gt; for an example of &lt;i&gt;extreme&lt;/i&gt; lossless compression.</text></comment>