twistedfall / opencv-rust

Rust bindings for OpenCV 3 & 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error opening video file in OpenCV 4.8.0

benjamingb opened this issue · comments

Hi
After manually compiling OpenCV 4.8.0, I encountered an issue where it fails to read video files. I consistently receive an error message indicating that the video cannot be opened. Any insights or suggestions to resolve this problem would be greatly appreciated

This is the output when I compile opencv

result.txt

That's what I'm trying to call it.

pub fn get_video_capture(video_src: &str, typ: String) -> VideoCapture {
    if typ == "rtsp" {
        let video_capture = match VideoCapture::from_file(video_src, CAP_ANY) {
            Ok(result) => {result},
            Err(err) => {
                panic!("Can't init '{}' due the error: {:?}", video_src, err);
            }
        };
        return video_capture;
    }
    let device_id = match video_src.parse::<i32>() {
        Ok(result) => {result},
        Err(err) => {
            panic!("Can't parse '{}' as device_id (i32) due the error: {:?}", video_src, err);
        }
    };
    let video_capture = match VideoCapture::new(device_id, CAP_ANY) {
        Ok(result) => {result},
        Err(err) => {
            panic!("Can't init '{}' due the error: {:?}", video_src, err);
        }
    };
    return video_capture;
}

let mut video_capture = get_video_capture(&settings.input.video_src, settings.input.typ.clone());
    let opened = VideoCapture::is_opened(&video_capture).map_err(|err| AppError::from(err))?;
    if !opened {
        return Err(AppError::VideoError(AppVideoError{typ: 1}))
    }

This is the output when compiling with cargo build -vv

r.txt

Environment

OS: Ubuntu 24.04
rustc:  1.77.2

The OpenCV build log looks fine, it picked up ffmpeg. Can you maybe check if the corresponding Python or C++ program linked against the same manually build of OpenCV works or fails in the similar fashion?

I tried in c++ and the same problem appears, I think it is an opencv problem

Looks like it then, maybe for RTSP support you need some additional dependencies?

I compiled again with the minimum configurations and it worked, the strange thing is that I did not enable FFMPEG

-- General configuration for OpenCV 4.8.0 =====================================
--   Version control:               unknown
-- 
--   Extra modules:
--     Location (extra):            /home/benjamin/dist/opencv_contrib-4.8.0/modules
--     Version control (extra):     unknown
-- 
--   Platform:
--     Timestamp:                   2024-05-06T15:19:11Z
--     Host:                        Linux 6.8.0-31-generic x86_64
--     CMake:                       3.28.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/gmake
--     Configuration:               Release
-- 
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (16 files):         + SSSE3 SSE4_1
--       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (7 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (35 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 13.2.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
--     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java julia matlab ovis python2 python3 sfm ts viz
--     Applications:                -
--     Documentation:               NO
--     Non-free algorithms:         YES
-- 
--   GUI:                           GTK2
--     QT:                          NO
--     GTK+:                        YES (ver 2.24.33)
--       GThread :                  YES (ver 2.80.0)
--       GtkGlExt:                  YES (ver 1.2.0)
--     OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so)
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.3)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x020f)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.43)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.5.1)
--     JPEG 2000:                   OpenJPEG (ver 2.5.0)
--     GDAL:                        NO
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      YES (2.2.6)
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   YES (1.24.2)
--     v4l/v4l2:                    YES (linux/videodev2.h)
--     gPhoto2:                     YES
-- 
--   Parallel framework:            TBB (ver 2020.2 interface 11102)
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Intel IPP:                   2021.8 [2021.8.0]
--            at:                   /home/benjamin/build/opencv/opencv-4.8.0-build/3rdparty/ippicv/ippicv_lnx/icv
--     Intel IPP IW:                sources (2021.8.0)
--               at:                /home/benjamin/build/opencv/opencv-4.8.0-build/3rdparty/ippicv/ippicv_lnx/iw
--     VA:                          NO
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.4.0)
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--     Flatbuffers:                 builtin/3rdparty (23.5.9)
-- 
--   Python (for build):            /usr/bin/python3
-- 
--   Install to:                    /usr
-- -----------------------------------------------------------------
--