Add MultiSnapshot

This commit is contained in:
2020-05-11 21:55:34 +02:00
parent ea15817e53
commit 6afdf1a387
21 changed files with 904 additions and 714 deletions
+108 -74
View File
@@ -1,74 +1,108 @@
#include "VStarCamRecorder.h"
#include "Util.h"
#include <HttpClient.h>
#include <Logging.h>
#include <fstream>
#include <sstream>
namespace CameraRecorder {
namespace Recorder {
VStarCamRecorder::VStarCamRecorder(Http::HttpClient* pHttpClient, const Settings& settings) :
m_pHttpClient(pHttpClient),
m_settings(settings)
{
}
VStarCamRecorder::~VStarCamRecorder()
{
}
std::string VStarCamRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
{
Logging::Log(Logging::Severity::Debug, "VStarCamRecorder Snapshot");
std::stringstream url;
url << "http://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << m_settings.Port << "/img/snapshot.cgi?res=0";
std::stringstream fileName;
fileName << m_settings.Path << "/" << m_settings.IpAddress << "/VSTA000000XXXXX_0_" << GetDateTimeString(true);
int i = 0;
while (i < 3)
{
try
{
std::ofstream file(fileName.str() + "_" + std::to_string(i) + ".jpg");
file << m_pHttpClient->GetUrlContents(url.str());
file.close();
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "CameraDevice::PerformVStarCamAction() - Error: " << e.what() << std::endl;
Logging::Log(Logging::Severity::Error, ss.str());
}
++i;
}
return fileName.str() + "_0.jpg";
}
std::string VStarCamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
{
Logging::Log(Logging::Severity::Debug, "VStarCamRecorder Video");
int port = 10554;
std::stringstream url;
url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << port << "/udp/av0_0";
std::stringstream fileName;
fileName << m_settings.Path << "/" << m_settings.IpAddress << "/VSTA000000XXXXX_0_" << GetDateTimeString(true) << ".mp4";
std::stringstream command;
command << ffmpeg << " -i \"" << url.str() << "\" -t 30 -c:v copy -c:a aac -strict experimental " << fileName.str() << " > /dev/null 2>&1";
std::string cmd(command.str());
Logging::Log(Logging::Severity::Debug, cmd);
pThreadPool->push( [cmd](int) { int retval = std::system(cmd.c_str()); } );
return fileName.str();
}
} // namespace Recorder
} // namespace CameraRecorder
#include "VStarCamRecorder.h"
#include "Util.h"
#include <HttpClient.h>
#include <Logging.h>
#include <fstream>
#include <sstream>
namespace CameraRecorder {
namespace Recorder {
VStarCamRecorder::VStarCamRecorder(Http::HttpClient* pHttpClient, const Settings& settings) :
m_pHttpClient(pHttpClient),
m_settings(settings)
{
}
VStarCamRecorder::~VStarCamRecorder()
{
}
std::string VStarCamRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
{
Logging::Log(Logging::Severity::Debug, "VStarCamRecorder Snapshot");
std::string dateTimeString = GetDateTimeString(true);
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
Http::HttpClient* pHttpClient = m_pHttpClient;
Settings settings = m_settings;
pThreadPool->push( [pHttpClient, settings, dateTimeString](int) { VStarCamRecorder::Snapshots(pHttpClient, settings, dateTimeString, 1); } );
return fileName;
}
std::string VStarCamRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages)
{
Logging::Log(Logging::Severity::Debug, "VStarCamRecorder MultiSnapshot");
std::string dateTimeString = GetDateTimeString(true);
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
Http::HttpClient* pHttpClient = m_pHttpClient;
Settings settings = m_settings;
pThreadPool->push( [pHttpClient, settings, dateTimeString, numberOfImages](int) { VStarCamRecorder::Snapshots(pHttpClient, settings, dateTimeString, numberOfImages); } );
return fileName;
}
std::string VStarCamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
{
Logging::Log(Logging::Severity::Debug, "VStarCamRecorder Video");
int port = 10554;
std::stringstream url;
url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << port << "/udp/av0_0";
std::string dateTimeString = GetDateTimeString(true);
std::string fileName = GetFileName(m_settings, "mp4", dateTimeString, 0);
std::stringstream command;
command << ffmpeg << " -i \"" << url.str() << "\" -t 30 -c:v copy -c:a aac -strict experimental " << fileName << " > /dev/null 2>&1";
std::string cmd(command.str());
Logging::Log(Logging::Severity::Debug, cmd);
pThreadPool->push( [cmd](int) { int retval = std::system(cmd.c_str()); } );
return fileName;
}
std::string VStarCamRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString, int imageIndex)
{
filesystem::path fileLocation(settings.Path);
fileLocation = fileLocation / filesystem::path(settings.IpAddress);
std::string fileName = std::string("VSTA000000XXXXX_0_").append(dateTimeString).append("_").append(std::to_string(imageIndex)).append(".").append(extension);
filesystem::path fullFileName = fileLocation / filesystem::path(fileName);
return fullFileName.str();
}
void VStarCamRecorder::Snapshots(Http::HttpClient* pHttpClient, const Settings& settings, std::string dateTimeString, int numberOfImages)
{
for (int i = 0; i < numberOfImages; ++i)
VStarCamRecorder::Snapshot(pHttpClient, settings, VStarCamRecorder::GetFileName(settings, "jpg", dateTimeString, i));
}
void VStarCamRecorder::Snapshot(Http::HttpClient* pHttpClient, const Settings& settings, const filesystem::path& fileName)
{
std::stringstream url;
url << "http://" << settings.Username << ":" << settings.Password << "@" << settings.IpAddress << ":" << settings.Port << "/img/snapshot.cgi?res=0";
try
{
std::ofstream file(fileName.str());
file << pHttpClient->GetUrlContents(url.str());
file.close();
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "VStarCamRecorder::Snapshot() - Error: " << e.what() << std::endl;
Logging::Log(Logging::Severity::Error, ss.str());
}
}
} // namespace Recorder
} // namespace CameraRecorder