How to Get Rid of Video Tearing (and Other Forms of It) under Linux

June 23 2011

Yesterday I was having problems with video tearing, so I figured I'd write a small guide about getting rid of tearing. I only have an Nvidia card, so if you're using an ATi driver, try and find a similar setting.

Since I don't like writing posts that don't teach people things, I'll give a short explanation of the theory behind the guide. As many of you probably know, X11/X Server is what draws the user interface on Linux (or at the very least, for now). All video playback goes through the XVideo extension for X11. Essentially, it hands off video scaling/drawing to the GPU, since the GPU is more specialised for that sort of thing, and can do it faster than the CPU.

The video starts out by being decoded from whatever codec it's in on the CPU until we get just pixel data for each frame. This is then handed off to XVideo, which then scales the video to the window it's being displayed in, and draws it on the screen. Nvidia's drivers (and likely ATi's as well) interact with XVideo, otherwise it wouldn't be able to "talk" to the GPU (and by talk, I mean send instructions to be executed).

So, what causes tearing? The short answer would be that the monitor and XVideo aren't synchronised using vsync. The long answer is that the screen is refreshing at a given rate (usually 60-75 Hz or times per second), and XVideo is dumping frames from the video stream without regard to this. So, if XVideo sends a new frame to the screen while the video card is sending a frame out to the monitor, we'll see half of the previous frame, and half of the next frame. In short, we get tearing.

How do you fix this? Vsync. Vsync will sync up XVideo and the refresh rate so that it won't push a frame out while the screen is refreshing. Vsync can also be enabled in OpenGL rendering; same principle, just with polygons and textures instead of a video stream. Many people make the mistake of disabling vsync because they get lower fps, when in actuality it's not really adding much overhead when compared to something like dynamic lighting. But that's a topic for another post.

If you were reading the previous paragraphs, what you need to do should be obvious (or at least I hope). If not, here's some directions:

1. Open up the Nvidia settings panel. Click on X Server XVideo Settings. Make sure vsync is checked. For multi-monitor setups, make sure it's syncing to the monitor you're going to be playing back video on, otherwise you'll still have tearing. Go back to the initial page showing the monitor configurations and save everything to your X configuration.

Special note: for one reason or the other, TwinView seems to cause tearing. I'm guessing this is a problem if your screens are different resolutions, but I haven't been able to test it. Try using separate X screens and see if things are still not working. I don't know enough about the Nvidia driver to say why, this is simply what I've found.

2. Make sure your video player is outputting using XVideo. If it's using some other method, we can't be sure it's vsynced. DON'T use OpenGL output unless you know what you're doing, XVideo should be fine in most cases. Here are the settings I have in VLC.

3. If your window manager (eg Compiz) redirects windows, make sure you have vsync enabled in it, and it's using the correct refresh rate. I don't know all that much about Compiz, so I may be wrong here. I find that Compiz has a tendency to not detect refresh rates correctly, but it could just be me. If you're finding compiz is tearing, this may help. Also make sure it's not redirecting fullscreen windows, since it'll add unneeded overhead. Basically redirecting windows involves having the pixel data go through Compiz so it can add effects and such, and if you're watching a fullscreen video, it's unnecessary. If you want to go crazy, you can force all OpenGL apps to be vsynced in the nividia driver settings (this should include compiz). Below are my settings, adjust them to fit your needs (check the refresh rate on your monitor).

Edit: A friend of mine told me this in IRC, so it seems I was a bit off...

edong23: [Refresh Rate is] not the same as the screen refreshing, its the frames per second
edong23: limiting them can impact your quality of all open gl apps
edong23: and video that is overlayed above it
hflw: so what you're saying is that you should have vsync on and max out the FPS?
edong23: yar
edong23: its the number of times it "can" refresh
edong23: this information came to me from the compiz guys
edong23: also, if you use compiz and nvidia, you should use loose binding
edong23: the auto detect refresh rate usually ends up defaulting very low
edong23: so setting it to 60 helps
edong23: alot
edong23: but, setting it higher is better

That should be it. Check your video playback, and if it's still giving you problems, take a look at your settings, make sure they're right. The Arch Wiki page has some helpful information on the Nvidia and ATi pages if you get stuck.

Posted by Will

1 comments

Read More»

Site Redesigned (Again)

June 16 2011

As I mentioned previously, I was kind of disappointed with the previous design. I put this together over the past two weeks or so. This time I was shooting for a very minimalistic, "open" feeling design. The most difficult parts were getting the colors right, and getting the typography right, but I definitely learned a lot from doing the new design. It's also using HTML5, which is a perk.

Hopefully this is the last redesign I'll have to go through for a while. I still have mixed feelings about the new slogan, need to think about it. Knowing me, I'll be tweaking this for the next two weeks until I deem it to be perfect.

I originally had plans for a "social feed" sort of thing on the homepage, but I just wanted to get this up ASAP, since I wasn't happy with the old design. When I have more time, I can always add it in. I also wanted to redesign the blog archive a bit, since I really liked how Usability Post handles things, but I'll get to it eventually. Need to finish Blackpyre and Lucid 2.0 first.

Posted by Will

1 comments

Read More»