Skip to content

MediaSDK encode decode backend

Maksim Shabunin edited this page Nov 1, 2017 · 3 revisions
Clone this wiki locally

Building OpenCV with MediaSDK support

  1. Install MediaSDK
  2. Make sure corresponding environment variable is set, Windows: INTELMEDIASDKROOT, Linux: MFX_HOME
  3. Build with -DWITH_MFX option turned on:
    cmake -DWITH_MFX=ON <path-to-opencv-sources>
    cmake --build .

Decoding

Media containers are not supported yet, so it is only possible to decode raw video stream stored in a file. It can be extracted from a container manually using the FFmpeg tool (source1, source2) or any other tools:

# H264
ffmpeg -i video.avi -vcodec copy -an -bsf:v h264_mp4toannexb video.264
# H265
ffmpeg -i in.mkv -c:v copy -bsf hevc_mp4toannexb out.h265

Then you can use VideoCapture object to decode the resulting file:

VideoCapture cap(“video.264”, CAP_INTEL_MFX);

Note! The file extension is important, because it will be used to determine the codec. It can be one of .264, .h264, .mp2, .mpeg2, .265 or .hevc.

Encoding

Use the VideoWriter object:

int fourcc = VideoWriter::fourcc('H', '2', '6', '4');
VideoWriter writer(filename, CAP_INTEL_MFX, fourcc, fps, frameSize, isColor);

Where fourcc can be one of MPG2, H264, X264, AVC , H265 or HEVC.