Opencv-python: Can not create x264 VideoWriter

Created on 26 Mar 2018  路  2Comments  路  Source: opencv/opencv-python

Expected behaviour

It would be nice to be able to write x264 (fourcc avc1) video with this opencv install.

Actual behaviour

Currently, I can write mp4v or xvid video but not avc1. The error message is:

[h264_nvenc @ 0x1f159e0] Cannot load libcuda.so.1
Could not open codec 'h264_nvenc': Unspecified error

I don't really know where this libcuda come from.
I tried to install libx264-dev but it did not help.

Steps to reproduce

import cv2
fourcc = cv2.VideoWriter_fourcc(*'avc1')
video = cv2.VideoWriter('test.mp4', fourcc, 30, (1280, 720))
  • ubuntu 16.04
  • x86
  • opencv-python==3.4.0.12

BTW: Thank you so much for this pip package. Not having to build opencv from source is really cool!

Most helpful comment

x264 encoding falls under GPL license in FFmpeg. Only LGPL licensed builds of FFmpeg are redistributed within opencv-python packages and thus the packages support only x264 decoding since the x264 decoder in FFmpeg is LGPL. Unfortunately you have to do a manual build if you wish to use x264 encoder.

Installing libx264-dev will not help. You can't use global system packages with opencv-python, Python's wheel format is self contained and already includes all the necessary dependencies.

All 2 comments

x264 encoding falls under GPL license in FFmpeg. Only LGPL licensed builds of FFmpeg are redistributed within opencv-python packages and thus the packages support only x264 decoding since the x264 decoder in FFmpeg is LGPL. Unfortunately you have to do a manual build if you wish to use x264 encoder.

Installing libx264-dev will not help. You can't use global system packages with opencv-python, Python's wheel format is self contained and already includes all the necessary dependencies.

Ok very clear. Thanks for the info. I'll stick to mp4v.

Was this page helpful?
0 / 5 - 0 ratings