title: opencv rtsp stream protocol
body: <p>I want to process and display a network rtsp stream that is created from a raspberry camera.
  I have this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;functional&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  
  int main(int argc, char** argv) {
  
      cv::VideoCapture * stream = new cv::VideoCapture("rtsp://192.168.55.151:8554/");
      if (!stream-&gt;isOpened()) return -1;
  
      cv::namedWindow("rtsp_stream", CV_WINDOW_AUTOSIZE);
      cv::Mat frame;
  
      while (true) {
  
          if (!stream-&gt;read(frame)) return -1;
  
          cv::imshow("rtsp_stream", frame);
          cv::waitKey(15);
      }
  
      return 1;
  }
  </code></pre>
  
  <p>When the stream is not live, the execution of this results in:</p>
  
  <pre><code>[tcp @ 0xa12480] Connection to tcp://192.168.55.151:8554?timeout=0 failed: Connection refused
  </code></pre>
  
  <p>Which means that the stream tries to connect with tcp. When the stream is live, the execution results in:</p>
  
  <pre><code> [rtsp @ 0xb07960] method SETUP failed: 461 Client error
  </code></pre>
  
  <p>From internet research i found that the problem may be that the stream uses udp. If i change the URL to:</p>
  
  <pre><code>"udp://192.168.55.151:8554/"
  </code></pre>
  
  <p>Then the execution freezes in the <code>cv::VideoCapture("udp://192.168.55.151:8554/");</code></p>
  
  <p>VLC is able to open the rtsp stream. As i am given to understand, ffmpeg is used to decode the stream with opencv. When i run:</p>
  
  <pre><code>ffmpeg -rtsp_transport udp -i rtsp://192.168.55.151:8554/ -t 5 test.mp4
  </code></pre>
  
  <p>the stream decoding and saving is successful. 
  So how can i specify the lower level protocol to be udp in the opencv code? Is there another way to do it with opencv?  </p>
  
  <p>EDIT: If i change the ffmpeg command to use tcp, i.e:</p>
  
  <pre><code>ffmpeg -rtsp_transport tcp -i rtsp://192.168.55.151:8554/ -t 5 test.mp4
  </code></pre>
  
  <p>then i get the same exact error with the c++ code, 461 client error</p>
  
  <p>EDIT: When the code uses the udp:// link, after some 15 seconds of freeze, the execution returns with error</p>