I'm trying to read the frames of an .mov file using OpenCV 3.2 (from the menpo conda channel). I'm using Python 3.5.3 through Anaconda on an Ubuntu 16.04 64-bit setup.
Problem is, I get the following error message from OpenCV when it hits the cap.read()
call, and the loop immediately breaks and catches the if num == 0
conditional.
Here's the entirety of the code I'm running:
import cv2
import numpy as np
import sys
f = sys.argv[1]
cap = cv2.VideoCapture(f)
frames = []
num = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret: break
gframe = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frames.append(gframe)
num += 1
if num % 100 == 0:
frames.append(gframe)
if num % 1000 == 0:
print(num)
if num == 0:
print("Something went wrong: no frames found.")
exit(0)
cap.release()
user@ubuntu:/data$ python read.py movie.mov
Unable to stop the stream: Inappropriate ioctl for device
Something went wrong: no frames found.
user@ubuntu:/data$
I've found a couple of other StackOverflow questions on this topic, but they don't quite translate to my exact circumstance:
- This question proposes rebuilding OpenCV (also uses Python 2). That's not an option for me, as I'm trying to do this with Anaconda.
- These two questions (here and here) on the OpenCV forums were left without any satisfactory answers.
- This one has a lively discussion and a thorough answer, but it's specific to perl.
To that third point--there are quite a few other questions here that have the quote inappropriate ioctl for device
but it's hard to see if any of them is directly relevant to this problem.
As a partial aside: I've installed this exact same opencv3 conda package on my macOS machine, and the code I've pasted here works just fine and on exactly the same .mov file I've tried on the Ubuntu machine.
Any ideas?