Add MultiSnapshot
This commit is contained in:
+118
-71
@@ -1,71 +1,118 @@
|
||||
#include "FoscamRecorder.h"
|
||||
#include "Util.h"
|
||||
#include <HttpClient.h>
|
||||
#include <Logging.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
|
||||
namespace CameraRecorder {
|
||||
namespace Recorder {
|
||||
|
||||
FoscamRecorder::FoscamRecorder(Http::HttpClient* pHttpClient, const Settings& settings) :
|
||||
m_pHttpClient(pHttpClient),
|
||||
m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
FoscamRecorder::~FoscamRecorder()
|
||||
{
|
||||
}
|
||||
|
||||
std::string FoscamRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "FoscamRecorder Snapshot");
|
||||
std::stringstream url;
|
||||
url << "http://" << m_settings.IpAddress << ":" << m_settings.Port << "/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=" << m_settings.Username << "&pwd=" << m_settings.Password;
|
||||
|
||||
std::stringstream fileName;
|
||||
fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".jpg";
|
||||
|
||||
try
|
||||
{
|
||||
std::ofstream file(fileName.str());
|
||||
file << m_pHttpClient->GetUrlContents(url.str());
|
||||
file.close();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "CameraDevice::PerformFoscamAction() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return fileName.str();
|
||||
}
|
||||
|
||||
std::string FoscamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "FoscamRecorder Video");
|
||||
int port = 65534;
|
||||
|
||||
std::stringstream url;
|
||||
url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << port << "/videoSub";
|
||||
|
||||
std::stringstream fileName;
|
||||
fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".mp4";
|
||||
|
||||
std::stringstream command;
|
||||
command << ffmpeg << " -i \"" << url.str() << "\" -t 30 -c:v copy -an -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 "FoscamRecorder.h"
|
||||
#include "Util.h"
|
||||
#include <HttpClient.h>
|
||||
#include <JpegImageCollection.h>
|
||||
#include <Logging.h>
|
||||
#include <filesystem/path.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
|
||||
namespace CameraRecorder {
|
||||
namespace Recorder {
|
||||
|
||||
FoscamRecorder::FoscamRecorder(Http::HttpClient* pHttpClient, const Settings& settings) :
|
||||
m_pHttpClient(pHttpClient),
|
||||
m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
FoscamRecorder::~FoscamRecorder()
|
||||
{
|
||||
}
|
||||
|
||||
std::string FoscamRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "FoscamRecorder Snapshot");
|
||||
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString);
|
||||
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
Settings settings = m_settings;
|
||||
pThreadPool->push( [pHttpClient, settings, dateTimeString](int) { FoscamRecorder::Snapshots(pHttpClient, settings, dateTimeString, 1); } );
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
std::string FoscamRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "FoscamRecorder MultiSnapshot");
|
||||
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString);
|
||||
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
Settings settings = m_settings;
|
||||
pThreadPool->push( [pHttpClient, settings, dateTimeString, numberOfImages](int) { FoscamRecorder::Snapshots(pHttpClient, settings, dateTimeString, numberOfImages); } );
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
std::string FoscamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "FoscamRecorder Video");
|
||||
int port = 65534;
|
||||
|
||||
std::stringstream url;
|
||||
url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << port << "/videoSub";
|
||||
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "mp4", dateTimeString);
|
||||
|
||||
std::stringstream command;
|
||||
command << ffmpeg << " -i \"" << url.str() << "\" -t 30 -c:v copy -an -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 FoscamRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString)
|
||||
{
|
||||
filesystem::path fileLocation(settings.Path);
|
||||
fileLocation = fileLocation / filesystem::path(settings.IpAddress);
|
||||
|
||||
std::string fileName = std::string(dateTimeString).append(".").append(extension);
|
||||
filesystem::path fullFileName = fileLocation / filesystem::path(fileName);
|
||||
|
||||
return fullFileName.str();
|
||||
}
|
||||
|
||||
void FoscamRecorder::Snapshots(Http::HttpClient* pHttpClient, const Settings& settings, std::string dateTimeString, int numberOfImages)
|
||||
{
|
||||
std::vector<Image::JpegImage> images;
|
||||
|
||||
for (int i = 0; i < numberOfImages; ++i)
|
||||
images.push_back(FoscamRecorder::Snapshot(pHttpClient, settings));
|
||||
|
||||
Image::JpegImageCollection collection(images);
|
||||
collection.Save(FoscamRecorder::GetFileName(settings, "jpg", dateTimeString));
|
||||
}
|
||||
|
||||
Image::JpegImage FoscamRecorder::Snapshot(Http::HttpClient* pHttpClient, const Settings& settings)
|
||||
{
|
||||
std::stringstream url;
|
||||
url << "http://" << settings.IpAddress << ":" << settings.Port << "/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=" << settings.Username << "&pwd=" << settings.Password;
|
||||
|
||||
Image::JpegImage image;
|
||||
|
||||
try
|
||||
{
|
||||
image.SetImageData(pHttpClient->GetUrlContents(url.str()));
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "FoscamRecorder::Snapshot() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
} // namespace Recorder
|
||||
} // namespace CameraRecorder
|
||||
|
||||
Reference in New Issue
Block a user