I've had a Python (3.7) app using OpenCV (3.4) for a year or so, working fine. I recently reinstalled Debian Buster, and with it upgraded to OpenCV 4.1. Somewhere in that process I've found that videos which previously worked ok now can't be read by OpenCV.
A sample video with the problem is here: https://www.dropbox.com/s/tu4ddegh6yn05nu/ErrorReadingHeader.mp4?dl=0
Basically, this plays fine in most media apps, but my install of OpenCV won't open it - isOpened() returns false. However, the odd thing is that it's not a constant problem - most of the videos from the same IP camera work fine, but around a quarter can't be read. I assume there's some very minor oddity with the files, but I can't see what it is, and it's hard to get the manufacturer to do much about it because they play fine in most media apps.
When I run cv2.getBuildInformation()
I get the following:
Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (58.35.100)
avformat: YES (58.20.100)
avutil: YES (56.22.100)
swscale: YES (5.3.100)
avresample: NO
GStreamer: YES (1.14.4)
v4l/v4l2: YES (linux/videodev2.h)
After turning on debugging mode (with export OPENCV_LOG_LEVEL=debug
and export OPENCV_VIDEOIO_DEBUG=1
) I get the following when I try to do vc = cv2.VideoCapture('/home/Dave/ErrorReadingHeader.mp4')
:
[ INFO:0] VIDEOIO: Enabled backends(5, sorted by priority): FFMPEG(1000); GSTREAMER(990); V4L2(980); CV_IMAGES(970); CV_MJPEG(960)
[ WARN:0] VIDEOIO(FFMPEG): trying capture filename='/home/Dave/ErrorReadingHeader.mp4' ...
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2338590] error reading header
[ WARN:0] VIDEOIO(FFMPEG): can't create capture
[ WARN:0] VIDEOIO(GSTREAMER): trying capture filename='/home/Dave/ErrorReadingHeader.mp4' ...
[ WARN:0] VIDEOIO(GSTREAMER): can't create capture
[ WARN:0] VIDEOIO(V4L2): trying capture filename='/home/Dave/ErrorReadingHeader.mp4' ...
VIDIOC_REQBUFS: Inappropriate ioctl for device
[ WARN:0] VIDEOIO(V4L2): can't create capture
[ WARN:0] VIDEOIO(CV_IMAGES): trying capture filename='/home/Dave/ErrorReadingHeader.mp4' ...
[ WARN:0] VIDEOIO(CV_IMAGES): created, isOpened=0
[ WARN:0] VIDEOIO(CV_MJPEG): trying capture filename='/home/Dave/ErrorReadingHeader.mp4' ...
[ WARN:0] VIDEOIO(CV_MJPEG): can't create capture
Any thoughts on how to resolve this issue? Keen to understand if this particular video can be opened in other people's installations of OpenCV 4.1, and if so what your VideoIO configuration is.
Thanks a lot!