VStarCamRecorder.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "VStarCamRecorder.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. VStarCamRecorder::VStarCamRecorder(Http::HttpClient* pHttpClient, const Settings& settings) :
  10. m_pHttpClient(pHttpClient),
  11. m_settings(settings)
  12. {
  13. }
  14. VStarCamRecorder::~VStarCamRecorder()
  15. {
  16. }
  17. std::string VStarCamRecorder::Snapshot(ctpl::thread_pool* pThreadPool)
  18. {
  19. Logging::Log(Logging::Severity::Debug, "VStarCamRecorder Snapshot");
  20. std::stringstream url;
  21. url << "http://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << m_settings.Port << "/img/snapshot.cgi?res=0";
  22. std::stringstream fileName;
  23. fileName << m_settings.Path << "/" << m_settings.IpAddress << "/VSTA000000XXXXX_0_" << GetDateTimeString(true);
  24. int i = 0;
  25. while (i < 3)
  26. {
  27. try
  28. {
  29. std::ofstream file(fileName.str() + "_" + std::to_string(i) + ".jpg");
  30. file << m_pHttpClient->GetUrlContents(url.str());
  31. file.close();
  32. }
  33. catch (const std::exception& e)
  34. {
  35. std::stringstream ss;
  36. ss << "CameraDevice::PerformVStarCamAction() - Error: " << e.what() << std::endl;
  37. Logging::Log(Logging::Severity::Error, ss.str());
  38. }
  39. ++i;
  40. }
  41. return fileName.str() + "_0.jpg";
  42. }
  43. std::string VStarCamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::string& ffmpeg)
  44. {
  45. Logging::Log(Logging::Severity::Debug, "VStarCamRecorder Video");
  46. int port = 10554;
  47. std::stringstream url;
  48. url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << port << "/udp/av0_0";
  49. std::stringstream fileName;
  50. fileName << m_settings.Path << "/" << m_settings.IpAddress << "/VSTA000000XXXXX_0_" << GetDateTimeString(true) << ".mp4";
  51. std::stringstream command;
  52. command << ffmpeg << " -i \"" << url.str() << "\" -t 30 -c:v copy -c:a aac -b:a 8k -strict experimental " << fileName.str() << " > /dev/null 2>&1";
  53. std::string cmd(command.str());
  54. Logging::Log(Logging::Severity::Debug, cmd);
  55. pThreadPool->push( [cmd](int) { int retval = std::system(cmd.c_str()); } );
  56. return fileName.str();
  57. }
  58. } // namespace Recorder
  59. } // namespace CameraRecorder