<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Blog on Charlie's Server &#187; HD</title> <atom:link href="http://blog.charlies-server.com/tag/hd/feed" rel="self" type="application/rss+xml" /><link>http://blog.charlies-server.com</link> <description></description> <lastBuildDate>Fri, 09 Sep 2011 05:31:51 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>HD Video Playback in Linux</title><link>http://blog.charlies-server.com/2007/09/13/hd-video-playback-in-linux</link> <comments>http://blog.charlies-server.com/2007/09/13/hd-video-playback-in-linux#comments</comments> <pubDate>Thu, 13 Sep 2007 15:17:03 +0000</pubDate> <dc:creator>Hasan</dc:creator> <category><![CDATA[Geekdom]]></category> <category><![CDATA[H.264]]></category> <category><![CDATA[Hardware]]></category> <category><![CDATA[HD]]></category> <category><![CDATA[Linux]]></category><guid isPermaLink="false">http://newblog.charlies-server.com/2007/09/13/hd-video-playback-in-linux/</guid> <description><![CDATA[It seems that any developer I ask tells me that it&#8217;s currently not possible to play back 1080p H.264 video in Linux. In this post, I respond loud and clear to anyone who has said that: They Are Wrong. But there has to be a catch, right? Of course there is; there&#8217;s always a catch. [...]]]></description> <content:encoded><![CDATA[<p>It seems that any developer I ask tells me that it&#8217;s currently not possible to play back 1080p H.264 video in Linux. In this post, I respond loud and clear to anyone who has said that: <strong>They Are Wrong</strong>. But there has to be a catch, right? Of course there is; there&#8217;s always a catch. Yes, I can play back <em>some</em> 1080p H.264 video flawlessly in Linux. Yes, I have watched entire movies in this fashion. Yes, there are some clips that I just can&#8217;t play back with my setup. Read on for the details of said setup, how I do it, and what the limitations are.<br /> <span id="more-105"></span></p><h3 id="toc-definitions-limitations">Definitions &amp; Limitations</h3><p>First, I should provide some definitions and/or limitations; in order to make any claims we first need to lay down some commonly accepted premises. I&#8217;m not going to argue that the following definitions are universally correct or even that they represent any general consensus; this is just how I define the following terms and what these definitions mean &#8212; subjectively &#8212; to me.</p><h4 id="toc-1080p">1080p</h4><p>This one is going to be controversial. Technically speaking, a video is defined as within the 1080p standard if (a) its picture is progressive (non-interlaced) and (b) the picture is made up of 1,080 rows of pixels. What is implied but not specifically stated in this definition is that the aspect ratio of a 1080p picture is 16:9, yielding a resolution of 1920&#215;1080. However, since many movies are filmed in wider aspect ratios, commercial 1080p media is often <a href="http://en.wikipedia.org/wiki/Letterbox" title="Wikipedia: Letterbox">letterboxed</a> in order to avoid cropping. As such, for my purposes, I define 1080p to be any picture with 1,920 columns of pixels.</p><h4 id="toc-h-264">H.264</h4><p>The H.264 codec is an ugly multi-headed beast. The specification for this particular video codec provides many different profiles which all require different amounts of processing power to encode or decode. There are all sorts of available &#8216;options&#8217; within the standard and many of them probably require a supercomputer just to decode (in 1080p) in realtime. For the purposes of this discussion, I&#8217;ll say that we&#8217;re dealing with the baseline or main H.264 profiles, using a reasonable amount of b-frames and reference frames &#8212; say, one to three &#8212; at a reasonable bitrate of about 10mbit (average) for 1080p films, using CABAC. Most of my test clips were encoded using the wonderful x264 open-source H.264 encoder.</p><h3 id="toc-hardware">Hardware</h3><p>When I set out to build a Home Theater PC (HTPC), I wanted to keep 1080p H.264 playback in mind, and knowing that this problem is computationally difficult, I bought fairly high-end hardware with budget somewhat in mind. I won&#8217;t argue for or against my hardware, since that&#8217;s a whole different debate better suited to people more so inclined. I will say that my hardware works me.</p><table class="visible"><tr><th>Processor</th><td>AMD Athlon 64 X2 6000+</td></tr><tr><th>Motherboard</th><td>Gigabyte GA-MA69G-S3H</td></tr><tr><th>RAM</th><td>Wintec AMPX 1GB (2 x 512MB) PC2 6400</td></tr><tr><th>Video</th><td>BFG Tech 3D Fuzion GeForce 6200LE</td></tr><tr><th>Display</th><td>Mitsubishi LT-46131 (1920&#215;1080 46&#8243; LCD)</td></tr></table><h4 id="toc-processor">Processor</h4><div class="alternate"><div class="wpg2tag-image"><a href="http://blog.charlies-server.com/v/Misc/AMD_Athlon64_X2_6000.html" title="AMD Athlon 64 X2 6000+"><img src="http://blog.charlies-server.com/gallery/d/3673-2/AMD_Athlon64_X2_6000" width="150" height="124" id="IFid5" class="ImageFrame_None" alt="AMD Athlon 64 X2 6000+"/></a></div></div><p>Whilst not getting into the AMD vs. Intel debate, I will say this: I feel that going with AMD is more cost-effective. At time of purchase, the chip I bought had just had a huge price drop and as such became quite attractive. Once I got the components together and verified that everything worked, I overclocked this bad-boy from its stock 3.0Ghz (200Mhz x 15) to 3.15Ghz (210Mhz x 15) just to squeeze a bit (5% to be precise) out of it. Whilst I could get it to run at 3.3Ghz, it wasn&#8217;t stable and I wasn&#8217;t willing to bump the voltages up too much on the stock cooling I have. Currently this processor runs at around 35&deg;C idle and around 65&deg;C under load.</p><h4 id="toc-motherboard" style="clear: right;">Motherboard</h4><div class="alternate"><div class="wpg2tag-image"><a href="http://blog.charlies-server.com/v/Misc/GA-MA69G-S3H.html" title="Gigabyte GA-MA69G-S3H"><img src="http://blog.charlies-server.com/gallery/d/3670-2/GA-MA69G-S3H" width="150" height="116" id="IFid6" class="ImageFrame_None" alt="Gigabyte GA-MA69G-S3H"/></a></div></div><p>This is where I spent a lot of time researching. I wanted a motherboard that had as many integrated components as possible. Most motherboards these days have integrated sound but not all have integrated sound with optical out, which was an absolute necessity for me. I was also looking for a motherboard with integrated video. I found this one with the added bonus of having integrated HDMI. I couldn&#8217;t get the sound pass-through over HDMI working under Linux, but since I have an optical connection to the receiver anyways I&#8217;m not too fettered about it.</p><h4 id="toc-ram" style="clear: right;">RAM</h4><p>Quite simply, just whatever cheap dual-channel 800Mhz RAM compatible with my motherboard I happened to find on <a href="http://newegg.com">newegg.com</a>.</p><h4 id="toc-video">Video</h4><div class="alternate"><div class="wpg2tag-image"><a href="http://blog.charlies-server.com/v/Misc/BFG_Tech_3D_Fuzion_GeForce_6200LE.html" title="BFG Tech 3D Fuzion GeForce 6200LE"><img src="http://blog.charlies-server.com/gallery/d/3676-4/BFG_Tech_3D_Fuzion_GeForce_6200LE" width="150" height="101" id="IFid7" class="ImageFrame_None" alt="BFG Tech 3D Fuzion GeForce 6200LE"/></a></div></div><p>As I found out just after putting all of the hardware together, ATI&#8217;s drivers for Linux do not support XVideo (hardware accelerated video scaling, color-space conversions, and display), rendering the integrated video card on the motherboard less useful. I decided to buy the cheapest PCI-Express NVIDIA card I could find, making sure that it was fully supported with the latest NVIDIA Linux drivers. More on this in the software section below.</p><h4 id="toc-display" style="clear: right;">Display</h4><div class="alternate"><div class="wpg2tag-image"><a href="http://blog.charlies-server.com/v/Misc/LT-46131.html" title="Mitsubishi LT-46131"><img src="http://blog.charlies-server.com/gallery/d/3667-4/LT-46131" width="150" height="117" id="IFid8" class="ImageFrame_None" alt="Mitsubishi LT-46131"/></a></div></div><p>Most new HDTVs now have some sort of direct-from-computer input &#8212; mine has a DVI port right on the back. Some HDTVs, however, do some <a href="http://en.wikipedia.org/wiki/Overscan" title="Wikipedia: Overscan">overscanning</a> and other image processing on the signal received, even for digital signals. Depending on the source, this can be good or bad, but in general when attaching a computer to a display you want a 1:1 (no overscan) pixel mapping. Fortunately my display supports this via its DVI port.</p><h3 id="toc-software" style="clear: right;">Software</h3><p>There was no doubt in my mind that I&#8217;d be running Linux, so hardware acceleration of H.264 playback was immediately a no-go: the driver support just isn&#8217;t there yet. It turns out that I&#8217;m pretty much stuck with ffmpeg&#8217;s H.264 decoder for playback (I won&#8217;t get into the controversial CoreAVC-on-Linux fiasco here other than to say I&#8217;m not about to go hacking up mplayer code to get CoreAVC on Linux under 64bit). But there&#8217;s more to playback than just decoding the input video stream; once the stream is decoded, there is an often necessary colorspace conversion to do, there may or may not be some scaling involved, and of course you have to get the decoded image to the display somehow, which can take significant amounts of compute time.</p><h4 id="toc-decoding">Decoding</h4><p>The ffmpeg H.264 decoder is really great with one major caveat: it&#8217;s not multithreaded. This means that no matter how many cores you have, H.264 decoding will use exactly one. I hear there&#8217;s some work being done on parallelizing said decoder, but as of yet I&#8217;ve heard of no working prototypes let alone a release. Knowing this is mostly why I wanted such a high clock speed for my main processor, regardless of how many cores it has &#8212; for sure I would have bought a cheaper, slower dual-core processor had the ffmpeg H.264 decoder been capable of taking advantage of two cores simultaneously.</p><p>That having been said, there are some decoding options that you can pass to ffmpeg&#8217;s H.264 decoder via mplayer that will improve performance at the cost of quality. Specifically, there&#8217;s the ability so skip all of the in-loop filters (deblocking, mainly), which should yield a performance increase of ranging from zero to three hundred precent or more depending on the source material and encoding options. Simply invoke mplayer with the option <code>-lavdopts fast=1:skiploopfilter=all</code> &#8212; you can read more about these in your mplayer manpage. If your processor just isn&#8217;t capable of handling H.264 videos you&#8217;re trying to play, a good first pass is to try disabling in-loop filters. If your processor still can&#8217;t handle it, it&#8217;s time for you to upgrade &#8212; there&#8217;s pretty much nothing else you can do.</p><h4 id="toc-displaying">Displaying</h4><p>Once a video stream has been decoded, it is typically sent to a display for viewing. Often this involves colorspace conversions and/or scaling. In my case, with 1080p playback, there is typically no scaling necessary as my display is exactly as large (at least in the limiting dimension) as the image being displayed. In the case of 720p on a 1080p display, however, some upscaling needs to be done. Some upscaling and colorspace conversion computations can be done in hardware on your graphics card if your graphics drivers are capable and set up for it. One such technology under Linux is XVideo, or XV for short.</p><p>XV can handle colorspace conversions and upscaling natively in graphics hardware so that your CPU doesn&#8217;t have to burn cycles doing so. In the absence of XV, I have found mplayer&#8217;s X11 output driver to be the best on my setup. Even though the X11 processing seemingly went on in the X11 server (according to top), which of course does not run on the same core as mplayer so as to maximize performance, I found that using the X11 display driver cause a significant decrease in video playback performance &#8212; enough to drop a few frames in some test clips. Since the ATI drivers for the integrated graphics chipset on my motherboard do not provide XV capabilities at time of writing (note that this is a specific case for my video chipset, the X1250 &#8212; most other ATI chipsets boast XV support in the proprietary ATI drivers), I bought a cheap NVIDIA card that I knew would work with XV. Once I had XV working, I was able to play back clips that had previously stuttered due to dropped frames.</p><p>It is my preference, however, to not upscale videos using XV, as generally I find the results to be much better when using a decent software upscaler. This is especially visible when viewing, for example, NTSC television captures on a 1080p display. There are a number of software upscale implementations bundled with mplayer, and for most people the default will suffice. If this is a bit too CPU-intensive, though, I find that the fast bilinear algorithm does a fairly good job and is a little bit less CPU intensive than the default bicubic algorithm. To select this, simply invoke mplayer with the <code>-zoom -sws 0</code> arguments. Of course, the quality of the upscale will depend on the source and the algorithm of choice, so as with anything else, try a few of the different options and go with what you prefer.</p><h4 id="toc-a-note-on-sound">A Note On Sound</h4><p>I run an optical line between my HTPC and my sound receiver and use it for both PCM and surround (Dolby or DTS) sound. While this article is, as the title suggests, about video, I feel compelled here to mention that decoding surround sound in software does take a nontrivial amount of CPU time. You&#8217;ll be much better off &#8212; for a number of reasons, compute time inclusive &#8212; sending the audio stream to a hardware decoder (read: sound receiver) for playback there. Sometimes the little bit of difference that decoding sound can make is what you&#8217;ll need to avoid a few dropped frames here and there.</p> ]]></content:encoded> <wfw:commentRss>http://blog.charlies-server.com/2007/09/13/hd-video-playback-in-linux/feed</wfw:commentRss> <slash:comments>32</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: blog.charlies-server.com @ 2012-02-10 22:03:04 -->
