当前位置:网站首页>Save video opencv:: videowriter
Save video opencv:: videowriter
2022-07-02 09:39:00 【Ignorant dream fireworks】
// Video parameters
m_videoInfo.fps = m_capture.get(cv::CAP_PROP_FPS);
m_videoInfo.width = m_capture.get(cv::CAP_PROP_FRAME_WIDTH);
m_videoInfo.height = m_capture.get(cv::CAP_PROP_FRAME_HEIGHT);
// initialization VideoWriter
m_mapVideoWriter[_strVideoName] = cv::VideoWriter(_strVideoName,
cv::VideoWriter::fourcc('X', 'V', 'I', 'D'),
m_videoInfo.fps,
cv::Size(m_videoInfo.width, m_videoInfo.height)
);
// Writing data
for (auto videoWriter : m_mapVideoWriter)
{
videoWriter.second << _mat;
}
Video save results
while(true)
{
for (auto videoWriter : m_mapVideoWriter)
{
videoWriter.second << _mat;
funtion();
}
}
The operation of writing data , Run the following , The premise of saving data is normal ,funtion() The execution time cannot be too long ( The frequency of saving pictures should meet certain requirements ,120ms There will be errors in saving , No other tests ). Upper figure video.mp4 Videos saved for normal ,15_9_36_model_zhiyin.mp4 Results saved for errors , There will be an error in the following figure when opening .
VideoSaveFunTool folders creating , File name splicing class
VideoSaveFunTool.h
#pragma once
/*
Save in video , File path processing class
*/
#ifndef VIDEOSAVEFUNTOOL_H
#define VIDEOSAVEFUNTOOL_H
#include <ctime>
#include <string>
namespace UsbCamera
{
class VideoSaveFunTool
{
public:
VideoSaveFunTool();
void GetSaveVidePath(std::string& _strVideoDir);
private:
std::string GetVideoDir();
bool CreateDir(std::string & _strDir);
void UpdateTime();
std::string m_fileDir;
struct tm* m_pTime; // Storage time , Used to save video files
};
}
#endif // !VIDEOSAVEFUNTOOL_H
VideoSaveFunTool.cpp
#include "VideoSaveFunTool.h"
#include "io.h"
#include <ctime>
#include <direct.h>
#include <iostream>
#include "tinyxml2.h"
namespace UsbCamera
{
#define PATH_DELIMITER '\\'
void VideoSaveFunTool::UpdateTime()
{
time_t nowtime;
time(&nowtime);
// Use this function to get the current system time , To use this function, you need to pass in time_t Type variable nowtime Address value of .
m_pTime = localtime(&nowtime);
m_pTime->tm_year += 1900;
}
bool VideoSaveFunTool::CreateDir(std::string & _strDir)
{
std::string folder_builder;
std::string sub;
sub.reserve(_strDir.size());
for (auto it = _strDir.begin(); it != _strDir.end(); ++it) {
const char c = *it;
sub.push_back(c);
if (c == PATH_DELIMITER || it == _strDir.end() - 1) {
folder_builder.append(sub);
if (0 != ::_access(folder_builder.c_str(), 0)) {
// this folder not exist
if (0 != ::_mkdir(folder_builder.c_str())) {
// create failed
return false;
}
}
sub.clear();
}
}
return true;
}
std::string VideoSaveFunTool::GetVideoDir()
{
// Create a new empty document
tinyxml2::XMLDocument xmlDoc;
// Read the specified xml File and judge whether the reading is successful
tinyxml2::XMLError eResult = xmlDoc.LoadFile("config/VideoFileConfig.cas");
if (eResult != tinyxml2::XML_SUCCESS)
{
printf("error code :%d\n", tinyxml2::XML_ERROR_FILE_NOT_FOUND);
return "";
}
// Get the first node of the file ( The root node )
tinyxml2::XMLNode * pRoot = xmlDoc.FirstChildElement("VideoFileConfig");
if (pRoot == nullptr)
{
printf("error code :%d\n", tinyxml2::XML_ERROR_FILE_READ_ERROR);
return "";
}
else
{
tinyxml2::XMLElement * pVideoDirElement = pRoot->FirstChildElement("VideoDir");
return pVideoDirElement->GetText();
}
}
VideoSaveFunTool::VideoSaveFunTool()
{
m_fileDir = GetVideoDir();
if (m_fileDir == "")
m_fileDir = "D:\\Video";
}
void VideoSaveFunTool::GetSaveVidePath(std::string& _strVideoDir)
{
struct tm time; // Time
std::string filePath; // Saved path
// Update time
UpdateTime();
// Build a storage directory
filePath = m_fileDir + "\\" + std::to_string(m_pTime->tm_year) + "\\" + std::to_string(m_pTime->tm_mon) + "\\"
+ std::to_string(m_pTime->tm_mday);
CreateDir(filePath);
filePath = filePath + "\\" + std::to_string(m_pTime->tm_hour) + "_" + std::to_string(m_pTime->tm_min)
+ "_" + std::to_string(m_pTime->tm_sec);
_strVideoDir = filePath;
}
}
边栏推荐
- Chrome视频下载插件–Video Downloader for Chrome
- Bold prediction: it will become the core player of 5g
- Redis installation and deployment (windows/linux)
- tinyxml2 读取和修改文件
- Amq6126 problem solving ideas
- 三相逆变器离网控制——PR控制
- A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
- 每天睡觉前30分钟阅读_day3_Files
- C语言之做木桶
猜你喜欢
c语言编程题
洞见云原生|微服务及微服务架构浅析
Microservice practice | load balancing component and source code analysis
Say goodbye to 996. What are the necessary plug-ins in idea?
Web security and defense
YOLO物体识别,生成数据用到的工具
定时线程池实现请求合并
Enterprise level SaaS CRM implementation
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
Microservice practice | declarative service invocation openfeign practice
随机推荐
tinyxml2 读取和修改文件
MySQL default transaction isolation level and row lock
What is the function of laravel facade
Demand delineation executive summary
Actual combat of microservices | discovery and invocation of original ecosystem implementation services
自定义Redis连接池
自定義Redis連接池
Required request body is missing:(跨域问题)
QT信号槽总结-connect函数错误用法
大学生四六级作文模板(自创版,成功跨过六级)
TD conducts functional simulation with Modelsim
三相逆变器离网控制——PR控制
2837xd 代码生成——StateFlow(4)
记录一下初次使用Xray的有趣过程
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
互联网API接口幂等设计
Activity的创建和跳转
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
Typora installation package sharing
Ckeditor 4.10.1 upload pictures to prompt "incorrect server response" problem solution