Tuesday, May 22, 2012

Eliminate Video Tearing in Ubuntu 12.04

Under Ubuntu 11.10, I quickly lost interest in the Unity interface and turned to Gnome 3 for my desktop experience. While it, too, was bug prone and awkward, it wasn't as bad as Unity, and I just accepted it as a temporary solution. I customized Gnome 3 quite a bit and in the end had a relatively stable environment with only one flaw: video tearing. When I upgraded to Ubuntu 12.04, I found the default Unity experience a bit more satisfactory and I decided it was time to get rid of my video artifacts once and for all.

Video tearing occurs when, for one of various reasons, one portion of the screen is displaying a different frame of a video from the rest of the screen. The effect can go from barely noticeable to downright annoying.

I have a dual-screen system using an NVidia 8600GTS graphics card. While a bit dated now, the card is generally satisfactory. I plan to upgrade it in the coming months to a card that supports CUDA GPU rendering in Blender. Under most applications, the display is clean and responsive, but it suffers a bit when playing video.

With a few, simple tweaks of Compiz, I've eliminated video tearing.

First, you'll need the CompizConfig Settings Manager. You can find it using Synaptic Package Manager or the Ubuntu Software Center, but I find it's really easy to drop into a terminal (ctrl-alt-t) and type:

sudo apt-get update
sudo apt-get install compizconfig-settings-manager

The CompizConfig Settings Manager (CCSM) allows you to make a variety of changes to the "personality" of your desktop experience. You can use it to control the behavior of the Unity Dash, apply special effects to common desktop activities, and even put your virtual desktops on a multi-sided polygon (the Cube) and spin to the desktop you need with your mouse.

For all its flexibility, CCSM (or maybe it's just Compiz itself) is glitchy and sometimes behaves unpredictably, so before you make any changes, scroll down under CCSM's Desktop section, click on the "Ubuntu Unity Plugin", and disable the plugin. Dash and your global menu will disappear. Don't worry, we'll re-enable them after we're done, and everything will be fine.

Now, scroll back up to the General section, and select "OpenGL". Turn off "Synch to VBlank", and set your Texture Filter to Best. Back out of OpenGL, then select the "Composite" plugin. Uncheck "Detect Refresh Rate" and bump the "Refresh Rate" up to at least 61. (Actually, I believe this depends on the refresh rate of your monitor -- you might need to check that first and set it higher.) "Force independent output painting" might be useful if you have multiple monitors; I do, but I leave this setting unchecked.

And that's it! Go back to the Unity Plugin and re-enable it, hit the back button, and when Unity finishes redrawing the Dash and global menu, close down CCSM. It's possible Dash won't respond unless you use the super key; if that happens, a simple log-out, log-in (don't bother rebooting) will suffice to get everything working again. As I said, Compiz is still a bit glitchy.

I've done this twice now under 12.04. Once within a couple weeks of installing it, and again this morning after I was messing around with command line utilities for Unity and accidentally reset it to default configuration. My cube was gone, my windows reset, my virtual workspaces all messed up, and that cursed video tear was back. After putting everything back, I figured I'd share my approach with others.

Good luck.

P.S.: Another thing to check: be sure both Sync to VBlank and Allow Flipping are enabled under the OpenGL tab in nVidia Settings.

1 comment: