Vainfo returns "libva error: /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so init failed" in dual gpu system

I have a dual gpu system. It has a 2nd generation Sandy Bridge iGPU and an nvidia 650ti. The Nvidia gpu is connected to the display and is using the proprietary drivers. I'm trying to use the iGPU for video encoding.

I have installed the va driver using

sudo apt-get install i965-va-driver

If I run vainfo it returns:

libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

But if I run LIBVA_DRIVER_NAME=i965 vainfo it returns:

libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'i965'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_1
libva error: /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so init failed
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

A little late, but I ran into the same problem so I thought I'd leave what worked for me. Apparently you need the VDPAU (http://http.download.nvidia.com/XFree86/vdpau/doxygen/html/index.html) wrapper.

sudo apt-get install vdpau-va-driver

After that it returns fine.

libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.1 (libva 2.1.0)
vainfo: Driver version: Splitted-Desktop Systems VDPAU backend for VA-API - 0.7.4

The package vdpau-va-driver is required for hardware acceleration with the NVIDIA proprietary drivers. Canonical dropped the package vdpau-va-driver some time ago for no clear reason. This is reported in Launchpad, please feel free to report that you are affected by clicking on "Does this bug affect you?".

Debian provides an up to date version, currently 0.7.4-7, which can be downloaded here (download the latest 32 bit 64 bit versions) and installed from a command line by running dpkg -i on the respective packages. After the installation the command vainfo is happy again and returns, among other things:

vainfo: Driver version: Splitted-Desktop Systems VDPAU backend for VA-API - 0.7.4

You can then refer to this guide from ArchWiki on how to take advantage of VDPAU in different applications.