{"id":1997,"date":"2009-11-30T20:42:45","date_gmt":"2009-12-01T03:42:45","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/?p=1997"},"modified":"2009-11-30T20:42:45","modified_gmt":"2009-12-01T03:42:45","slug":"gcc-of-multimedia","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/gcc-of-multimedia\/","title":{"rendered":"Is FFmpeg Doomed To Be The GCC of Multimedia?"},"content":{"rendered":"<p><a href=\"http:\/\/ffmpeg.org\/\">FFmpeg<\/a> is quite an amazing program. There&#8217;s a certain smugness that comes with being involved with it. That can lead to a bit of complacency followed by shock when realizing that you&#8217;re not as good as you thought you were.<\/p>\n<p>That happened to me recently when <a href=\"http:\/\/multimedia.cx\/eggs\/theora-1-1-released\/\">I realized the official libtheora decoder is significantly more performant<\/a> than FFmpeg&#8217;s Theora decoder. I suddenly wondered if this was true in any other departments, i.e., if FFmpeg is slower than other open source libraries that are dedicated to a single purpose. Why do I care? Because I started to wonder if FFmpeg would simply come to be known as the gcc of multimedia processing.<\/p>\n<p>Is it good or bad to be compared to gcc in this way? Depends; gcc has its pros and cons. A colleague once succinctly summarized these trade-offs thusly: &#8220;You can generally count on gcc to generate adequate code for just about any platform.&#8221; Some free software fans grow indignant when <a href=\"http:\/\/multimedia.cx\/eggs\/compiler-performance-profiling-with-ffmpeg\/\">repeated benchmarks<\/a> <a href=\"http:\/\/multimedia.cx\/eggs\/intel-beats-up-gcc\/\">unequivocally show<\/a>, e.g., <a href=\"http:\/\/multimedia.cx\/eggs\/performance-smackdown-now-with-64-bit\/\">Intel&#8217;s proprietary compilers<\/a> <a href=\"http:\/\/multimedia.cx\/eggs\/icc-vs-gcc-smackdown-round-3\/\">slaughtering gcc&#8217;s various versions<\/a>. But what do you expect? gcc spreads the effort around to all kinds of chips while Intel largely focuses on generating code for chips that they invented and know better than anyone else. Frankly, I&#8217;ve always admired gcc for being able to do as well as it does.<\/p>\n<p>But does it have to be that way with FFmpeg? &#8220;You can generally count on FFmpeg to be able to decode a particular format fairly quickly and encode to a wide variety of formats with reasonable quality.&#8221; That&#8217;s certainly the case currently regarding Theora (it can decode the format, just not as efficiently as libtheora). What about some other notable formats? I think some tests are in order.<\/p>\n<p><!--more--><\/p>\n<p>Methodology: Take a long audio file (I had a 10m44s audio file within reach when I brainstormed this test) and encode it as MP3, AAC, Vorbis, and FLAC. Profile FFmpeg&#8217;s performance vs. other open source packages by measuring best wall-clock (real) time out of 3 consecutive runs. Run these tests on an EeePC 701 which has an Intel Celeron M running at 630 MHz. This is somewhere that performance matters. Ask all programs to decode to 16-bit PCM and dump the output directly to \/dev\/null while squelching as much console output as the program will allow (I don&#8217;t know how to make FFmpeg shut up entirely but &#8216;-v 0&#8217; makes it not update its status along the way).<\/p>\n<p>FFmpeg SVN revision 20667 was used for these tests.<\/p>\n<p><strong>FLAC:<\/strong><\/p>\n<p>Using FLAC 1.2.1. Command lines:<\/p>\n<pre>\r\nffmpeg -v 0 -i file.flac -f s16le - > \/dev\/null\r\nflac --silent --stdout --decode file.flac > \/dev\/null\r\n<\/pre>\n<p>Results:<\/p>\n<pre>\r\n<font color=\"green\">FFmpeg:  8.4s<\/font>\r\nFLAC:   12.2s\r\n<\/pre>\n<p><strong>Vorbis:<\/strong><\/p>\n<p>Using whatever is currently installed in Ubuntu 9.10. I saw some security updates were downloaded recently so I suspect the Ogg and Vorbis libraries are quite up to date. Command lines:<\/p>\n<pre>\r\nffmpeg -v 0 -i file.ogg -f s16le - > \/dev\/null\r\noggdec --quiet --raw --output \/dev\/null file.ogg\r\n<\/pre>\n<p>Results:<\/p>\n<pre>\r\n<font color=\"green\">FFmpeg:     7.2s<\/font>\r\nlibvorbis: 12.3s\r\n<\/pre>\n<p><strong>AAC:<\/strong><\/p>\n<p>Using FAAD v2.6. Command lines:<\/p>\n<pre>\r\nffmpeg -v 0 -i file.m4a -f s16le - > \/dev\/null\r\nfaad -q -f 2 file.m4a -o \/dev\/null\r\n<\/pre>\n<p>Results:<\/p>\n<pre>\r\n<font color=\"green\">FFmpeg:   7.4s<\/font>\r\nlibfaad: 17.5s\r\n<\/pre>\n<p><strong>MP3:<\/strong><\/p>\n<p>Using mpg123 v1.9.2 and madplay v0.15.1 (beta). Command lines:<\/p>\n<pre>\r\nffmpeg -v 0 -i file.mp3 -f s16le - > \/dev\/null\r\nmadplay --very-quiet --output=raw:\/dev\/null file.mp3\r\nmpg123 -q -s file.mp3 > \/dev\/null\r\n<\/pre>\n<p>Results:<\/p>\n<pre>\r\n<font color=\"red\">FFmpeg: 22.3s<\/font>\r\nlibmad: 24.2s\r\nmpg123:  9.5s\r\n<\/pre>\n<p>So FFmpeg fared quite well except in the case of MP3 decoding. I&#8217;m a bit surprised that FFmpeg is relatively so slow to decode MP3. As Mans discovered, sometimes FFmpeg&#8217;s deficiencies are <a href=\"http:\/\/hardwarebug.org\/2009\/05\/13\/gcc-makes-a-mess\/\">actually gcc&#8217;s fault<\/a>. However, that blog post was primarily concerned with PowerPC. I wonder if x86_32 has the same problems.<\/p>\n<p>I also wanted to test XviD vs. FFmpeg&#8217;s decoder but I didn&#8217;t know how to set up that test. And if you want to know how various H.264 decoders stack up, both performance-wise and feature-wise, corner <a href=\"http:\/\/x264dev.multimedia.cx\/\">Dark Shikari<\/a> and he will be pleased to regale you with the benchmarks.<\/p>\n<p>So I guess that leaves FFmpeg&#8217;s Theora decoder as the biggest embarrassment. The good news is that I have some substantial optimizations planned for the very near future.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The good news is that FFmpeg still outperforms most dedicated open source multimedia libraries<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1997","post","type-post","status-publish","format-standard","hentry","category-open-source-multimedia"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1997","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=1997"}],"version-history":[{"count":6,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1997\/revisions"}],"predecessor-version":[{"id":2003,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1997\/revisions\/2003"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=1997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=1997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=1997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}