Yalantis/uCrop · error · CImgArgumentException

save_video(): No already open video writer found. You must…

Error message

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

What it means

save_video() supports resuming writes to an already-open cv::VideoWriter by passing a null filename on subsequent calls. This argument exception is thrown when the first call (or a call after all slots were closed) passes a null filename, so there is no open writer to reuse.

Solutions

  1. Pass a valid non-null output filename (e.g. 'out.avi') on the first save_video() call for the list
  2. Track whether a writer is already open before passing null
  3. Re-open a writer with a filename after any close_save_video()
  4. Refactor to keep one persistent list instance for the whole video-writing session

Example fix

// before
frames.save_video(nullptr); // first call, no open writer
// after
frames.save_video("output.avi", 25, "h264"); // first call needs filename
Defensive patterns

Strategy: validation

Validate before calling

// C++
bool firstCall = !writerOpen;
if (firstCall && (filename == nullptr || filename[0] == '\0')) return fail("filename required for first save_video call");

Type guard

bool hasFilename(const char* f) { return f != nullptr && f[0] != '\0'; }

Try / catch

try { frames.save_video(fname, fps, codec); }
catch (CImgArgumentException& e) { fprintf(stderr, "need filename on first call: %s", e.what()); }

Prevention

When it happens

Trigger: Calling list.save_video((const char*)0, ...) or save_video(nullptr) with no video writer previously opened for this list; the internal index lookup returns -1 and filename is null.

Common situations: Reusing save_video code paths across lists without keeping the filename argument on the first call; mismanaged writer lifecycle where close_save_video() was already called.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

        static CImg<intT> sizes(32,2,1,1,0);
        static int last_used_index = -1;

        // Detect if a video writer already exists for the specified filename.
        cimg::mutex(9);
        int index = -1;
        if (filename) {
          if (last_used_index>=0 && !std::strcmp(filename,filenames[last_used_index])) {
            index = last_used_index;
          } else cimglist_for(filenames,l) if (filenames[l] && !std::strcmp(filename,filenames[l])) {
              index = l; break;
            }
        } else index = last_used_index;
        cimg::mutex(9,0);

        // Find empty slot for capturing video stream.
        if (index<0) {
          if (!filename)
            throw CImgArgumentException(_cimglist_instance
                                        "save_video(): No already open video writer 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
                                  "save_video(): File '%s', no video writer slots available. "
                                  "You have to release some of your previously opened videos.",
                                  cimglist_instance,filename);
          if (is_empty())
            throw CImgInstanceException(_cimglist_instance
                                        "save_video(): Instance list is empty.",
                                        cimglist_instance);
          const unsigned int W = _data?_data[0]._width:0, H = _data?_data[0]._height:0;
          if (!W || !H)
            throw CImgInstanceException(_cimglist_instance
                                        "save_video(): Frame [0] is an empty image.",
                                        cimglist_instance);

View on GitHub (pinned to f788b534b4)