使用opencv统计视频库的总时长
2013-10-21 08:55
239 查看
统计视频库里的视频文件的总时长
废话不多说,直接上代码:
废话不多说,直接上代码:
/* * ===================================================================================== * * Filename: count_the_vedeo_time.cpp * Environment: * Description: 用于计算视频文件列表里的视频文件各个时长及其总和,用于统计视频数据库的时长 * * * Version: 1.0 * Created: 2013/10/21 8:50:09 * Author: yuliyang I* * Mail: wzyuliyang911@gmail.com * Blog: http://www.cnblogs.com/yuliyang * * ===================================================================================== */ #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream> #include "fstream" using namespace std; using namespace cv; int main(int args,char* argv[]) { string buf; ifstream svm_data(argv[1]); /*读入视频文件列表 */ ofstream result(argv[2]); /* 保存结果文件 */ double sum=0; while (svm_data) { if (getline(svm_data,buf)) { result<<"计算视频"<<buf.c_str()<<"的时长"<<endl; //打开视频文件:其实就是建立一个VideoCapture结构 VideoCapture capture(buf.c_str()); //检测是否正常打开:成功打开时,isOpened返回ture if(!capture.isOpened()) result<<"fail to open!"<<endl; //获取整个帧数 double totalFrameNumber = capture.get(CV_CAP_PROP_FRAME_COUNT); //获取帧率 double rate = capture.get(CV_CAP_PROP_FPS); double vedio_time= totalFrameNumber/rate; result<<"该个视频共"<<totalFrameNumber<<"帧,"<<"帧率为:"<<rate<<"该视频时长为:"<<vedio_time<<" s"<<endl; capture.release(); sum +=vedio_time; } } result<<"视频时长总和为:"<<sum/60<<"mins"<<endl; result.close(); return 0; }
相关文章推荐
- learn opencv-使用OpenCV(C ++ / Python)读取,写入和显示视频
- opencv读取视频使用ssd处理定位类别并将处理后类别存储起来
- 使用自动化测试专项性能----对不同时长视频导出不同规格的耗时数据统计
- 使用opencv默认的hog行人检测器来检测视频中的行人
- Linux下使用QT调用opencv读取摄像头视频 调试心得
- OpenCV使用VideoInput库从摄像头捕获视频
- OpenCV 视频人数统计研究 .
- Qt5.3里使用OpenCV库采集摄像头图像保存为图片和视频
- 使用opencv在Qt中实现卡通化视频处理
- 使用opencv把图片拼接成视频
- [置顶] 完整VS2010中使用MFC+Opencv设计视频读取(有代码和相关解析)
- 使用opencv进行多路视频的播放
- Ogre中使用Opencv加载视频作为纹理贴图
- 【OpenCV开发】OpenCV:使用VideoCapture类进行视频读取和显示
- Ogre中使用Opencv加载视频作为纹理贴图
- 使用Opencv调用摄像头并在MFC中进行视频显示
- 使用openCV进行视频拼接
- vs2015使用OpenCV录制视频的一些总结(一)
- 视频人数统计(opencv)