{"id":2891,"date":"2010-09-11T21:40:45","date_gmt":"2010-09-12T04:40:45","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/?p=2891"},"modified":"2010-09-11T22:29:04","modified_gmt":"2010-09-12T05:29:04","slug":"naive-svq1-encoder","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/naive-svq1-encoder\/","title":{"rendered":"Naive Sorenson Video 1 Encoder"},"content":{"rendered":"<p><em>(Yes, the word is &#8220;naive&#8221; &#8212; or rather, &#8220;na\u00efve&#8221; &#8212; not &#8220;native&#8221;. People always try to correct me when I use the word. Indeed, it should actually be written with 2 dots over the &#8216;i&#8217; but who has a keyboard that can easily do that?)<\/em><\/p>\n<p>At the most primitive level, programming a video encoder is about writing out a sequence of bits that the corresponding video decoder will understand. It&#8217;s sort of like creating a program &#8212; represented as a stream of opcodes &#8212; that will run on a given microprocessor or virtual machine. In fact, reading a video codec bitstream specification will reveal a lot of terminology along the lines of &#8220;transmitting information to the decoder&#8221; or &#8220;signaling the decoder to do <em>xyz<\/em>.&#8221;<\/p>\n<p>Creating <strong>a good encoder<\/strong> that will deliver decent quality at a reasonable bitrate is difficult. Creating <strong>a naive encoder<\/strong> that produces a technically compliant bitstream, not so much.<\/p>\n<p><center><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-title.jpg\" alt=\"\" title=\"Big Buck Bunny title\" width=\"400\" height=\"225\" class=\"aligncenter size-full wp-image-2892\" srcset=\"https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-title.jpg 400w, https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-title-300x168.jpg 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><br \/>\n<\/center><\/p>\n<p>When I wrote an FFmpeg encoder for <a href=\"http:\/\/wiki.multimedia.cx\/index.php?title=Sorenson_Video_1\">Sorenson Video 1 (SVQ1)<\/a>, the first step was to just create a minimally compliant bitstream. The coarsest encoding mode that SVQ1 allows is to encode the average (mean) of each 16&#215;16 block of samples. So I created an encoder that just encoded the mean of each block. Apple&#8217;s QuickTime Player was able to play the resulting video in all of its blocky glory. The result rather reminds me of the Super Nintendo&#8217;s mosaic effect.<\/p>\n<p>Level 5 blocks (mean-only 16&#215;16 encoding):<br \/>\n<center><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-svq1-l5.png\" alt=\"\" title=\"Big Buck Bunny - blocky title\" width=\"400\" height=\"225\" class=\"aligncenter size-full wp-image-2893\" srcset=\"https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-svq1-l5.png 400w, https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-svq1-l5-300x168.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><br \/>\n<\/center><\/p>\n<p>Level 3 blocks (mean-only 8&#215;8 encoding):<br \/>\n<center><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-svq1-l3.png\" alt=\"\" title=\"Big Buck Bunny title - still blocky, but finer resolution\" width=\"400\" height=\"225\" class=\"aligncenter size-full wp-image-2894\" srcset=\"https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-svq1-l3.png 400w, https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-svq1-l3-300x168.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><br \/>\n<\/center><\/p>\n<p>It&#8217;s one thing for your own decoder (in this case, FFmpeg&#8217;s own decoder) to be able to decode the data. The big test is whether the official decoder (in this case, Apple QuickTime Player) can decode the file.<\/p>\n<p><center><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-qt-player.png\" alt=\"\" title=\"Playing in Apple QuickTime Player\" width=\"558\" height=\"349\" class=\"aligncenter size-full wp-image-2895\" srcset=\"https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-qt-player.png 558w, https:\/\/multimedia.cx\/eggs\/wp-content\/uploads\/2010\/09\/bbb-qt-player-300x187.png 300w\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" \/><br \/>\n<\/center><\/p>\n<p>Now that&#8217;s a good feeling. After establishing that sort of baseline, it&#8217;s possible to adapt more and more features of the codec.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is how to start writing a video encoder<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2891","post","type-post","status-publish","format-standard","hentry","category-general"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/2891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/comments?post=2891"}],"version-history":[{"count":8,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/2891\/revisions"}],"predecessor-version":[{"id":2903,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/2891\/revisions\/2903"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=2891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=2891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=2891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}