Search code examples
c#emgucvrtpsdp

EmguCV & OpenCV: Whitelist RTP protocol


I am trying to receive some video from a Parrot Bebop 2 drone. I am using this Bebop.sdp file, which is supplied by Parrot.

I have previously tried in Python which worked by setting an environment variable OPENCV_FFMPEG_CAPTURE_OPTIONS to protocol_whitelist;file,rtp,udp. This worked in Python. Since then we have ported that project mostly to C#. But when trying to connect to the stream, we get this error Protocol 'rtp' not on whitelist 'file,crypto'!. I have seen other examples where this -protocol_whitelist "file,rtp,udp" is passed through ffmpeg arguments, but in this case it does not seem as a solution, since i cannot pass it on.

Firstly i started with a simple test:

VideoCapture videoCapture = new VideoCapture(0);
var frame = videoCapture.QueryFrame();

while (frame != null)
{
    using (frame)
    {
        CvInvoke.Imshow("frame", frame);
        CvInvoke.WaitKey(1);
    }

    frame = videoCapture.QueryFrame();
}

This code get's the stream from the webcam and works.

I get the error when i run it with the SDP file:

VideoCapture videoCapture = new VideoCapture(@"./bebop.sdp");

var frame = videoCapture.QueryFrame();

while (frame != null)
{
    using (frame)
    {
        CvInvoke.Imshow("frame", frame);
        CvInvoke.WaitKey(1);
    }

    frame = videoCapture.QueryFrame();
}

I have tried to add both:

Environment.SetEnvironmentVariable("OPENCV_FFMPEG_CAPTURE_OPTIONS", "protocol_whitelist;file,rtp,udp");

And for a more aggressive approach:

Environment.SetEnvironmentVariable("OPENCV_FFMPEG_CAPTURE_OPTIONS", "protocol_whitelist;file,rtp,udp", EnvironmentVariableTarget.User);

None of them seem to have an impact since i get same error.

I would expect when setting the environment variables that the OpenCV would whitelist the protocols needed so the stream would come trough, and be displayed in the frame.


Solution

  • Environment variable was working, however due to the need for Visual Studio to restart first, in order to update environment variables, this was not discovered before today.