From cf6a285f3ec5b4f2a4e971738f3f241045615854 Mon Sep 17 00:00:00 2001 From: jario-jin Date: Wed, 27 Dec 2023 15:24:47 +0800 Subject: [PATCH] fix video reading skipping --- video_io/sv_video_base.cpp | 9 ++++++--- video_io/sv_video_input.cpp | 27 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/video_io/sv_video_base.cpp b/video_io/sv_video_base.cpp index 5586b9c..39f59a4 100644 --- a/video_io/sv_video_base.cpp +++ b/video_io/sv_video_base.cpp @@ -1185,8 +1185,11 @@ void CameraBase::_run() { while (this->_is_running && this->_cap.isOpened()) { - this->_cap >> this->_frame; - this->_is_updated = true; + if (this->_type != CameraType::VIDEO || this->_is_updated == false) + { + this->_cap >> this->_frame; + this->_is_updated = true; + } std::this_thread::sleep_for(std::chrono::milliseconds(2)); } } @@ -1199,8 +1202,8 @@ bool CameraBase::read(cv::Mat& image) { if (this->_is_updated) { - this->_is_updated = false; this->_frame.copyTo(image); + this->_is_updated = false; break; } std::this_thread::sleep_for(std::chrono::milliseconds(20)); diff --git a/video_io/sv_video_input.cpp b/video_io/sv_video_input.cpp index 71f8bdc..76913d2 100644 --- a/video_io/sv_video_input.cpp +++ b/video_io/sv_video_input.cpp @@ -72,18 +72,20 @@ void Camera::openImpl() this->_fps = 30; } -#ifdef PLATFORM_JETSON - sprintf(pipe, "rtspsrc location=rtsp://%s:%d/H264?W=%d&H=%d&FPS=%d&BR=4000000 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->_ip.c_str(), this->_port, this->_width, this->_height, this->_fps); -#else +#if defined(PLATFORM_X86_CUDA) || defined(PLATFORM_X86_INTEL) sprintf(pipe, "rtspsrc location=rtsp://%s:%d/H264?W=%d&H=%d&FPS=%d&BR=4000000 latency=100 ! \ application/x-rtp,media=video ! rtph264depay ! parsebin ! avdec_h264 ! \ videoconvert ! appsink sync=false", this->_ip.c_str(), this->_port, this->_width, this->_height, this->_fps); #endif - printf("%s\r\n",pipe); +#ifdef PLATFORM_JETSON + sprintf(pipe, "rtspsrc location=rtsp://%s:%d/H264?W=%d&H=%d&FPS=%d&BR=4000000 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->_ip.c_str(), this->_port, this->_width, this->_height, this->_fps); +#endif + + // printf("%s\r\n",pipe); this->_cap.open(pipe, cv::CAP_GSTREAMER); } else if (this->_type == CameraType::GX40) @@ -98,7 +100,7 @@ void Camera::openImpl() { this->_port = 554; } -#ifdef PLATFORM_X86_CUDA +#if defined(PLATFORM_X86_CUDA) || defined(PLATFORM_X86_INTEL) camera_url << "rtspsrc location = rtsp://user:0000@" << this->_ip << ":" << this->_port << "/cam/realmonitor?channel=1&subtype=0 latency=100 ! application/x-rtp,media=video ! \ rtph265depay ! parsebin ! avdec_h265 ! videoscale ! video/x-raw,width=(int)" << this->_width @@ -150,9 +152,12 @@ void Camera::openImpl() 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); +#if defined(PLATFORM_X86_CUDA) || defined(PLATFORM_X86_INTEL) + sprintf(pipe, "rtspsrc location=%s?W=%d&H=%d&FPS=%d latency=100 ! \ + application/x-rtp,media=video ! rtph264depay ! parsebin ! avdec_h264 ! \ + videoconvert ! appsink sync=false", + this->_rtsp_url.c_str(), this->_width, this->_height, this->_fps); + this->_cap.open(pipe, cv::CAP_GSTREAMER); #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);