Yalantis/uCrop · error · CImgArgumentException

load_video(): No already open video reader found. You must s

Error message

load_video(): No already open video reader found. You must specify a non-(null) filename argument for the first call.

What it means

In the OpenCV-backed load_video(), passing filename=nullptr with index<0 means 'continue with the already open video reader'. If no such reader exists (this is the first call), CImg throws this CImgArgumentException because there is nothing to continue from. The API contract requires a non-null filename on the first call to open a capture slot.

Source

Thrown at ucrop/src/main/jni/CImg.h:67364

          if (last_used_index==index) last_used_index = -1;
          index = -1;
          cimg::mutex(9,0);
        } else
          if (filename)
            cimg::warn(_cimglist_instance
                       "load_video() : File '%s', no opened video stream associated with filename found.",
                       cimglist_instance,filename);
          else
            cimg::warn(_cimglist_instance
                       "load_video() : No opened video stream found.",
                       cimglist_instance,filename);
        if (!step_frame) return *this;
      }

      // Find empty slot for capturing video stream.
      if (index<0) {
        if (!filename)
          throw CImgArgumentException(_cimglist_instance
                                      "load_video(): No already open video reader found. You must specify a "
                                      "non-(null) filename argument for the first call.",
                                      cimglist_instance);
        else { cimg::mutex(9); cimglist_for(filenames,l) if (!filenames[l]) { index = l; break; } cimg::mutex(9,0); }
        if (index<0)
          throw CImgIOException(_cimglist_instance
                                "load_video(): File '%s', no video reader slots available. "
                                "You have to release some of your previously opened videos.",
                                cimglist_instance,filename);
        cimg::mutex(9);
        captures[index] = new cv::VideoCapture(filename);
        positions[index] = 0;
        if (!captures[index]->isOpened()) {
          delete captures[index];
          captures[index] = 0;
          cimg::mutex(9,0);
          cimg::fclose(cimg::fopen(filename,"rb")); // Check file availability
          throw CImgIOException(_cimglist_instance

View on GitHub (pinned to f788b534b4)

Solutions

  1. Pass a valid, existing video filename on the first load_video call to open a reader slot.
  2. Ensure the initial open call succeeded before switching to null-filename continuation calls.
  3. Reuse the same CImgList instance across calls so its internal captures[] state (and last_used_index) is preserved.

Example fix

// before
CImgList<unsigned char> frames;
frames.load_video(nullptr, 0, ~0U, 1, -1); // no reader open -> throws

// after
CImgList<unsigned char> frames;
frames.load_video("clip.mp4", 0, ~0U, 1, -1); // opens reader first
// subsequent calls may use nullptr to continue with the open reader
frames.load_video(nullptr, 5, ~0U, 1, -1);
Defensive patterns

Strategy: validation

Validate before calling

// track whether a reader was opened
bool readerOpened = false;
// first call must pass a real filename:
if (!readerOpened && filename == nullptr) {
  // refuse to call with nullptr before the first successful open
}

Type guard

bool canLoadContinuation(const char* filename, bool readerOpen) {
  return filename != nullptr || readerOpen;
}

Try / catch

try {
  list.load_video(filename, first, last, step, index);
} catch (CImgArgumentException&) {
  // no open reader: open with a real filename first
  list.load_video(realFile, 0, ~0U, 1, -1);
}

Prevention

When it happens

Trigger: Calling CImgList::load_video(nullptr, ..., index) (or relying on the null-filename continuation mode) before any successful call opened a video, so the internal captures[] array has no active reader.

Common situations: Incremental frame-pulling code that calls load_video(nullptr) on each iteration but whose first call failed (e.g. the file was missing), leaving no open reader for subsequent null-filename calls.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/d6feb91ccea5f276. Report an issue: GitHub.