Add MultiSnapshot
This commit is contained in:
@@ -46,11 +46,17 @@ std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClien
|
||||
settings.Username = uriTokens[5];
|
||||
settings.Password = uriTokens[6];
|
||||
|
||||
int numberOfImages = 5;
|
||||
if (uriTokens.size() > 7)
|
||||
numberOfImages = stoi(uriTokens[7]);
|
||||
|
||||
if (StringAlgorithm::iequals("Digoo", brand))
|
||||
{
|
||||
auto recorder = Recorder::DigooRecorder(pHttpClient, settings);
|
||||
if (StringAlgorithm::iequals("Snapshot", action))
|
||||
output = recorder.Snapshot(pThreadPool);
|
||||
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
||||
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
||||
else if (StringAlgorithm::iequals("Video", action))
|
||||
output = recorder.Video(pThreadPool, ffmpeg);
|
||||
}
|
||||
@@ -59,6 +65,8 @@ std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClien
|
||||
auto recorder = Recorder::FoscamRecorder(pHttpClient, settings);
|
||||
if (StringAlgorithm::iequals("Snapshot", action))
|
||||
output = recorder.Snapshot(pThreadPool);
|
||||
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
||||
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
||||
else if (StringAlgorithm::iequals("Video", action))
|
||||
output = recorder.Video(pThreadPool, ffmpeg);
|
||||
}
|
||||
@@ -67,6 +75,8 @@ std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClien
|
||||
auto recorder = Recorder::VStarCamRecorder(pHttpClient, settings);
|
||||
if (StringAlgorithm::iequals("Snapshot", action))
|
||||
output = recorder.Snapshot(pThreadPool);
|
||||
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
||||
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
||||
else if (StringAlgorithm::iequals("Video", action))
|
||||
output = recorder.Video(pThreadPool, ffmpeg);
|
||||
}
|
||||
@@ -75,6 +85,8 @@ std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClien
|
||||
auto recorder = Recorder::WatchBotRecorder(pHttpClient, settings);
|
||||
if (StringAlgorithm::iequals("Snapshot", action))
|
||||
output = recorder.Snapshot(pThreadPool);
|
||||
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
||||
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
||||
else if (StringAlgorithm::iequals("Video", action))
|
||||
output = recorder.Video(pThreadPool, ffmpeg);
|
||||
}
|
||||
@@ -83,6 +95,8 @@ std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClien
|
||||
auto recorder = Recorder::ZModoRecorder(pHttpClient, settings);
|
||||
if (StringAlgorithm::iequals("Snapshot", action))
|
||||
output = recorder.Snapshot(pThreadPool);
|
||||
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
||||
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
||||
else if (StringAlgorithm::iequals("Video", action))
|
||||
output = recorder.Video(pThreadPool, ffmpeg);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <Logging.h>
|
||||
#include <HttpClient.h>
|
||||
#include <HttpServer.h>
|
||||
#include <filesystem/path.h>
|
||||
#include <functional>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -27,17 +28,20 @@ int main(int argc, char** argv)
|
||||
if (port == 0)
|
||||
throw std::runtime_error("Port directive missing in ini file.");
|
||||
|
||||
std::string path = iniReader.Get("CameraRecorder", "Path", "");
|
||||
if (path.empty())
|
||||
std::string pathString = iniReader.Get("CameraRecorder", "Path", "");
|
||||
if (pathString.empty())
|
||||
throw std::runtime_error("Path directive missing in ini file.");
|
||||
|
||||
std::string ffmpeg = iniReader.Get("CameraRecorder", "FFMPEG", "");
|
||||
if (ffmpeg.empty())
|
||||
throw std::runtime_error("FFMPEG directive missing in ini file.");
|
||||
|
||||
filesystem::path path(pathString);
|
||||
path = path.make_absolute();
|
||||
|
||||
ctpl::thread_pool threadPool(6);
|
||||
Http::HttpClient httpClient;
|
||||
auto callback = std::bind(&CameraRecorder::API::WebAPI::ProcessQuery, &threadPool, &httpClient, path, ffmpeg, std::placeholders::_1, std::placeholders::_2);
|
||||
auto callback = std::bind(&CameraRecorder::API::WebAPI::ProcessQuery, &threadPool, &httpClient, path.str(), ffmpeg, std::placeholders::_1, std::placeholders::_2);
|
||||
|
||||
Http::HttpServer server(port, callback);
|
||||
Logging::Log(Logging::Severity::Info, "Startup Complete");
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../Libraries/Image
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../Libraries/filesystem
|
||||
@@ -14,7 +14,12 @@ LFLAGS += -lUtilities
|
||||
LFLAGS += -L$(ROOTPATH)/Libraries/Utilities/lib/$(ARCH)
|
||||
CFLAGS += -I$(ROOTPATH)/Libraries/Utilities/include
|
||||
|
||||
LFLAGS += -lImage -ljpeg
|
||||
LFLAGS += -L$(ROOTPATH)/Libraries/Image/lib/$(ARCH)
|
||||
CFLAGS += -I$(ROOTPATH)/Libraries/Image/include
|
||||
|
||||
CFLAGS += -I$(ROOTPATH)/Libraries/CTPL
|
||||
CFLAGS += -I$(ROOTPATH)/Libraries/filesystem
|
||||
CFLAGS += -I$(ROOTPATH)/Libraries/inih
|
||||
|
||||
LFLAGS += -pthread
|
||||
|
||||
@@ -22,6 +22,12 @@ std::string DigooRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string DigooRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "DigooRecorder MultiSnapshot");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string DigooRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "DigooRecorder Video");
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
~DigooRecorder();
|
||||
|
||||
virtual std::string Snapshot(ctpl::thread_pool* pThreadPool) override;
|
||||
virtual std::string MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages) override;
|
||||
virtual std::string Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg) override;
|
||||
|
||||
private:
|
||||
|
||||
+69
-22
@@ -1,7 +1,9 @@
|
||||
#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>
|
||||
@@ -23,27 +25,29 @@ 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";
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString);
|
||||
|
||||
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();
|
||||
}
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
Settings settings = m_settings;
|
||||
pThreadPool->push( [pHttpClient, settings, dateTimeString](int) { FoscamRecorder::Snapshots(pHttpClient, settings, dateTimeString, 1); } );
|
||||
|
||||
return fileName.str();
|
||||
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)
|
||||
@@ -54,17 +58,60 @@ std::string FoscamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::str
|
||||
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::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.str() << " > /dev/null 2>&1";
|
||||
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.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
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "Recorder.h"
|
||||
#include "Settings.h"
|
||||
#include <JpegImage.h>
|
||||
|
||||
|
||||
namespace Http {
|
||||
@@ -21,8 +22,14 @@ public:
|
||||
~FoscamRecorder();
|
||||
|
||||
virtual std::string Snapshot(ctpl::thread_pool* pThreadPool) override;
|
||||
virtual std::string MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages) override;
|
||||
virtual std::string Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg) override;
|
||||
|
||||
private:
|
||||
static std::string GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString);
|
||||
static void Snapshots(Http::HttpClient* pHttpClient, const Settings& settings, std::string dateTimeString, int numberOfImages);
|
||||
static Image::JpegImage Snapshot(Http::HttpClient* pHttpClient, const Settings& settings);
|
||||
|
||||
private:
|
||||
Http::HttpClient* m_pHttpClient;
|
||||
Settings m_settings;
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
~Recorder();
|
||||
|
||||
virtual std::string Snapshot(ctpl::thread_pool* pThreadPool) = 0;
|
||||
virtual std::string MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages) = 0;
|
||||
virtual std::string Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -22,31 +22,29 @@ 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);
|
||||
std::string dateTimeString = GetDateTimeString(true);
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
|
||||
|
||||
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;
|
||||
}
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
Settings settings = m_settings;
|
||||
pThreadPool->push( [pHttpClient, settings, dateTimeString](int) { VStarCamRecorder::Snapshots(pHttpClient, settings, dateTimeString, 1); } );
|
||||
|
||||
return fileName.str() + "_0.jpg";
|
||||
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)
|
||||
@@ -57,17 +55,53 @@ std::string VStarCamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::s
|
||||
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::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.str() << " > /dev/null 2>&1";
|
||||
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.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
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "Recorder.h"
|
||||
#include "Settings.h"
|
||||
#include <filesystem/path.h>
|
||||
|
||||
|
||||
namespace Http {
|
||||
@@ -21,8 +22,14 @@ public:
|
||||
~VStarCamRecorder();
|
||||
|
||||
virtual std::string Snapshot(ctpl::thread_pool* pThreadPool) override;
|
||||
virtual std::string MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages) override;
|
||||
virtual std::string Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg) override;
|
||||
|
||||
private:
|
||||
static std::string GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString, int imageIndex);
|
||||
static void Snapshots(Http::HttpClient* pHttpClient, const Settings& settings, std::string dateTimeString, int numberOfImages);
|
||||
static void Snapshot(Http::HttpClient* pHttpClient, const Settings& settings, const filesystem::path& fileName);
|
||||
|
||||
private:
|
||||
Http::HttpClient* m_pHttpClient;
|
||||
Settings m_settings;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "WatchBotRecorder.h"
|
||||
#include "Util.h"
|
||||
#include <HttpClient.h>
|
||||
#include <JpegImageCollection.h>
|
||||
#include <Logging.h>
|
||||
#include <filesystem/path.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace CameraRecorder {
|
||||
@@ -22,27 +25,29 @@ WatchBotRecorder::~WatchBotRecorder()
|
||||
std::string WatchBotRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "WatchBotRecorder Snapshot");
|
||||
std::stringstream url;
|
||||
url << "http://" << m_settings.IpAddress << ":" << m_settings.Port << "/snapshot.cgi?user=" << m_settings.Username << "&pwd=" << m_settings.Password;
|
||||
|
||||
std::stringstream fileName;
|
||||
fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".jpg";
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString);
|
||||
|
||||
try
|
||||
{
|
||||
std::ofstream file(fileName.str());
|
||||
file << m_pHttpClient->GetUrlContents(url.str());
|
||||
file.close();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "CameraDevice::PerformWatchBotAction() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
return std::string();
|
||||
}
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
Settings settings = m_settings;
|
||||
pThreadPool->push( [pHttpClient, settings, dateTimeString](int) { WatchBotRecorder::Snapshots(pHttpClient, settings, dateTimeString, 1); } );
|
||||
|
||||
return fileName.str();
|
||||
return fileName;
|
||||
}
|
||||
|
||||
std::string WatchBotRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "WatchBotRecorder 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) { WatchBotRecorder::Snapshots(pHttpClient, settings, dateTimeString, numberOfImages); } );
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
std::string WatchBotRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
|
||||
@@ -52,17 +57,60 @@ std::string WatchBotRecorder::Video(ctpl::thread_pool* pThreadPool, const std::s
|
||||
std::stringstream url;
|
||||
url << "http://" << m_settings.IpAddress << ":" << m_settings.Port << "/videostream.asf?user=" << m_settings.Username << "&pwd=" << m_settings.Password;
|
||||
|
||||
std::stringstream fileName;
|
||||
fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".mp4";
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "mp4", dateTimeString);
|
||||
|
||||
std::stringstream command;
|
||||
command << ffmpeg << " -i \"" << url.str() << "\" -t 30 -c:v libx264 -pix_fmt yuv420p -profile:v main -level:v 3.1 -c:a aac -strict experimental " << fileName.str() << " > /dev/null 2>&1";
|
||||
command << ffmpeg << " -i \"" << url.str() << "\" -t 30 -c:v libx264 -pix_fmt yuv420p -profile:v main -level:v 3.1 -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.str();
|
||||
return fileName;
|
||||
}
|
||||
|
||||
std::string WatchBotRecorder::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 WatchBotRecorder::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(WatchBotRecorder::Snapshot(pHttpClient, settings));
|
||||
|
||||
Image::JpegImageCollection collection(images);
|
||||
collection.Save(WatchBotRecorder::GetFileName(settings, "jpg", dateTimeString));
|
||||
}
|
||||
|
||||
Image::JpegImage WatchBotRecorder::Snapshot(Http::HttpClient* pHttpClient, const Settings& settings)
|
||||
{
|
||||
std::stringstream url;
|
||||
url << "http://" << settings.IpAddress << ":" << settings.Port << "/snapshot.cgi?user=" << settings.Username << "&pwd=" << settings.Password;
|
||||
|
||||
Image::JpegImage image;
|
||||
|
||||
try
|
||||
{
|
||||
image.SetImageData(pHttpClient->GetUrlContents(url.str()));
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "WatchBotRecorder::Snapshot() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
} // namespace Recorder
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "Recorder.h"
|
||||
#include "Settings.h"
|
||||
#include <JpegImage.h>
|
||||
|
||||
|
||||
namespace Http {
|
||||
@@ -21,8 +22,14 @@ public:
|
||||
~WatchBotRecorder();
|
||||
|
||||
virtual std::string Snapshot(ctpl::thread_pool* pThreadPool) override;
|
||||
virtual std::string MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages) override;
|
||||
virtual std::string Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg) override;
|
||||
|
||||
private:
|
||||
static std::string GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString);
|
||||
static void Snapshots(Http::HttpClient* pHttpClient, const Settings& settings, std::string dateTimeString, int numberOfImages);
|
||||
static Image::JpegImage Snapshot(Http::HttpClient* pHttpClient, const Settings& settings);
|
||||
|
||||
private:
|
||||
Http::HttpClient* m_pHttpClient;
|
||||
Settings m_settings;
|
||||
|
||||
@@ -22,6 +22,12 @@ std::string ZModoRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string ZModoRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "ZModoRecorder MultiSnapshot");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string ZModoRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "ZModoRecorder Video");
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
~ZModoRecorder();
|
||||
|
||||
virtual std::string Snapshot(ctpl::thread_pool* pThreadPool) override;
|
||||
virtual std::string MultiSnapshot(ctpl::thread_pool* pThreadPool, int numberOfImages) override;
|
||||
virtual std::string Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg) override;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user