Yalantis/uCrop · warning

save_video(): Frame %u has incompatible dimension…

Error message

save_video(): Frame %u has incompatible dimension (%u,%u,%u,%u). Some image data may be ignored when writing frame into video file '%s'.

What it means

CImgList::save_video() emits a non-fatal cimg::warn when a frame written to a video file has _spectrum > 3 channels. Video encoders only support up to 3 channels (RGB/HSV etc.); the extra channel data is silently dropped while the remaining channels are written. It is a warning, not an exception: the video is still produced.

Solutions

  1. Reduce each frame to 3 channels before saving: if (img.spectrum()>3) img.channels(0,2);
  2. If the alpha channel matters, composite frames onto an opaque RGB background instead of channels(0,2).
  3. Check spectrum() of your frames before calling save_video() and convert/reject incompatible frames.

Example fix

// before
frames.save_video("out.avi");
// after
cimg_for(frames, it, CImg<unsigned char>) if (it->spectrum()>3) it->channels(0,2);
frames.save_video("out.avi");
Defensive patterns

Strategy: validation

Validate before calling

if (frames.width() == 0) throw std::runtime_error("empty frame list");
for (const CImg<unsigned char>& f : frames)
  if (f.spectrum() > 3)
    fprintf(stderr, "frame %p has %u channels, will be truncated\n", (void*)&f, f.spectrum());

Type guard

bool is_video_compatible(const CImg<unsigned char>& f) {
  return !f.is_empty() && f.spectrum() <= 3;
}

Prevention

When it happens

Trigger: Calling CImgList::save_video() on a list whose frame images have 4+ spectrum channels, e.g. RGBA images, hyperspectral stacks, or tensors loaded with more than 3 color channels.

Common situations: Passing RGBA screenshots or PNG frames (alpha channel) straight to save_video(); processing scientific/hyperspectral data with many bands; accidentally constructing images with spectrum 4 via assign(width,height,depth,4).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

                                  codec0,codec1,codec2,codec3);
          }
          CImg<charT>::string(filename).move_to(filenames[index]);
          sizes(index,0) = W;
          sizes(index,1) = H;
          cimg::mutex(9,0);
        }

        if (!is_empty()) {
          const unsigned int W = sizes(index,0), H = sizes(index,1);
          cimg::mutex(9);
          cimglist_for(*this,l) {
            CImg<T> &src = _data[l];
            if (src.is_empty())
              cimg::warn(_cimglist_instance
                         "save_video(): Skip empty frame %d for file '%s'.",
                         cimglist_instance,l,filename);
            if (src._spectrum>3)
              cimg::warn(_cimglist_instance
                         "save_video(): Frame %u has incompatible dimension (%u,%u,%u,%u). "
                         "Some image data may be ignored when writing frame into video file '%s'.",
                         cimglist_instance,l,src._width,src._height,src._depth,src._spectrum,filename);
            cimg_forZ(src,z) {
              CImg<T> _src = src._depth>1?src.get_slice(z):src.get_shared();
              if (_src._width==W && _src._height==H && _src._spectrum==3)
                writers[index]->write(CImg<ucharT>(_src)._cimg2cvmat());
              else {
                CImg<ucharT> __src(_src,false);
                __src.channels(0,std::min(__src._spectrum - 1,2U)).resize(W,H);
                __src.resize(W,H,1,3,__src._spectrum==1);
                writers[index]->write(__src._cimg2cvmat());
              }
            }
          }
          cimg::mutex(9,0);
        }

View on GitHub (pinned to f788b534b4)