WatchBotRecorder.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /*
  43. std::stringstream url;
  44. url << "http://" << m_settings.IpAddress << ":" << m_settings.Port << "/videostream.asf?user=" << m_settings.Username << "&pwd=" << m_settings.Password << "&resolution=64&rate=0";
  45. std::stringstream fileName;
  46. fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".mp4";
  47. std::stringstream command;
  48. command << "ffmpeg -i \"" << url.str() << "\" -t 30 -c:v copy -c:a aac -b:a 8k -strict experimental " << fileName.str() << " > /dev/null 2>&1";
  49. std::string cmd(command.str());
  50. Logging::Log(Logging::Severity::Debug, cmd);
  51. pThreadPool->push( [cmd](int) { int retval = std::system(cmd.c_str()); } );
  52. return fileName.str();
  53. */
  54. return std::string();
  55. }
  56. } // namespace Recorder
  57. } // namespace CameraRecorder