opencv-python: Bug: https URL not working with opencv-python
Bug summary:
opencv-contrib-python
python library’s VideoCapture
class fails to parse https URL received from pafy/youtube-dl
. But strangely this bug doesn’t exist on same/different machine with OpenCV installed from scratch.
Affected users:
Users with OpenCV installed with opencv-contrib-python
or opencv-python
python library from PyPi
Non-Affected users:
Users with OpenCV installed from scratch/source-code and not from PyPi (Tested with OpenCV 4.1.0-dev & 3.4.5)
Steps to reproduce
- operating system -
Ubuntu 18.04.1 bionic
- architecture
x64
- opencv-python
4.1.0.25
- youtube-dl
2019.5.20
- pafy
0.5.4
- python_version
3.6/2.7/3.5 tested
Test-Code:
You can copy url
directly to cv2.VideoCapture
class and this result in same Bug.
import cv2
import pafy
video = pafy.new("dQw4w9WgXcQ")
object = video.getbestvideo()
url = object.url
print(url) #means pafy and youtube-dl working correctly
stream = cv2.VideoCapture(url)
# infinite loop
while True:
(grabbed, frame) = stream.read()
# read frames
# check if frame empty
if not grabbed:
print('opencv is buggy')
break
cv2.imshow("Output Frame", frame)
# Show output window
key = cv2.waitKey(1) & 0xFF
# check for 'q' key-press
if key == ord("q"):
#if 'q' key-pressed break out
break
cv2.destroyAllWindows()
# close output window
stream.release()
# safely close video stream.
This code exit instantly with no error on opencv-python 4.1.0.25
since no frame grabbed BUT instead this algorithm works when OpenCV installed from scratch and returns valid frames.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 18 (16 by maintainers)
Commits related to this issue
- Added OpenSSL & different protocol support to FFmpeg backend - Fixed Docker dependencies (both x86 & x86-64) - Fixes bug #204 — committed to abhiTronix/opencv-python by abhiTronix 5 years ago
- Added OpenSSL & various protocol support to FFmpeg backend (#229) * Added OpenSSL & different protocol support to FFmpeg backend - Fixed Docker dependencies (both x86 & x86-64) - Fixes bug #204 ... — committed to opencv/opencv-python by abhiTronix 5 years ago
- Added OpenSSL & various protocol support to FFmpeg backend (#229) * Added OpenSSL & different protocol support to FFmpeg backend - Fixed Docker dependencies (both x86 & x86-64) - Fixes bug #204 ... — committed to opencv/opencv-python by abhiTronix 5 years ago
Actually, the complete opposite:
However, despite
openssl
marked nonfree inconfigure
logic, https://github.com/FFmpeg/FFmpeg/blob/master/LICENSE.md#incompatible-libraries claims:git blame
’ingconfigure
shows thatopenssl
has been marked nonfree since its adoption and there are no explanation of the reason. I believe this may have been done to discourage users from choosing these “problematic” libraries over freer alternatives – in particular, to remove any technical roadblocks to using GPLed parts.Whatever is the case, GNU TLS (LGPL) should work as an alternative.
@abhiTronix , it is not related, that issue is caused by very long string incorrectly processed by built-in CAP_IMAGES backend.
If there are GPL’ed components I would have to re-license the whole package under GPL license and any package using opencv-python, respectively, would have to be licensed under GPL. This would also mean that this package or any package which uses opencv-python could not be used for commercial purposes / proprietary applications.
I have to re-buid the Docker images and check if this problem is present also on macOS. I cannot give any timetable when this will happen. Please note that this is not a bug. This is a feature request. If you wish to speed up the process, you can try to enable the SSL support in FFmpeg builds locally in the Docker images, build a opencv-python wheel and test if the solution works.
The issue is not GStreamer but FFmpeg. It’s most likely compiled without https support or some other build flag is missing and therefore it cannot open Youtube video streams.
Your script works under Windows which confirms that this is related to FFmpeg build time configuration. To see the FFmpeg build flags check out the Dockerfiles: https://github.com/skvark/opencv-python/blob/master/docker/Dockerfile_x86_64
@abhiTronix
cv2
installed usingpip install opencv-python
fail to load any http videos but works when I installed it from scratch. The.getBuildInformation()
printout of my workingcv2
installation has no GStreamer.