Error in Java: can't find starting number (in the name of file)

Using the last version of OpenCV 4.5.2 with Java on Windows 10. Below is a short reproducible test case which results in

[ERROR:0] global C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\videoio\src\cap.cpp (589) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.2) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): C:/testfiles/output.avi in function 'cv::icvExtractPattern'

Here is the code:

public class OpenCVError {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        final int fourcc = VideoWriter.fourcc('m', 'j', 'p', 'g');
        final double fps = 30.00;
        Size frameSize = new Size(1080, 1920);
        VideoWriter videoWriter = new VideoWriter("C:/testfiles/output.avi", fourcc, fps, frameSize, true);
    }
}
  • make sure opencv_videoio_ffmpeg452_64.dll can be found at runtime
    (folder w opencv dlls should be on the PATH)
  • set an env var: set OPENCV_VIDEOIO_DEBUG=1
    to see which video backends are available / tried
    rerun code, and report back, please
  • System.out.println(Core.getBuildInformation());
    (there’s a “Video IO” section)

Thank you. I am using this Maven dependacy:

  <dependency>
            <groupId>org.openpnp</groupId>
            <artifactId>opencv</artifactId>
            <version>4.5.1-2</version>
  </dependency>

I thought it was all self-contained. I see it has opencv_java451.dll, but I don’t see any other dll’s. What else do I need?

I’m new to OpenCV.

Here are the logs from turning on Debug

[ WARN:0] global C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\videoio\src\cap.cpp (108) cv::VideoCapture::open VIDEOIO(FFMPEG): trying capture filename=‘file:/C:/VideoSandbox/target/classes/streetsign.mov’ …
[ WARN:0] global C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\videoio\src\cap.cpp (170) cv::VideoCapture::open VIDEOIO(FFMPEG): backend is not available (plugin is missing, or can’t be loaded due dependencies or it is not compatible)

(120) cv::VideoCapture::open VIDEOIO(MSMF): created, isOpened=1
(524) cv::VideoWriter::open VIDEOIO(FFMPEG): trying writer with filename=‘C:/testfiles/output.avi’ fourcc=0x67706a6d fps=23.976 sz=1280x720 isColor=1…
(583) cv::VideoWriter::open VIDEOIO(FFMPEG): backend is not available (plugin is missing, or can’t be loaded due dependencies or it is not compatible)

(524) cv::VideoWriter::open VIDEOIO(INTEL_MFX): trying writer with filename=‘C:/testfiles/output.avi’ fourcc=0x67706a6d fps=23.976 sz=1280x720 isColor=1…
(583) cv::VideoWriter::open VIDEOIO(INTEL_MFX): backend is not available (plugin is missing, or can’t be loaded due dependencies or it is not compatible)
(524) cv::VideoWriter::open VIDEOIO(MSMF): trying writer with filename=‘C:/testfiles/output.avi’ fourcc=0x67706a6d fps=23.976 sz=1280x720 isColor=1…

(556) cv::VideoWriter::open VIDEOIO(MSMF): can’t create writer
(524) cv::VideoWriter::open VIDEOIO(CV_IMAGES): trying writer with filename=‘C:/testfiles/output.avi’ fourcc=0x67706a6d fps=23.976 sz=1280x720 isColor=1…
(563) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

cpp:253: error: (-5:Bad argument) CAP_IMAGES: can’t find starting number (in the name of file): C:/testfiles/output.avi in function ‘cv::icvExtractPattern’

cv::VideoWriter::open VIDEOIO(CV_MJPEG): trying writer with filename=‘C:/testfiles/output.avi’ fourcc=0x67706a6d fps=23.976 sz=1280x720 isColor=1…
cv::VideoWriter::open VIDEOIO(CV_MJPEG): can’t create writer

Here is the Video I/O config

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.91.100)
      avformat:                  YES (58.45.100)
      avutil:                    YES (56.51.100)
      swscale:                   YES (5.7.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      NO

sorry, i have no idea about maven.

opencv_videoio_ffmpeg452_64.dll

(maybe pester the maven folks to pack that, too !)

that means it was compiled with ffmpeg (and this should be used for video files, but again, if the dll is missing, it will fall through trying any other backend possible, ending with the “write single images” one.)

i don’t understand this one. CV_MJPEG is the builtin, native, homegrown mjpg codec, it MUST work out-of-the-box.

‘C:/testfiles

does it exist ? (VideoWriter can’t create intermediate dirs)

Yes, the directory exists.

Is there a more official maven distribution? I tried pointing to the dll by setting java.library.path or jna.library.path, but it didn’t seem to have any affect

no, it’s not loaded from java, but from some internal c++ code, so it must be on the PATH (or next to where your app starts)

there is NO official maven distro

you can try the binaries from sourceforge, they should contain both the java bindings & the ffmpeg dll (but that’s another XXX download)