Reading a video File

We have a video grabbing loop that is able to grab frames from a webcam and then we process the images.

However I can’t seem to get the file open command to work to read in a video file.
The video was shot from a mobile phone, plays fine in vlc on the pc and had a default file extension of .mov which I renamed to .avi, (also tried .mp4 and .mpeg .

videoStreamAddress = “/home/lvuser/deploy/testmovie.mpeg”;

VideoCapture visionCam(videoStreamAddress);

  • [ INFO:0] VIDEOIO: Enabled backends(3, sorted by priority): V4L2(1000); CV_IMAGES(990); CV_MJPEG(980)

  • (DEBUG) V4L: opening /home/lvuser/deploy/testmovie.mpeg

  • Cannot open the video cam /home/lvuser/deploy/testmovie.mpeg

If the string is /dev/video0 it works.

I have done this in the past on a separate co-processor, just fine.

Could the rio not have the v4l codecs to understand how to handle the file?


The opencv used on the Rio is not built with the libraries required to read video files (ffmpeg in particular). You should be able to load individual jpeg images, but video files are not supported.

Well that explains it. Many thanks. We were hoping to simply walk the field with a camera, and then feed this video into the robot to test image processing.

I guess the workaround will be to externally on a pc, extract frames from a recorded video, sequence them and use those files as a test.

Is the reason not to support video due to licensing issues?

Yes, we need to research to licensing question more, but the other thing is that every library dependency adds complexity to the build, it is a fairly manual process to get each one working, and most teams don’t need it, so it’s fairly low on the priority list. It’s something we are looking at for 2020.

I’ll note that GRIP has support for video files, but the latest release was in 2017 so you’d have to build GRIP from source to use that functionality.

Good point Sam.
Since the image processing is a GRIP pipeline anyway, we will likely just push the video to Grip on the pc and if it works there, it should work in the Robot.

Just wondering, would this be the same reason we had trouble opening up an Axis Camera via a IP webcam http: url?

While we could access the axis camera as a “dumb” CameraServer source , when we tried grabbing a frame from the CVSINK it would fail. And when trying to open it up as a VideoCapture in OpenCV, it would not open in the same fashion we saw with the video file.


Axis cameras should work, as they stream MJPEG. I’ve not tested OpenCV VideoCapture, but I have tested cscore with at least a couple of the models. Can you give some more detail? What model Axis camera, how did you set it up, etc? There’s some debugging flags we can turn on to get more info about what’s happening.

Axis Camera Model M1013

And with respect to the open we tried…


and even

which all work in a webbrowser

Code segment is:

s> td::string videoStreamAddress;

videoStreamAddress = “”;

VideoCapture visionCam(videoStreamAddress);

if (!visionCam.isOpened()) // if not success, exit program


cout << "Cannot open the video cam " << videoStreamAddress << std::endl;



{ cout << “Congrats Dashcamera opened.” << videoStreamAddress << std::endl;


Error we receive:

I even tried just reading static images from the camera using cv::imread but did not succeed there either.

this link has a list of various urls that the camera

Connect to Axis cameras

which may help others as well.


What did the cscore version of your code look like? I’m not sure OpenCV VideoCapture has the http client capability built into it.

Dont let anyone tell you otherwise. You are awesome !


cs::CvSink cvSink4 = frc::CameraServer::GetInstance()->GetVideo(“Axis Camera”);