twistedfall / opencv-rust

Rust bindings for OpenCV 3 & 4
MIT License
1.96k stars 157 forks source link

Can't initialize VIdeoCapture from file #551

Closed 111raigeki closed 6 months ago

111raigeki commented 6 months ago

Hello, I am trying to open a video using VideoCapture::from_file, but I can't get it to read the file properly. The project builds without any issues, but is_opened doesn't return true:

let mut cam = videoio::VideoCapture::from_file("data/test_vid.mp4", videoio::CAP_ANY)?;

let opened = videoio::VideoCapture::is_opened(&cam)?;//always false independent of file path or file format 

I've tried to do the same in python (3.10, opencv-python 4.9.0) and it works just fine. Capturing video from webcam also works fine.

Information:

  1. os: Mint 21.2
  2. way to install opencv: manual build (cmake)
  3. opencv version: 4.9.0-dev
  4. rustc version: 1.76.0 (07dca489a 2024-02-04)
  5. crate version: 0.88.8
twistedfall commented 6 months ago

It can be that OpenCV is built without mp4 support for example, but python is using the different OpenCV version that has this support. Please also post cargo build -vv after doing cargo clean, it contains a lot of helpful debug information that might aid in tracking the source of the issue down.

111raigeki commented 6 months ago

The codecs were indeed the issue - for some reason opencv did not recognize ffmpeg. Thank you for help.

benjamingb commented 5 months ago

The codecs were indeed the issue - for some reason opencv did not recognize ffmpeg. Thank you for help.

@111raigeki I have the same problem, what codecs did you need to install?