Ask Your Question
0

opencv rtsp stream freezing

asked 2017-03-11 17:47:53 -0600

rududoo gravatar image

updated 2017-03-11 17:51:55 -0600

Hi,

I have a live view system - DS-7108HWI-SL from HIKVISION. I am using opencv 2.4.13 to capture its rtsp stream from one channel. The channel options are :

<streamingchannel version="1.0"><id>301</id><channelname/><enabled>true</enabled><transport><rtspportno>554</rtspportno><controlprotocollist><controlprotocol><streamingtransport>RTSP</streamingtransport></controlprotocol></controlprotocollist></transport><video><enabled>true</enabled><videoinputchannelid>3</videoinputchannelid><videocodectype>H.264</videocodectype><videoresolutionwidth>960</videoresolutionwidth><videoresolutionheight>576</videoresolutionheight><videoqualitycontroltype>VBR</videoqualitycontroltype><fixedquality>60</fixedquality><vbruppercap>512</vbruppercap><vbrlowercap>32</vbrlowercap><maxframerate>2500</maxframerate><snapshotimagetype>JPEG</snapshotimagetype></video><audio><enabled>false</enabled><audioinputchannelid>3</audioinputchannelid><audiocompressiontype>G.711ulaw</audiocompressiontype></audio></streamingchannel>

This information is given by the system while giving an url in browser for the specific channel -in this case channel 3. So to access this stream - the rtsp protocol is used; video compression is h264.

I set the video stream url for my opencv application and I open it with a video capture object. Everything seems fine; for a couple of seconds I have a good fps but then the capture window that I display from opencv freezes and will block for tens of seconds then the process repeats (it works then after a short time it blocks).

I will appreciate if anyone could give me a hint of how to avoid this blocking.

Note that I used this application with an ip cam which provided a http stream and the video format was mjpg. There were small delays and jams but it was acceptable.

As an observation I do not know how reliable is rtsp with h264 in a WAN with lots of hops. I forgot to mention that I try to open the rtsp stream over internet - I am not in a local network. I mention that I tried the stream in vlc and there it blocks too. I tried from different locations with vlc and the same result. Is there another transport option? I checked in the video system but I saw only rtsp.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-21 20:10:28 -0600

rududoo gravatar image

I come back with an interesting fact. I took the latest version of ffmpeg library and built it. I rebuilt opencv - fixed the symlinks to point to the new ffmpeg and then rerun my application with the rtsp stream. It took longer until the stream froze again.

I tried to play the stream using the ffplay tool generated in ffmpeg. With the ffplay there is no blocking of the rtsp stream. So this looks like an implementation issue inside opencv. Does anyone have some sources examples using ffmpeg library in opencv such that I bypass the opencv videocapture object that behind it uses its implementation for grabbing ffmpeg flow? So I want to grab frames like in ffplay and save them as Mat type and use them further.

edit flag offensive delete link more

Comments

The solution I found was to use ffmpeg library instead of VideoCapture class implemented by OpenCv. It works without any problems or glitches unlike the situation I used VideoCapture object.

rududoo gravatar imagerududoo ( 2017-03-24 19:39:55 -0600 )edit

Hi, I have the same problem, i try to read an h264 stream from ipcamera (local network) and process motion detection. With the object VideoCapture the stream freeze after 20-60 secondes. So I want replace the VideoCapture objet by, ffmpeg or vlc, but I need a cv::Mat objet to process my motion detection. Do you have an idea hot to do it ? Thx, Psykomusic

psykomusic gravatar imagepsykomusic ( 2017-05-26 03:19:09 -0600 )edit

I am also having the same problem. Can you tell how to build ffmpeg with opencv and use it to read rtsp stream in code

archit522 gravatar imagearchit522 ( 2018-05-30 02:23:13 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-03-11 17:47:53 -0600

Seen: 3,481 times

Last updated: Mar 21 '17