OpenCV with Intel Media SDK

TimoK93
TimoK93 New Member Posts: 27 ✭✭

Hi all,
we are just programming a little VideoCapture node to read a stream from a camera and write it down to file with H.264 encoding. We're using OpenCV with it's functions
cv::VideoCapture("/dev/video0", ...)
cv::VideoWriter("DestinationFile", cv::fourCC('H','2','6,''4'), ...)

It's just a simple OpenCV Code processing reading and writing in a Loop. The input of the camera shall be 1920x1080. Capturing this with GStreamer is no problem!

The Problem that occoured

We felt very sad after programming this, because the writing is very slow... The maximum was about 10 fps, even with 1280x720. But we did not dispair!

The possible solution

OpenCV is supporting the 'Intel Media SDK'. You can use it with
cv::VideoWriter("DestinationFile", apiReference="INTEL_MFX", ...).
This API Reference will directly adress the Intel Chipset to encode/decode your stuff. Before your are able to use the API Reference the Intel Media SDK has to be installed.

Here is detailled description: https://github.com/opencv/opencv/wiki/MediaSDK-encode-decode-backend

But we have a problem building OpenCV with the MediaSDK: CMake is Unable to find the SDK. In CMake it is allways telling
-- Intel MEdia SDK: NO
no matter which flags are set.

Is there somebody that have experiences with installing OpenCV with Media SDK?

Greetings
Timo

Comments

  • TimoK93
    TimoK93 New Member Posts: 27 ✭✭

    Hey ho,
    after some investigations my colleague finished the API installation on the UP^2.

    Let me report her notices. Maybe someone will get the same problems. I did this work not on my own, so i maybe cannot answer questions, sorry...

    Build OpenCV with Intel Media SDK

    Intel Media SDK

    Intel Media SDK install

    • libva & libva-utils

      libva and libva-utils download and compile:

      git clone https://github.com/intel/libva.git
      git clone https://github.com/intel/libva-utils.git
      cd libva
      ./autogen.sh
      make -j4
      sudo make install
      cd libva-utils
      ./autogen.sh
      make -j4
      sudo make install
      
    • gmmlib

      gmmlib download and compile:

      git clone https://github.com/intel/gmmlib.git
      cd gmmlib
      mkdir build && cd build
      cmake ..
      make -j4
      sudo make install
      
    • media-driver

      media-driver download and compile:

      git clone https://github.com/intel/media-driver.git
      mkdir build_media
      cd build_media
      cmake ../media-driver
      make -j4
      sudo make install
      
    • copy Driver iHD_drv_video.so

    Copy driver iHD_drv_video.so from /usr/local/lib/dri/ to /opt/intel/mediasdk/lib.
    bash sudo cp /usr/local/lib/dri/iHD_drv_video.so /opt/intel/mediasdk/lib/

    Set Environment Variables

    bash export MFX_HOME=/opt/intel/mediasdk export LIBVA_DRIVERS_PATH=/opt/intel/mediasdk/lib export LIBVA_DRIVER_NAME=iHD

    Test installation

    In Terminal mit folgendem Befehl testen:
    bash vainfo

    Intel Quick Sync Video

    Intel Quick Sync Video installieren

    MediaSDK backend in OpenCV

    Change OpenCVDetectMediaSDK.cmake

    In OpenCV/cmake/OpenCVDetectMEdiaSDK.cmake line 24:
    find_library(MFX_LIBRARY NAMES mfx PATHS "${root}/lib/${arch}" NO_DEFAULT_PATH)

    "${root}/lib/${arch}" cannot find MFX_LIBRARY.

    To find MFX_LIBRARY change "${root}/lib/${arch}" to "${root}/lib/".

    Cmake Flags

    Use cmake:
    bash cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_MFX=ON ..
    Verify in Buildinformation:
    bash -- Intel Media SDK YES (/opt/intel/mediasdk/lib/libmfx.a)

Privacy Policy