Writing X264 from Opencv 3 with Ffmpeg on Linux

Writing x264 from OpenCV 3 with FFmpeg on Linux

The problem had nothing to do with the displayed warning. I was trying to write single-channel images, while the VideoWriter was expecting a 3-channel color image (default value of isColor, the 5-th argument to VideoWriter's constructor, is "true"). The solution was setting isColor to false.

openCV - ffmpeg H264 and Webm error

Thanks for the answer I fixed the issue by using multi threading. Since write method takes more time, during that time the opencv might miss the reference frame so I used seperate thread for read and write. Then used to queue to store the images before writing to disk.

OpenCV encoding to H264

To answer my own question - thank you for the previous suggestions though - I've managed to create and write frames to H264 video now, without any recompiling needed. This is what I've used:

  • Using OpenCV version 3.4.1
  • In the same folder as the exe: opencv_ffmpeg341_64.dll (provided with OpenCV)
  • In the same folder: openh264-1.7.0-win64.dll (available from: https://github.com/cisco/openh264/releases)
  • Use OpenCV VideoWriter class, omitting a specific encoding API
  • Container: MP4
  • Codec fourcc string: "H264"

I formatted my machine (Windows 10 64bit) so I can't exclude any issues with potential codec-clashing - also I have not fully tested for other combinations. As this appears to be such a common problem (with many misconceptions) I hope this is useful.

Save video in opencv with H264 codec

Finally, I found the solution. I can solve my problem in the ubuntu:20.04 docker. The important thing you should notice is that you should install OpenCV via apt-get install python3-opencv not using pip.

Writing a video with H.264 in OpenCV with High profile from a high profile mp4 file

You would need to pass parameters through OpenCV, to ffmpeg and libx264.

As far as I can tell from official documentation, OpenCV doesn't support that.

However, the source contains access to the environment variable OPENCV_FFMPEG_WRITER_OPTIONS

You should be able to pass parameters like you would give them to ffmpeg, except the syntax is a little weird (semicolon between key and value, pipe between pairs).

Here is some talk of such facilities:

  • https://github.com/opencv/opencv/issues/6342
  • https://github.com/opencv/opencv/pull/9292

You should pass avc1 as fourcc. AFAIK that's the fourcc defined by standards. It does not however guarantee that you get libx264, only that you get some encoder for AVC.

I've opened an issue for this. Documentation issues are always a nice way for newbies to get their feet wet contributing to an open source project.



Related Topics



Leave a reply



Submit