FoscamRecorder.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "FoscamRecorder.h"
  2. #include "Util.h"
  3. #include <HttpClient.h>
  4. #include <Logging.h>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <thread>
  8. namespace CameraRecorder {
  9. namespace Recorder {
  10. FoscamRecorder::FoscamRecorder(Http::HttpClient* pHttpClient, const Settings& settings) :
  11. m_pHttpClient(pHttpClient),
  12. m_settings(settings)
  13. {
  14. }
  15. FoscamRecorder::~FoscamRecorder()
  16. {
  17. }
  18. std::string FoscamRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
  19. {
  20. Logging::Log(Logging::Severity::Debug, "FoscamRecorder Snapshot");
  21. std::stringstream url;
  22. url << "http://" << m_settings.IpAddress << ":" << m_settings.Port << "/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=" << m_settings.Username << "&pwd=" << m_settings.Password;
  23. std::stringstream fileName;
  24. fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".jpg";
  25. try
  26. {
  27. std::ofstream file(fileName.str());
  28. file << m_pHttpClient->GetUrlContents(url.str());
  29. file.close();
  30. }
  31. catch (const std::exception& e)
  32. {
  33. std::stringstream ss;
  34. ss << "CameraDevice::PerformFoscamAction() - Error: " << e.what() << std::endl;
  35. Logging::Log(Logging::Severity::Error, ss.str());
  36. return std::string();
  37. }
  38. return fileName.str();
  39. }
  40. std::string FoscamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
  41. {
  42. Logging::Log(Logging::Severity::Debug, "FoscamRecorder Video");
  43. int port = 65534;
  44. std::stringstream url;
  45. url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << port << "/videoSub";
  46. std::stringstream fileName;
  47. fileName << m_settings.Path << "/" << m_settings.IpAddress << "/" << GetDateTimeString() << ".mp4";
  48. std::stringstream command;
  49. command << ffmpeg << " -i \"" << url.str() << "\" -t 30 -c:v copy -an -strict experimental " << fileName.str() << " > /dev/null 2>&1";
  50. std::string cmd(command.str());
  51. Logging::Log(Logging::Severity::Debug, cmd);
  52. pThreadPool->push( [cmd](int) { int retval = std::system(cmd.c_str()); } );
  53. return fileName.str();
  54. }
  55. } // namespace Recorder
  56. } // namespace CameraRecorder