15

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.

Gor
  • 2,808
  • 6
  • 25
  • 46

5 Answers5

11

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
WuerfelDev
  • 140
  • 1
  • 13
劉大為
  • 197
  • 2
  • 5
  • I am also getting same error in c++. I tried all possible solutions,but it didnot work. Can you help – Anirudh Sep 15 '17 at 16:06
2

Hi i also taked this error and solved with this commands.

sudo apt-get install libv4l-dev
cmake -DWITH_LIBV4L=ON .. (this is important)
make && sudo make install

if error occurs with cmake command second one pls install cmake gui.Do first command: sudo apt-get install libv4l-dev Through cmakegui program u can set parameters with CmakeVars.txt file. Edit CmakeVars.txt file exchange WITH_LIBV4L=OFF to WITH_LIBV4L=ON and run make && sudo make install command. For more information about this error visit: https://github.com/opencv/opencv/issues/6157

emre
  • 35
  • 4
  • What directory should cmake be run from? – saulspatz Jan 10 '17 at 20:35
  • @emre, The error you refereed in https://github.com/opencv/opencv/issues/6157 is about "VIDIOC_QUERYCTRL: Inappropriate ioctl for device". It is different from "Unable to stop the stream: Inappropriate ioctl for device". Are you sure they are relevant? – Hong Mar 22 '17 at 19:12
1

I had the exact same issue using Manjaro 17.0.2 and OpenCV 3.2.0 with Java. I removed the old implementation of OpenCV, went and reinstalled it from scratch. Ran cmake with these parameters cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_LIBV4L=ON .. (thanks @emre)

Then in the output of the Cmake installation I noticed Can't find ffmpeg - 'pkg-config' utility is missing. Installed the pkg-config and re ran cmake, make and now everything works.

Ognjen Mišić
  • 1,219
  • 17
  • 37
1

The problem was due to missing ffmpeg and ffmpeg-devel. You can verify this in cmake output.

CMAKE output

If FFMPEG is not available, those YES will become NO. And if you compile and install the opencv without FFMPEG, you will get error "Unable to stop the stream: Inappropriate ioctl for device" for video related samples.

To solve your problem, install ffmpeg and ffmpeg-devel, then "make" and "make install" again.

Hope this helps.

Stanley Yong
  • 1,844
  • 1
  • 12
  • 7
0

I use Linux Mint, and programming in C++. I apply the same procedure of https://stackoverflow.com/a/45893821/11247666. This is:

sudo apt-get install ffmpeg
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev
cd opencv-3.3.0
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

But after this. The problem was cannot be solved. I have this error:

Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow.

I apply the following

sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config

After this, I applied this same procedure:

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

The above worked for me.

adrtam
  • 6,991
  • 2
  • 12
  • 27