WatchBotRecorder.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "WatchBotRecorder.h"
  2. #include "Util.h"
  3. #include <HttpClient.h>
  4. #include <Logging.h>
  5. #include <fstream>
  6. #include <sstream>
  7. namespace CameraRecorder {
  8. namespace Recorder {
  9. WatchBotRecorder::WatchBotRecorder(Http::HttpClient* pHttpClient, const Settings& settings) :
  10. m_pHttpClient(pHttpClient),
  11. m_settings(settings)
  12. {
  13. }
  14. WatchBotRecorder::~WatchBotRecorder()
  15. {
  16. }
  17. std::string WatchBotRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
  18. {
  19. Logging::Log(Logging::Severity::Debug, "WatchBotRecorder Snapshot");
  20. std::stringstream url;
  21. url << "http://" << m_settings.IpAddress << ":" << m_settings.Port << "/snapshot.cgi?user=" << m_settings.Username << "&pwd=" << m_settings.Password;
  22. std::stringstream fileName;
  23. fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".jpg";
  24. try
  25. {
  26. std::ofstream file(fileName.str());
  27. file << m_pHttpClient->GetUrlContents(url.str());
  28. file.close();
  29. }
  30. catch (const std::exception& e)
  31. {
  32. std::stringstream ss;
  33. ss << "CameraDevice::PerformWatchBotAction() - Error: " << e.what() << std::endl;
  34. Logging::Log(Logging::Severity::Error, ss.str());
  35. return std::string();
  36. }
  37. return fileName.str();
  38. }
  39. std::string WatchBotRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
  40. {
  41. Logging::Log(Logging::Severity::Debug, "WatchBotRecorder Video");
  42. std::stringstream url;
  43. url << "http://" << m_settings.IpAddress << ":" << m_settings.Port << "/videostream.asf?user=" << m_settings.Username << "&pwd=" << m_settings.Password;
  44. std::stringstream fileName;
  45. fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".mp4";
  46. std::stringstream command;
  47. 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";
  48. std::string cmd(command.str());
  49. Logging::Log(Logging::Severity::Debug, cmd);
  50. pThreadPool->push( [cmd](int) { int retval = std::system(cmd.c_str()); } );
  51. return fileName.str();
  52. }
  53. } // namespace Recorder
  54. } // namespace CameraRecorder