From 182c2d9f0b26b7c744dcd92bc5a8a723c67da993 Mon Sep 17 00:00:00 2001 From: jario Date: Mon, 25 Dec 2023 15:00:35 +0800 Subject: [PATCH] add RTSP, VIDEO to sv::CameraType --- include/sv_video_base.h | 6 +++++- video_io/sv_video_base.cpp | 8 ++++++++ video_io/sv_video_input.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/sv_video_base.h b/include/sv_video_base.h index ff74885..4dbcb18 100644 --- a/include/sv_video_base.h +++ b/include/sv_video_base.h @@ -327,7 +327,7 @@ protected: }; -enum class CameraType {NONE, WEBCAM, V4L2CAM, G1, Q10, MIPI, GX40}; +enum class CameraType {NONE, WEBCAM, V4L2CAM, MIPI, RTSP, VIDEO, G1, Q10, GX40}; class CameraBase { public: @@ -351,6 +351,8 @@ public: void setWH(int width, int height); void setFps(int fps); void setIp(std::string ip); + void setRtspUrl(std::string rtsp_url); + void setVideoPath(std::string video_path); void setPort(int port); void setBrightness(double brightness); void setContrast(double contrast); @@ -373,6 +375,8 @@ protected: int _height; int _fps; std::string _ip; + std::string _rtsp_url; + std::string _video_path; int _port; double _brightness; double _contrast; diff --git a/video_io/sv_video_base.cpp b/video_io/sv_video_base.cpp index 7ff38a9..5586b9c 100644 --- a/video_io/sv_video_base.cpp +++ b/video_io/sv_video_base.cpp @@ -1080,6 +1080,14 @@ void CameraBase::setIp(std::string ip) { this->_ip = ip; } +void CameraBase::setRtspUrl(std::string rtsp_url) +{ + this->_rtsp_url = rtsp_url; +} +void CameraBase::setVideoPath(std::string video_path) +{ + this->_video_path = video_path; +} void CameraBase::setPort(int port) { this->_port = port; diff --git a/video_io/sv_video_input.cpp b/video_io/sv_video_input.cpp index 2db1c8d..b6688ca 100644 --- a/video_io/sv_video_input.cpp +++ b/video_io/sv_video_input.cpp @@ -19,6 +19,7 @@ void Camera::openImpl() if (this->_type == CameraType::V4L2CAM) { this->_cap.open(this->_camera_id, cv::CAP_V4L2); + // this->_cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('Y', 'U', 'Y', 'V')); } if (this->_type == CameraType::WEBCAM) { @@ -127,6 +128,36 @@ void Camera::openImpl() sprintf(pipe, "nvarguscamerasrc sensor-id=%d ! video/x-raw(memory:NVMM), width=(int)%d, height=(int)%d, format=(string)NV12, framerate=(fraction)%d/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink", this->_camera_id, this->_width, this->_height, this->_fps, this->_width, this->_height); this->_cap.open(pipe, cv::CAP_GSTREAMER); } + else if (this->_type == CameraType::RTSP) + { + char pipe[512]; + if (this->_width <= 0 || this->_height <= 0) + { + this->_width = 1280; + this->_height = 720; + } + if (this->_port <= 0) + { + this->_port = 554; + } + if (this->_fps <= 0) + { + this->_fps = 30; + } + +#ifdef PLATFORM_X86_CUDA + sprintf(pipe, "%s?W=%d&H=%d&FPS=%d", this->_rtsp_url.c_str(), this->_width, this->_height, this->_fps); + this->_cap.open(pipe); +#endif +#ifdef PLATFORM_JETSON + sprintf(pipe, "rtspsrc location=%s?W=%d&H=%d&FPS=%d latency=100 ! application/x-rtp,media=video ! rtph264depay ! parsebin ! nvv4l2decoder enable-max-performancegst=1 ! nvvidconv ! video/x-raw,format=(string)BGRx ! videoconvert ! appsink sync=false", this->_rtsp_url.c_str(), this->_width, this->_height, this->_fps); + this->_cap.open(pipe, cv::CAP_GSTREAMER); +#endif + } + else if (this->_type == CameraType::VIDEO) + { + this->_cap.open(this->_video_path); + } } }