From c8ced1a25d36edb1e94e74443e6870fd4e8d6f03 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 1 Nov 2017 15:04:42 +0300 Subject: [PATCH] Added MediaSDK backend usage page --- MediaSDK-encode-decode-backend.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 MediaSDK-encode-decode-backend.md diff --git a/MediaSDK-encode-decode-backend.md b/MediaSDK-encode-decode-backend.md new file mode 100644 index 0000000..49c6eab --- /dev/null +++ b/MediaSDK-encode-decode-backend.md @@ -0,0 +1,31 @@ +### 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: + ```.cpp + cmake -DWITH_MFX=ON + cmake --build . + ``` +### Decoding +Media containers are not supported yet, so it only possible to decode raw video stream stored to a file. It can be done with FFmpeg ([source1](https://stackoverflow.com/questions/19300350/extracting-h264-raw-video-stream-from-mp4-or-flv-with-ffmpeg-generate-an-invalid), [source2](https://superuser.com/questions/678897/extract-hevc-bitstream-with-ffmpeg)): +```.sh +# 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: +```.cpp +VideoCapture cap(“video.264”, CAP_INTEL_MFX); +``` +**Note!** +The file extension is important, because it will be used to [determine](https://github.com/opencv/opencv/blob/ec2409157857a5dabf159e6c052ec001e7110bf5/modules/videoio/src/cap_mfx_reader.cpp#L21-L31) the codec. It can be one of `.264`, `.h264`, `.mp2`, `.mpeg2`, `.265` or `.hevc`. + +### Encoding +Use the _VideoWriter_ object: +```.cpp +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`.