{"id":1394,"date":"2012-09-30T09:51:21","date_gmt":"2012-09-30T07:51:21","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1394"},"modified":"2012-09-30T09:52:05","modified_gmt":"2012-09-30T07:52:05","slug":"libx264-illustrated","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1394","title":{"rendered":"libx264 illustrated"},"content":{"rendered":"<p>As <a href=\"http:\/\/www.videolan.org\/developers\/x264.html\"><code>libx264<\/code><\/a> has so many presets and tunes, I was curious how they all related one to another when it comes to encode video info <code>H.264<\/code>. I was more interested in single pass encoding for live video, so the measurements are respectively for this mode of operation with encoder running in CRF (constant rate factor, <code>X264_RC_CRF<\/code>).<\/p>\n<p>So I took <a href=\"http:\/\/homepage.ntlworld.com\/shaun.zoe\/projects\/hdtv.htm\">Robotica_1080.wmv<\/a> HD video in 1440&#215;1080 resolution and batch-transcoded into H.264 using libx264 (build 128) in various modes operation:<\/p>\n<ul>\n<li>Presets: &#8220;ultrafast&#8221;, &#8220;superfast&#8221;, &#8220;veryfast&#8221;, &#8220;faster&#8221;, &#8220;fast&#8221;, &#8220;medium&#8221;, &#8220;slow&#8221;, &#8220;slower&#8221;, &#8220;veryslow&#8221;<\/li>\n<li>Tunes: &#8220;film&#8221;, &#8220;animation&#8221;, &#8220;grain&#8221;, &#8220;stillimage&#8221;, &#8220;psnr&#8221;, &#8220;ssim&#8221;, &#8220;fastdecode&#8221;, &#8220;zerolatency&#8221;, &#8220;touhou&#8221;<\/li>\n<li>CRFs: 14, 17, 20, 23, 26<\/li>\n<\/ul>\n<p>It is worth mentioning that libx264 does EXCELLENT job in transcoding in terms of performance. Transcoding operation was a DirectShow graph of the following topology:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image001-800x551.png\" alt=\"\" title=\"x264 based WMV to MP4 Transcoding Topology\" width=\"620\" height=\"427\" class=\"alignnone size-large wp-image-1395\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image001-800x551.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image001-320x220.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image001.png 1013w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>Some measurements are obviously not quite accurate because not only encoding time counts, WMV decoding time counts also etc. Still this should give a good idea how modes stand side by side one with another.<\/p>\n<p>For every transcoding run I have the following values (Excel spreadsheet attached below):<\/p>\n<ul>\n<li>Processor Time: number of processor-milliseconds spent on the transcoding; I was measuring in 8 core system, so with 100% load processor time could be up to eight times higher than Elapsed Time (below) provided that all cores were used in full<\/li>\n<li>Elapsed Time: milliseconds spent on the transcoding; regardless of how many actual cores were in use, because original clip is 20 seconds long everything below that is faster than realtime processing<\/li>\n<li>Output File Size: size of resulting MP4 video only file, some headers count as well however it is obviously mostly payload data; for a 20 seconds clip, 20 MB is 8 mbit\/s bitrate<\/li>\n<\/ul>\n<p>Another derivative value is:<\/p>\n<ul>\n<li>Processor Time\/Elapsed Time: which shows fullness of use of multicore system; some modes are clearly not using all available cores, while other do<\/li>\n<\/ul>\n<p>Let us start watching pictures.<\/p>\n<p>Average Elapsed Time for Preset\/Tune (covers runs with different rate factors) shows that <code>slow+<\/code> modes take exponentially more time for encoding. <code>psnr<\/code> and <code>ssim<\/code> tunes do transcoding slightly faster, while <code>zerolatency<\/code> tune is the most expensive.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image004.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image004-800x519.png\" alt=\"\" title=\"Average Elapsed Time\" width=\"620\" height=\"402\" class=\"alignnone size-large wp-image-1401\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image004-800x519.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image004-320x207.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image004.png 1237w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p><!-- more \/\/--><\/p>\n<p><code>ultrafast<\/code> and <code>superfast<\/code> presets produced significantly larger files, about 2x as large as other presets.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002a.png\" alt=\"\" title=\"Average Output File Size\" width=\"605\" height=\"304\" class=\"alignnone size-full wp-image-1396\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002a.png 605w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002a-320x160.png 320w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><\/a><\/p>\n<p>Once again exponential scale of Elapsed Time, and similar Processor Time chart:<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002b.png\" alt=\"\" title=\"Average Elapsed Time\" width=\"605\" height=\"303\" class=\"alignnone size-full wp-image-1397\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002b.png 605w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002b-320x160.png 320w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002c.png\" alt=\"\" title=\"Average Processor Time\" width=\"605\" height=\"303\" class=\"alignnone size-full wp-image-1398\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002c.png 605w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002c-320x160.png 320w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><\/a><\/p>\n<p>It is worth mentioning that fastest presets are not using all CPU cores. Apart from being faster on their own, they leave some CPU time for other processing which can be useful for live encoding applications, and those processing multiple streams at once.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002d.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002d.png\" alt=\"\" title=\"Average Processor Time\/Elapsed Time\" width=\"605\" height=\"304\" class=\"alignnone size-full wp-image-1399\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002d.png 605w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image002d-320x160.png 320w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><\/a><\/p>\n<p>And finally detailed file size dependency from preset and CRF rate. As we already discovered, <code>ultrafast<\/code> and <code>superfast<\/code> produce larger stream, while output of other modes not so much differ (within a few percent, mostly on the slowest end). A step in rate factor of three gives about 0.7x decrease in amount of produces bytes.<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image003.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image003-800x520.png\" alt=\"\" title=\"Average Output File Size\" width=\"620\" height=\"403\" class=\"alignnone size-large wp-image-1400\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image003-800x520.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image003-320x208.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Image003.png 1237w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>More fun charts can be obtained from the attached .XLS file.<\/p>\n<p>Download links:<\/p>\n<ul>\n<li><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/09\/Transcode-Robotica_1080.wmv.xlsx\">Raw Data<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>As libx264 has so many presets and tunes, I was curious how they all related one to another when it comes to encode video info H.264. I was more interested in single pass encoding for live video, so the measurements are respectively for this mode of operation with encoder running in CRF (constant rate factor,&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1394\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[78,83,439,379,440,103,438],"class_list":["post-1394","post","type-post","status-publish","format-standard","hentry","category-video","tag-directshow","tag-dmo","tag-encoding","tag-h-264","tag-libx264","tag-performance","tag-x264"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1394"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1394\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}