{"record":{"id":"786777aea7a05337","repo":"Yalantis/uCrop","slug":"save-video-frame-u-has-incompatible-dimension","errorCode":null,"errorMessage":"save_video(): Frame %u has incompatible dimension (%u,%u,%u,%u). Some image data may be ignored when writing frame into video file '%s'.","messagePattern":"save_video\\(\\): Frame %u has incompatible dimension \\(%u,%u,%u,%u\\)\\. Some image data may be ignored when writing frame into video file '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68620,"sourceCode":"                                  codec0,codec1,codec2,codec3);\n          }\n          CImg<charT>::string(filename).move_to(filenames[index]);\n          sizes(index,0) = W;\n          sizes(index,1) = H;\n          cimg::mutex(9,0);\n        }\n\n        if (!is_empty()) {\n          const unsigned int W = sizes(index,0), H = sizes(index,1);\n          cimg::mutex(9);\n          cimglist_for(*this,l) {\n            CImg<T> &src = _data[l];\n            if (src.is_empty())\n              cimg::warn(_cimglist_instance\n                         \"save_video(): Skip empty frame %d for file '%s'.\",\n                         cimglist_instance,l,filename);\n            if (src._spectrum>3)\n              cimg::warn(_cimglist_instance\n                         \"save_video(): Frame %u has incompatible dimension (%u,%u,%u,%u). \"\n                         \"Some image data may be ignored when writing frame into video file '%s'.\",\n                         cimglist_instance,l,src._width,src._height,src._depth,src._spectrum,filename);\n            cimg_forZ(src,z) {\n              CImg<T> _src = src._depth>1?src.get_slice(z):src.get_shared();\n              if (_src._width==W && _src._height==H && _src._spectrum==3)\n                writers[index]->write(CImg<ucharT>(_src)._cimg2cvmat());\n              else {\n                CImg<ucharT> __src(_src,false);\n                __src.channels(0,std::min(__src._spectrum - 1,2U)).resize(W,H);\n                __src.resize(W,H,1,3,__src._spectrum==1);\n                writers[index]->write(__src._cimg2cvmat());\n              }\n            }\n          }\n          cimg::mutex(9,0);\n        }\n","sourceCodeStart":68602,"sourceCodeEnd":68638,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68602-L68638","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Reduce each frame to 3 channels before saving: if (img.spectrum()>3) img.channels(0,2);","If the alpha channel matters, composite frames onto an opaque RGB background instead of channels(0,2).","Check spectrum() of your frames before calling save_video() and convert/reject incompatible frames."],"exampleFix":"// before\nframes.save_video(\"out.avi\");\n// after\ncimg_for(frames, it, CImg<unsigned char>) if (it->spectrum()>3) it->channels(0,2);\nframes.save_video(\"out.avi\");","handlingStrategy":"validation","validationCode":"if (frames.width() == 0) throw std::runtime_error(\"empty frame list\");\nfor (const CImg<unsigned char>& f : frames)\n  if (f.spectrum() > 3)\n    fprintf(stderr, \"frame %p has %u channels, will be truncated\\n\", (void*)&f, f.spectrum());","typeGuard":"bool is_video_compatible(const CImg<unsigned char>& f) {\n  return !f.is_empty() && f.spectrum() <= 3;\n}","tryCatchPattern":null,"preventionTips":["Normalize all frames to RGB (spectrum()==3) in a single preprocessing pass before any save_video call","Strip or composite alpha channels right after loading RGBA sources","Assert spectrum() <= 3 in debug builds when building frame lists"],"tags":["cimg","video","spectrum","channels","warning"],"backgroundTag":"invalid-argument-value","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}