[英]OpenCV VideoCapture says video has 0 frames (C++ and Python)
I'm using OpenCV 2.4.9 and trying to open a video. 我正在使用OpenCV 2.4.9并尝试打开视频。
isOpened()
successfully runs, but when I try to look at the number of frames the video has, it returns 0, and I can't access the frames of the video. isOpened()
成功运行,但是当我尝试查看视频的帧数时,它返回0,我无法访问视频的帧。 This happens with every video I have. 我的每个视频都会发生这种情况。 I can use the same videos on a different machine (the issue happens in my CentOS 7 VM, the videos are in a shared folder and the host OS can access them fine in OpenCV).
我可以在不同的机器上使用相同的视频(问题发生在我的CentOS 7 VM中,视频位于共享文件夹中,主机操作系统可以在OpenCV中正常访问它们)。 Ffmpeg is installed and I can
ffplay
the videos and ffmpeg -i
tells me the videos have a nonzero number of frames. Ffmpeg已安装,我可以
ffplay
视频, ffmpeg -i
告诉我视频的帧数非零。 My OpenCV was compiled with ffmpeg successfully: 我的OpenCV成功编译为ffmpeg:
" Video I/O:\n"
" DC1394 1.x: NO\n"
" DC1394 2.x: YES (ver 2.2.2)\n"
" FFMPEG: YES\n"
" codec: YES (ver 56.26.100)\n"
" format: YES (ver 56.25.101)\n"
" util: YES (ver 54.20.100)\n"
" swscale: YES (ver 3.1.101)\n"
" gentoo-style: YES\n"
" GStreamer: \n"
" base: YES (ver 0.10.36)\n"
" app: YES (ver 0.10.36)\n"
" video: YES (ver 0.10.36)\n"
" OpenNI: NO\n"
" OpenNI PrimeSensor Modules: NO\n"
" PvAPI: NO\n"
" GigEVisionSDK: NO\n"
" UniCap: NO\n"
" UniCap ucil: NO\n"
" V4L/V4L2: Using libv4l (ver 0.9.5)\n"
" XIMEA: NO\n"
" Xine: NO\n"
"\n"
My code correctly compiles and I can read images with OpenCV. 我的代码正确编译,我可以使用OpenCV读取图像。
The code is incredibly basic. 代码非常基本。 For Python:
对于Python:
import cv2
cap = cv2.VideoCapture('test.mp4')
print cap.isOpened()
print cap.get(cv2.cv.CV_CAP_PROP_FPS)
print cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)
>> True
>> 0.0
>> 0
And for C++: 而对于C ++:
#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <stdlib.h>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
cv::VideoCapture cap;
cap.open("test.mp4");
if(cap.isOpened())
{
cout >> cap.get(CV_CAP_PROP_FPS) >> endl;
cout >> cap.get(CV_CAP_PROP_FRAME_COUNT) >> endl;
}
return(0);
}
Which prints 0 as well. 其中也打印0。
This looks similar to the codec issues I had, and described in this stack overflow post . 这看起来类似于我的编解码器问题,并在此堆栈溢出帖子中进行了描述。 In short: I used
ffmpeg
to convert the video: 简而言之:我使用
ffmpeg
转换视频:
ffmpeg -i input.avi -c:v libx264 -vf format=yuv420p output.mp4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.