cap.isOpened() always returns false

Hello
I make some tests with OpenCV and videos.
I first tested with MP4 videos using H264 (codec checked and video running in VLC), isOpened returns false. I tested with a standard MPEG video using “MPEG-1/2 Video” (codec checked and video running in VLC) but still isOpened returns false.
The video is opened with cv::VideoCapture cap("D:\\Download\\sample.mpeg");, the file is there. I tried with cv::VideoCapture cap("D:/Download/sample.mpeg");, but this is not better.

getBuildInformation() returns

General configuration for OpenCV 4.7.0-dev =====================================
  Version control:               4.7.0-1-g9208dcb07c

  Platform:
    Timestamp:                   2022-12-28T15:49:34Z
    Host:                        Windows 10.0.19045 AMD64
    CMake:                       3.23.3
    CMake generator:             Visual Studio 16 2019
    CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
    MSVC:                        1928
    Configuration:               Debug 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 (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (32 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:                C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe  (ver 19.28.29334.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP  /MD /O2 /Ob2 /DNDEBUG 
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP  /MDd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /MD /O2 /Ob2 /DNDEBUG 
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /MDd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64  /INCREMENTAL:NO 
    Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL 
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoio world
    Disabled:                    python3
    Disabled by dependency:      -
    Unavailable:                 java python2 ts
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI: 
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.13)
    JPEG:                        build-libjpeg-turbo (ver 2.1.3-62)
      SIMD Support Request:      YES
      SIMD Support:              NO
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   C:/GHA-OCV-2/_work/ci-gha-workflow/ci-gha-workflow/build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/GHA-OCV-2/_work/ci-gha-workflow/ci-gha-workflow/build/3rdparty/ippicv/ippicv_win/iw
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/GHA-OCV-2/_work/ci-gha-workflow/ci-gha-workflow/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            C:/Python-3.9/python.exe

  Java:                          
    ant:                         C:/apache-ant-1.9.15/bin/ant.bat (ver 1.9.15)
    JNI:                         C:/Program Files/Java/jdk-11.0.9/include C:/Program Files/Java/jdk-11.0.9/include/win32 C:/Program Files/Java/jdk-11.0.9/include
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    C:/GHA-OCV-2/_work/ci-gha-workflow/ci-gha-workflow/install
-----------------------------------------------------------------

What do I do wrong, please?
Thanks
David

Weird…

can you change .mpeg in .mp4?

Same.
I copied ffmpeg.exe in the software directory. Same.

Is there a way to get the reason why isopened() returns false?

use your debugger

bullshit.

however, there IS an opencv_ffmpeg.dll, make sure, that is on the PATH (or otherwise available to your exe), it contains ALL functionality to play video files on windows

I’m certainly not used to it, but how can you use the debugger to know what happens internally in VideoCapture constructor or isopened()?

ffprobe on the video file please.

Input #0, mpeg, from ‘sample.mp4’:
Duration: 00:00:13.28, start: 0.533367, bitrate: 341 kb/s
Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 640x360 [SAR 1:1 DAR 16:9], 104857 kb/s, 29.97 fps, 29.97 tbr, 90k tbn

The files are in the directory
image

(my code is 64 bits)

I’m sure I’m doing something wrong:
If I just want to read images and videos (imread(), VideoCapture::read()), do I need to add the whole list of LIBs provided with OpenCV in the dependencies? Same for the DLL, should I provide all of them with my program? Shouldn’t there be an error message thrown by Windows if a DLL is missing?
Thanks and sorry for th newbie questions.

no, you should add the folder containing the dlls to the PATH, like:

set PATH=%PATH%;c:\opencv\bin

Thanks for your answer. If I want to distribute my program, do I need to package the whole list of DLLs with it?

either that, or make ppl install prebuilt binaries (e.g. github release) as well

OK thanks again, I’m gonna test if that solve my problem.

OK I’ve passed the “isOpened()” step, now with this video

and this code:

                            cv::VideoCapture cap("E:\\Download\\sample.mp4");
                            if (!cap.isOpened())
                            {
                                MessageBoxA(hImages, "Can't open the file", "Failed", MB_OK);
                                return false;
                            }
                            cv::Mat tmat;
                            cap >> tmat;
                            if (tmat.empty())
                            {
                                cap.release();
                                tmat.release();
                                return TRUE;
                            }

tmat.empty() is always true.

OK I think I found why: there is no 64 bit debug dll for ffmpeg, “opencv_videoio_ffmpeg451_64.dll” makes my code work in release configuration, but if I run it in debug configuration, “tmat.empty()” is always true. Is there a place where I can find the 64 bit debug dll, please?

I just made a copy and renamed it “opencv_videoio_ffmpeg451_64d.dll”, it works, but it would be fine to have the real debug version, please.
Thanks for your time.

General configuration for OpenCV 4.7.0-dev =====================================
  Version control:               4.7.0-1-g9208dcb07c

and

“opencv_videoio_ffmpeg451_64.dll” makes my code works in release configuration,
?

H264 is Codec MP 1/2 Video (mpgv) ?

4.7.0 ? dont mix versions here, please

Sorry:

  • @laurent.berger : My first try was with H264 MP4 codec, then I switched to “Codec MP 1/2 Video (mpgv)” video I downloaded from internet, both were not working. You asked me to change the extension of the mpeg file to MP4.
  • @berak : I didn’t mix 4.5.1 and 4.7.0, I reverted to 4.5.1, because I wanted to start from full examples I found to be sure that every thing was working or not.
1 Like