【发布时间】:2016-08-13 19:45:29
【问题描述】:
我正在开发一个录制视频的 iOS 应用程序,然后对该视频进行一些处理以创建另一个视频文件。我从 videoCapture 得到了非常奇怪的行为。它就像文件已打开,但 get() 调用似乎为我关心的所有属性返回 1(我知道它们不是 1)。我的代码如下所示:
VideoCapture cap(fileIn); // open the video file for reading
if ( !cap.isOpened() ) // if not success, exit program
{
cout << "Cannot open the video file" << endl;
return -1;
}
else{
cout << "File Open " << fileIn << endl;
}
double dFps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
cout << "Frames per second = " << dFps << endl;
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << "Frame Size = " << dWidth << "x" << dHeight << endl;
Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));
double dFrameCount = cap.get(CV_CAP_PROP_FRAME_COUNT);
cout << "Frame count = " << dFrameCount << endl;
VideoWriter oVideoWriter (fileOut, CV_FOURCC('m','p', '4', 'v'), dFps, frameSize, true); //initialize the VideoWriter object
if ( !oVideoWriter.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
{
cout << "ERROR: Failed to write the video" << endl;
return -1;
}
else{
cout << "Output file open." << endl;
}
控制台输出为:
File Open /var/mobile/Containers/Data/Application/7CEE8B87-BD50-4172-8F62-A74AD7F3C45A/Documents/15318B74-07D9-43EE-932F-224EDCA9CDA7.mov
Frames per second = 1
Frame Size = 1x1
Frame count = 1
Output file open.
我尝试将文件路径更改为无效文件,以防它根本没有找到该文件,但这给了我“无法打开视频文件”。任何想法,将不胜感激。我认为这可能是权限问题,因为当我尝试使用此代码访问相机胶卷中的视频时看到了类似的行为,但此文件位于我的应用程序的文档目录中,因此我应该可以完全访问它。
【问题讨论】:
标签: c++ ios opencv video-capture