Ask Your Question
0

network stream udp

asked 2017-03-27 04:49:05 -0600

k_kaz gravatar image

updated 2017-03-27 09:41:56 -0600

I want to process and display a network rtsp stream that is created from a raspberry camera. I have this code:

#include <iostream>
#include <functional>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main(int argc, char** argv) {

    cv::VideoCapture * stream = new cv::VideoCapture("rtsp://192.168.55.151:8554/");
    if (!stream->isOpened()) return -1;

    cv::namedWindow("rtsp_stream", CV_WINDOW_AUTOSIZE);
    cv::Mat frame;

    while (true) {

        if (!stream->read(frame)) return -1;

        cv::imshow("rtsp_stream", frame);
        cv::waitKey(15);
    }

    return 1;
}

When the stream is not live, the execution of this results in:

[tcp @ 0xa12480] Connection to tcp://192.168.55.151:8554?timeout=0 failed: Connection refused

Which means that the stream tries to connect with tcp. When the stream is live, the execution results in:

 [rtsp @ 0xb07960] method SETUP failed: 461 Client error

From internet research i found that the problem may be that the stream uses udp. If i change the URL to:

"udp://192.168.55.151:8554/"

Then the execution freezes in the cv::VideoCapture("udp://192.168.55.151:8554/"); How can i solve my problem?

Edit 1: VLC is able to open the stream.

Edit 2: As i am given to understand, ffmpeg is used to decode the stream. When i run:

ffmpeg -rtsp_transport udp -i rtsp://192.168.55.151:8554/ -t 5 test.mpg

the stream decoding and saving is successful. So how can i specify the lower level protocol to be udp?

Edit 3: If i use the ffmpeg command with tcp instead of udp, i get the same error with the c++ code, 461 client error

edit retag flag offensive close merge delete

Comments

I don't think it is an opencv problem. You can google error message "461 Client error" and hope to find good syntax in a post

LBerger gravatar imageLBerger ( 2017-03-27 09:37:14 -0600 )edit

@LBerger but i get the same exact error from the ffmpeg when i try to connect with tcp. If i change to udp in the ffmpeg command, the decoding is successful. So i guess that i need to tell opencv to use ffmpeg with udp instead of tcp, right?

k_kaz gravatar imagek_kaz ( 2017-03-27 09:41:04 -0600 )edit
LBerger gravatar imageLBerger ( 2017-03-27 10:38:51 -0600 )edit

@LBerger i ve tried this solution, but it has the same behavior with the "udp://192.168.55.151:8554/" link. Is it possible that the problem is from the server?

k_kaz gravatar imagek_kaz ( 2017-03-29 01:36:04 -0600 )edit

No idea but you can do it with vlc and ffmpeg then I think your server is ok. May be you can try with gstreamer?

LBerger gravatar imageLBerger ( 2017-03-29 01:55:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-29 07:29:36 -0600

k_kaz gravatar image

@LBerger it was answered in the github opencv issues. Opencv forces a tcp connection. So i changed the server to an http stream. Thanks for the help

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-03-27 04:49:05 -0600

Seen: 6,617 times

Last updated: Mar 27 '17