Kyle Brandt

Original computing and productivity articles by a Linux administrator

Archive for December, 2008

1080p HDTV H.264 Playback in Linux

with one comment

I recently picked up a 40 inch 1080p TV on Black Friday for my media computer (standard Ubuntu Intrepid Ibex install). Since this machine is a $450 dollar Dell Vostro (Intel Core 2 Duo E4500 CPU) it isn’t the fastest machine out there, but I have still been able to get generally smooth playback of H.264 1080p video.

Vocabulary
My understanding of the relevant codec vocabulary is as follows (Please comment on any inaccuracies). You get can get a lot of detail from this thread.

  • H.264 is the format of the encoded video.
  • x264 is a common encoder for creating H.264 video.
  • ffmpeg an open source decoder of H.264 video. It is the packaged standard in Linux for vlc and MPlayer.
  • CoreAVC is a commercial decoder that is built for windows, but can be used in Linux.
  • mkv (Mastroka) is a container that packages the video, audio, subtitles, etc. into one file. There is often H.264 in these files, but .mkv does not always mean H.264 or even HD.

Abstract
To successfully get good playback of 1080p H.264 video I had to purchase the CoreAVC codec, use the coreavc-for-linux project and wine to enable CoreAVC in Linux, and then recompile MPlayer with support for CoreAVC.

CoreAVC
The reason CoreAVC performs so much better than ffmpeg on my system is because CoreAVC is multi-threaded. This means that on a dual core system both CPU cores will be used to decode the video, instead of just one. If you run top and press ‘1′ you can see the utilization of each core, you will probably just see 1 core being utilized when you play video. The other core will probably show some usage, but it will be another process using it.

Since decoding H.264 is very resource intensive, multi-threading really helps. Currently there is no GPU (video card based) decoding for Linux except for a very beta NVidia driver.

CoreAVC costs a very reasonable 15 dollars, so it is definitely worth supporting the development of it.

CoreAVC For Linux
CoreAVC for Linux allows you to use the windows CoreAVC codec with Linux. The wiki on the project page will guide you through the installation. You must first run the CoreAVC install using wine (‘apt-get install wine‘ if you don’t have it already). Then follow the steps in registering the codec. Lastly, you will need to apply a patch to MPlayer and then compile it from source. Alternativly, you can get pre-built binaries (.deb ) from here of MPlayer and coreavc-for linux, but you will still need to install and register CoreAVC.

Mplayer

Mplayer is a very flexible player with a great depth of configuration. After applying the patch as instructed to in the CoreAVC wiki I configured it to install into /opt/mplayer before compiling (with ‘./configure PREFIX=/opt/mplayer‘) so I would have both the Ubuntu packed MPlayer and my own compiled version. I then run my version by typing the absolute path to it ( /opt/mplayer/bin/mplayer ).

I also had to update my x264 libraries for the latest subversion snapshot of MPlayer to compile successfully in Ubuntu Inrepid Ibex:

sudo apt-get install git-core
git clone git://git.videolan.org/x264.git
cd x264
make
sudo make install

The one problem I am still trying to resolve with MPlayer is to stop screen tearing. Screen tearing is when part of the image is no longer vertically aligned with the rest of the image for a brief moment. It is most noticeable in shots when the camera is panning. It is caused by the refresh rate of the monitor not being synced with the refresh rate of the video. There is only one way to fix this that I have found in Linux and that is to enable VSync to Blank and use the OpenGL output buffer. (sync to vblank can be enabled with the driconf package). Unfortunetly, for me when I select OpenGL with MPlayer the screen flickers. To try OpenGL pass ‘-vo gl’ to MPlayer.

The MPlayer options I use are: ‘-vc coreserve -cache 20000 -fs’. ‘-vc coresevre’ selects CoreAVC,the cache switch creates a cache of 20MB that will help if other applications are accessing the disk, and finally ‘-fs’ makes the playback fullscreen. I also increase the disk io and the cpu priority of MPlayer and dshowserver to max with the following commands:

ps aux | grep mplayer #Note the PID of the process (second column)
ps aux | grep dshow #Again, note the PID
#The following for both PIDs:
renice -1 -p$PID
ionice -c 1 -p$PID

Conclusion
With this setup I get much better 1080p HD playback than I did with the default Ubuntu Intrepid Ibex setup. I only occasionally get a hickup in playback but only in the most demanding scenes (lots of water) from something like BBC’s Planet Earth.

Written by Kyle

December 5th, 2008 at 7:35 am