title: OpenCV3 error: "Unable to stop the stream: Inappropriate ioctl for device"
body: <p>I'm trying to read the frames of an .mov file using OpenCV 3.2 (from the <a href="https://anaconda.org/menpo/opencv3" rel="nofollow noreferrer">menpo conda channel</a>). I'm using Python 3.5.3 through Anaconda on an Ubuntu 16.04 64-bit setup.</p>
  
  <p>Problem is, I get the following error message from OpenCV when it hits the <code>cap.read()</code> call, and the loop immediately breaks and catches the <code>if num == 0</code> conditional.</p>
  
  <p>Here's the entirety of the code I'm running:</p>
  
  <pre><code>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()
  </code></pre>
  
  <p><code><pre>
  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$
  </pre></code></p>
  
  <p>I've found a couple of other StackOverflow questions on this topic, but they don't quite translate to my exact circumstance:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/41200201/opencv-unable-to-stop-the-stream-inappropriate-ioctl-for-device">This question</a> proposes rebuilding OpenCV (also uses Python 2). That's not an option for me, as I'm trying to do this with Anaconda.</li>
  <li>These two questions (<a href="http://answers.opencv.org/question/99659/videocapture-problem-inappropriate-ioctl-for-device/" rel="nofollow noreferrer">here</a> and <a href="http://answers.opencv.org/question/117110/netcat-stream-on-devstdin-not-working-with-opencv-310-dev-on-ubuntu-1604/" rel="nofollow noreferrer">here</a>) on the OpenCV forums were left without any satisfactory answers.</li>
  <li><a href="https://stackoverflow.com/questions/1605195/inappropriate-ioctl-for-device">This one</a> has a lively discussion and a thorough answer, but it's specific to perl.</li>
  </ul>
  
  <p>To that third point--there are quite a few other questions here that have the quote <code>inappropriate ioctl for device</code> but it's hard to see if any of them is directly relevant to this problem.</p>
  
  <p>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.</p>
  
  <p>Any ideas?</p>