Build OpenCV with MFX for sandy bridge (linux)

Hi mshabunin, thank you for your fast response.
The env. is set in .bashrc as well as other variables:

export MFX_HOME=/opt/intel/mediasdk
export LIBVA_DRIVERS_PATH=/opt/intel/mediasdk/lib
export LIBVA_DRIVER_NAME=i965

This works pretty well for the vainfo command:
libva info: VA-API version 1.8.0
libva info: User environment variable requested driver ‘iHD’
libva info: Trying to open /opt/intel/mediasdk/lib/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_8
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.8 (libva 2.1.0)
vainfo: Driver version: Intel iHD driver for Intel® Gen Graphics - 20.2.0 (97e2ea9)

But it seems to have no meaning to openCV.

I figured out that OpenCVDetectMediaSDK.cmake has been removed after version 4.0.1 on github. So maybe it is not even longer possible to get it in the build. I tried 4.0.1. and I could make it work with a part of this description. But my old cpu is still not running and does not use the path set in the environment variables. When it gets to the part, where the cv::VideoWriter is created:

cv::VideoWriter videoWriter(path, cv::CAP_INTEL_MFX, fourcc, fps, *size);

it prints for my dev system:

libva info: VA-API version 1.11.0
libva info: Trying to open /usr/local/lib/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_8
libva info: va_openDriver() returns 0

and works just fine, while my deployment system with the old intel sandbridge cpu prints this:

libva info: VA-API version 1.11.0
libva info: Trying to open /usr/local/lib/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_11
libva error:  /usr/local/lib/dri/iHD_drv_video.so init failed
libva info: va_openDriver() returns 1
libva info: Trying to open /usr/local/lib/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_1
libva info: va_openDriver() returns 0
MFX: Can't initialize session

So the deployment system tries another driver, i965, which is fine because it is older, but it can’t make it work. In both cases there are two things fishy:

  • VA-API version is for openCV 1.11.0 while you can see for vainfo it is 1.8
  • the path for the driver is not the path specified in MFX_HOME etc.

How can I use the libva of my vainfo and use the drivers directly from mediasdk?

I already used the provided link for MediaSDK, it is from 2017, it does not work.

Thank you for the plugin link, I have currently no idea how openCV is working with plugins, I am not even able to use the libs/tools of my system for openCV (ffmpeg, gstreamer, intel media sdk), do you have a good tutorial to see how the plugin works and my compiled tools are linked/used?