1

I'm trying to open a videoURL using cv2.VideoCapture on Heroku, and it consistently fails to open. I've called the same code on my local machine (Windows 10) and it ran with no problems. Does anyone have recommendations/buildpacks/alternatives to resolve this?

OpenCV Version: 3.4.2.16

Python: 3.7

Current Buildpacks:

Open Cv Build info (Video) from the Heroku Dyno

Video I/O:
DC1394:                      NO
FFMPEG:                      YES
  avcodec:                   YES (ver 58.21.104)
  avformat:                  YES (ver 58.17.101)
  avutil:                    YES (ver 56.18.102)
  swscale:                   YES (ver 5.2.100)
  avresample:                NO
GStreamer:                   NO
libv4l/libv4l2:              NO
v4l/v4l2:                    linux/videodev.h linux/videodev2.h
gPhoto2:                     NO

Edit: we're trying to use the code below to open the video

cap = cv.VideoCapture(video_url) #get video
print(cap.isOpened())

With this code, we've noticed that the print statement consistently says 'False' when using a URL similar to one provided by youtubeDL.

Bowen Xu
  • 13
  • 3
  • Please define "fail to open". What is the error message you are getting on Heroku? Please also provide your source code that illustrates the problem. Your question is at the risk of being closed as none of us can reproduce your problem. To improve this, please take the [tour] and please visit [ask]. – rayryeng Aug 09 '20 at 00:03
  • @rayryeng Please see the edited changes. – Bowen Xu Aug 09 '20 at 00:29

1 Answers1

0

My apologies for the delay. I am assuming you are using pip to install OpenCV. The answer to your question is that for OpenCV 3.x, Mac OS and Linux (and ultimately the environment that Heroku is run under) do not link with FFMPEG which means that video support is not enabled for those platforms. However, it is enabled with Windows. This is the reason why there is an inconsistency between the platforms: What is the deal with `pip install opencv-python` is it a full opencv?

The solution is you will either need to build OpenCV 3.x from source, or use OpenCV 4 which now bundles FFMPEG with it. I would highly recommend you use OpenCV 4 unless there is something blocking you from using it. However to install OpenCV 4, use either pip install --upgrade opencv-python or pip install --upgrade opencv-contrib-python. I'm not sure which flavour you are using, but either one should work.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • 1
    Thanks a bunch Ray! Using OpenCV 4 fixed it. – Bowen Xu Aug 16 '20 at 07:52
  • No problem at all. If this issue has been resolved, please consider accepting this answer to let the community know you no longer need help. That can be done by clicking on the checkmark icon at the top of my post, to the left underneath the up and down voting buttons. Welcome to our community! – rayryeng Aug 16 '20 at 08:07