Ask Your Question
0

Cancel VideoCapture::open RTSP from an other thread [closed]

asked 2019-10-29 05:46:16 -0500

Thierry gravatar image

updated 2019-10-29 09:36:01 -0500

Hi all,

I'm developping a C++ application using Qt (5.12), OpenCv (4.1.0) and GStreamer on Ubuntu 18.04 I instanciate a VideoCapture object in a dedicaced thread, then I try to open a RSTP connection with a deconnected video camera. The timeout of VideoCapture::open("rtspsrc location=rtsp://...) is about 20 seconds. When I close my application, my main thread wait the open failed to close properly the GUI. 20 seconds are too long for a GUI. I think there are 2 solutions to solve my problem, but I don't manage to implement them... any help is appreciated :)

  • Reduce the timeout, but it seems to be implemented in the interface (cv::CAP_GSTREAMER in my case), and need to compile opencv :(
  • Cancel the open() from the main Thread, the best solution. I already tryed to call VideoCapture::release(), or to delete my object (desperate solution I know ^^'), but the open() doesn't exit before its timeout...
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Thierry
close date 2019-10-29 09:38:25.677878

Comments

please avoid multithreading with opencv.

computer-vision programs also might not need a gui (or a human in the loop)

berak gravatar imageberak ( 2019-10-29 05:51:12 -0500 )edit

With a GUI application and lot of treatments, I don't have other solution that threading treatments. My application architecture can handle 2 sources (video camera or files). Each source (VideoCapture) is connected to 3 outputs (GUI / File (VideoWriter) / RTSP server). In the following diagram, the [] represent a thread : [Source] => [Publisher (process copy)] => [Outputs file] / [RTSP server] / [GUI (rendered by the main thread (qml)] This architecture works fine, but I still have my problem to close the VideoCapture during the open() step.

Thierry gravatar imageThierry ( 2019-10-29 09:00:59 -0500 )edit

let's note the absence of any actual computer-vision task

berak gravatar imageberak ( 2019-10-29 09:05:12 -0500 )edit

Well seen @berak, it's the next step of my developpment :). For now, I just need to display/record/forwad a video.

Thierry gravatar imageThierry ( 2019-10-29 09:12:05 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-10-29 09:25:22 -0500

Thierry gravatar image

updated 2019-10-29 09:26:42 -0500

I solved my problem (reducing the timeout).

The open() is blocking with RTSP sources. The parameter "time-out" in rtspsrc allow me to reduce the timeout (to 1s in my case). Here my command :

m_pCapture->open(QString("rtspsrc location=rtsp://%1 latency=0 tcp-timeout=1 ! rtph264depay ! h264parse ! avdec_h264 output-corrupt=false ! videoconvert ! appsink").arg(m_Url).toLatin1().data(), cv::CAP_GSTREAMER);

I hope that will help other people ;)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-10-29 05:46:16 -0500

Seen: 477 times

Last updated: Oct 29 '19