opencv-rust icon indicating copy to clipboard operation
opencv-rust copied to clipboard

`VideoCapture::get(CAP_PROP_FOURCC)` always returns zero

Open rosscanning opened this issue 1 year ago • 2 comments

OS: Ubuntu 24.04. I installed OpenCV using apt install libopencv-dev. Rustc version is 1.86.0 (05f9846f8 2025-03-31)

Here's an quick repro (hopefully):

use opencv::prelude::*;
use opencv::videoio::{CAP_ANY, CAP_PROP_FOURCC, VideoCapture};

fn main() {
    let filename = std::env::args().nth(1).unwrap();
    let vid = VideoCapture::from_file(&filename, CAP_ANY).unwrap();

    let fourcc = vid.get(CAP_PROP_FOURCC).unwrap();

    println!("fourcc: {fourcc}");
}

then run on any video clip (for me, it happens with all of about half a dozen video clips)

Program always prints "fourcc: 0", when it should print "fourcc: 808996950" or similar. This Python program works correctly (prints "fourcc: 808996950") when run on the same box:

import cv2
import sys

cap = cv2.VideoCapture(sys.argv[1])
assert(cap.isOpened())
fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))
print(fourcc)

By the way, the full output from this command:

RUST_BACKTRACE=full cargo build -vv 

is quite lengthy, but I'm happy to add it if you need it.

rosscanning avatar May 09 '25 00:05 rosscanning

Hmm, I can now reproduce this with a C++ program, so it's nothing to do with this crate. Seems to be something to do with OpenCV and FFMPEG. I foresee much painful debugging in my future.

rosscanning avatar May 17 '25 00:05 rosscanning

For anyone finding this: the issue was OpenCV version. Upgrading to the latest OpenCV (4.11.0 at the time of writing) fixed the issue, for both my C++ program, and my Rust program using this crate.

rosscanning avatar Jun 24 '25 04:06 rosscanning