fix video reading skipping

This commit is contained in:
jario-jin 2023-12-27 15:24:47 +08:00
parent 5f656487a1
commit cf6a285f3e
2 changed files with 22 additions and 14 deletions

View File

@ -1185,8 +1185,11 @@ void CameraBase::_run()
{ {
while (this->_is_running && this->_cap.isOpened()) while (this->_is_running && this->_cap.isOpened())
{ {
this->_cap >> this->_frame; if (this->_type != CameraType::VIDEO || this->_is_updated == false)
this->_is_updated = true; {
this->_cap >> this->_frame;
this->_is_updated = true;
}
std::this_thread::sleep_for(std::chrono::milliseconds(2)); std::this_thread::sleep_for(std::chrono::milliseconds(2));
} }
} }
@ -1199,8 +1202,8 @@ bool CameraBase::read(cv::Mat& image)
{ {
if (this->_is_updated) if (this->_is_updated)
{ {
this->_is_updated = false;
this->_frame.copyTo(image); this->_frame.copyTo(image);
this->_is_updated = false;
break; break;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(20)); std::this_thread::sleep_for(std::chrono::milliseconds(20));

View File

@ -72,18 +72,20 @@ void Camera::openImpl()
this->_fps = 30; this->_fps = 30;
} }
#ifdef PLATFORM_JETSON #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 ! 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
sprintf(pipe, "rtspsrc location=rtsp://%s:%d/H264?W=%d&H=%d&FPS=%d&BR=4000000 latency=100 ! \ 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 ! \ application/x-rtp,media=video ! rtph264depay ! parsebin ! avdec_h264 ! \
videoconvert ! appsink sync=false", videoconvert ! appsink sync=false",
this->_ip.c_str(), this->_port, this->_width, this->_height, this->_fps); this->_ip.c_str(), this->_port, this->_width, this->_height, this->_fps);
#endif #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); this->_cap.open(pipe, cv::CAP_GSTREAMER);
} }
else if (this->_type == CameraType::GX40) else if (this->_type == CameraType::GX40)
@ -98,7 +100,7 @@ void Camera::openImpl()
{ {
this->_port = 554; 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 camera_url << "rtspsrc location = rtsp://user:0000@" << this->_ip << ":" << this->_port
<< "/cam/realmonitor?channel=1&subtype=0 latency=100 ! application/x-rtp,media=video ! \ << "/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 rtph265depay ! parsebin ! avdec_h265 ! videoscale ! video/x-raw,width=(int)" << this->_width
@ -150,9 +152,12 @@ void Camera::openImpl()
this->_fps = 30; this->_fps = 30;
} }
#ifdef PLATFORM_X86_CUDA #if defined(PLATFORM_X86_CUDA) || defined(PLATFORM_X86_INTEL)
sprintf(pipe, "%s?W=%d&H=%d&FPS=%d", this->_rtsp_url.c_str(), this->_width, this->_height, this->_fps); sprintf(pipe, "rtspsrc location=%s?W=%d&H=%d&FPS=%d latency=100 ! \
this->_cap.open(pipe); 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 #endif
#ifdef PLATFORM_JETSON #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); 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);