尝试使用 OpenCV 写入视频文件
我正在尝试使用 OpenCV 编写视频文件。我有一个简单的程序,它从视频文件加载帧,然后接受保存它们。
首先,cvCreateVideoWrite 总是返回 NULL。我从你们的小组得到答复说它返回单独的图像并尝试将文件名更改为 test0001.png,这有效。
但现在cvWriteFrame函数总是失败,代码是
CString path;
path="d:\\mice\\Test_Day26_2.avi";
CvCapture* capture = cvCaptureFromAVI(path);
IplImage* img = 0;
CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 25; // or 30
int frameW = 640; // 744 for firewire cameras
int frameH = 480; // 480 for firewire cameras
writer=cvCreateVideoWriter("d:\\mice\\test0001.png",CV_FOURCC('P','I','M','1'),
fps,cvSize(frameW,frameH),isColor);
if (writer==0)
MessageBox("could not open writter");
int nFrames = 50;
for(int i=0;i<nFrames;i++){
if (!cvGrabFrame(capture))
MessageBox("could not grab frame");
img=cvRetrieveFrame(capture); // retrieve the captured frame
if (img==0)
MessageBox("could not retrive data");
if (!cvWriteFrame(writer,img) )
MessageBox("could not write frame");
}
cvReleaseVideoWriter(&writer);
I’m trying to use OpenCV to write a video file. I have a simple program that loads frames from a video file then accepts to save them
At first the cvCreateVideoWrite always return NULL. I got a answer from your group saying it returns separate images and to try to change the file name to test0001.png, this worked.
But now the cvWriteFrame function always fails, the code is
CString path;
path="d:\\mice\\Test_Day26_2.avi";
CvCapture* capture = cvCaptureFromAVI(path);
IplImage* img = 0;
CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 25; // or 30
int frameW = 640; // 744 for firewire cameras
int frameH = 480; // 480 for firewire cameras
writer=cvCreateVideoWriter("d:\\mice\\test0001.png",CV_FOURCC('P','I','M','1'),
fps,cvSize(frameW,frameH),isColor);
if (writer==0)
MessageBox("could not open writter");
int nFrames = 50;
for(int i=0;i<nFrames;i++){
if (!cvGrabFrame(capture))
MessageBox("could not grab frame");
img=cvRetrieveFrame(capture); // retrieve the captured frame
if (img==0)
MessageBox("could not retrive data");
if (!cvWriteFrame(writer,img) )
MessageBox("could not write frame");
}
cvReleaseVideoWriter(&writer);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
CV_FOURCC('D', 'I', 'V', 'X')
,CV_FOURCC('f', 'f', 'd', 's')
code>(使用*.avi
文件名)或CV_FOURCC_DEFAULT
(使用*.mpg
)。 opencv中视频写的还是比较乱>>_>Try
CV_FOURCC('D', 'I', 'V', 'X')
,CV_FOURCC('f', 'f', 'd', 's')
(with*.avi
filename) orCV_FOURCC_DEFAULT
(with*.mpg
). Video writing is still quite messy in opencv >_>我在 OpenCV 中也看到了许多编写视频的问题。我发现英特尔 iYUV 格式非常适合我的需要。
I've seen many issues with writing video as well in OpenCV. I found intel iYUV format worked well for what I needed.
您的库是使用定义的
HAVE_FFMPEG
构建的吗?如果不是,您可能需要使用该选项重新编译 opencv。您应该在配置步骤中看到类似这样的内容:
如果您没有 ffmpeg,您可以从 此处。
Was your library built with
HAVE_FFMPEG
defined?If it wasn't,you might need to recompile opencv with that option.You should see something like this in the configure step:
If you don't have ffmpeg,you can get it from here.