Python opencv 无法停止流:设备的 ioctl 不合适
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41200201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
opencv Unable to stop the stream: Inappropriate ioctl for device
提问by Gor
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
无法停止流:设备的 ioctl 不合适
I am using python 2.7.6 on ubuntu server.
我在 ubuntu 服务器上使用 python 2.7.6。
回答by u4036972
I have solved this issue on Ubuntu 16.04.3.
我已经在 Ubuntu 16.04.3 上解决了这个问题。
sudo apt-get install ffmpeg
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev
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
sudo apt-get install ffmpeg
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev
使用以下命令重建 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
回答by emre
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
如果第二个cmake命令出现错误,请安装cmake gui。执行第一个命令:sudo apt-get install libv4l-dev
通过cmakegui程序,您可以使用CmakeVars.txt文件设置参数。编辑 CmakeVars.txt 文件将 WITH_LIBV4L=OFF 改为 WITH_LIBV4L=ON 并运行make && sudo make install
命令。有关此错误的更多信息,请访问:https: //github.com/opencv/opencv/issues/6157
回答by Ognjen Mi?i?
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)
我在使用 Manjaro 17.0.2 和 OpenCV 3.2.0 和 Java 时遇到了完全相同的问题。我删除了旧的 OpenCV 实现,然后从头开始重新安装它。使用这些参数运行 cmake cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_LIBV4L=ON ..
(感谢 @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.
然后在 Cmake 安装的输出中,我注意到Can't find ffmpeg - 'pkg-config' utility is missing
. 安装 pkg-config 并重新运行 cmake、make,现在一切正常。
回答by Stanley Yong
The problem was due to missing ffmpeg and ffmpeg-devel. You can verify this in cmake output.
问题是由于缺少 ffmpeg 和 ffmpeg-devel。您可以在 cmake 输出中验证这一点。
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.
如果 FFMPEG 不可用,那些 YES 将变为 NO。如果您在没有 FFMPEG 的情况下编译和安装 opencv,对于视频相关示例,您将收到错误“无法停止流:设备的 ioctl 不合适”。
To solve your problem, install ffmpeg and ffmpeg-devel, then "make" and "make install" again.
要解决您的问题,请安装 ffmpeg 和 ffmpeg-devel,然后再次“make”和“make install”。
Hope this helps.
希望这可以帮助。
回答by Jorge Daniel Aguilar Orozco
I use Linux Mint, and programming in C++. I apply the same procedure of https://stackoverflow.com/a/45893821/11247666. This is:
我使用 Linux Mint,并用 C++ 编程。我应用了https://stackoverflow.com/a/45893821/11247666的相同程序。这是:
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.
未指定错误(该功能未实现。使用 Windows、GTK+ 2.x 或 Carbon 支持重建库。如果您使用的是 Ubuntu 或 Debian,请安装 libgtk2.0-dev 和 pkg-config,然后重新运行 cmake 或配置脚本) 在 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.
以上对我有用。