Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv Unable to stop the stream: Inappropriate ioctl for device

I just want to convert video to frame images.

Using this simple code

import cv2
vidcap = cv2.VideoCapture('gog.mp4')
success,image = vidcap.read()
count = 0
success = True
while success:
  success,image = vidcap.read()
  print 'Read a new frame: ', success
  cv2.imwrite("frame%d.jpg" % count, image)
  count += 1

output is

Unable to stop the stream: Inappropriate ioctl for device

I am using python 2.7.6 on ubuntu server.

like image 540
Gor Avatar asked Dec 17 '16 15:12

Gor


1 Answers

I have solved this issue on Ubuntu 16.04.3.

  1. sudo apt-get install ffmpeg
  2. sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev
  3. Rebuild OpenCV 3.3.0 with the following commands:

    • cd build
    • cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_FFMPEG=ON -D WITH_TBB=ON -D WITH_GTK=ON -D WITH_V4L=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -DWITH_QT=OFF -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" ..
    • make -j7
    • sudo make install
like image 148
劉大為 Avatar answered Oct 17 '22 05:10

劉大為