{"record":{"id":"6a427d177e918188","repo":"Yalantis/uCrop","slug":"save-ffmpeg-external-invalid-instance-dimension","errorCode":null,"errorMessage":"save_ffmpeg_external(): Invalid instance dimensions for file '%s'.","messagePattern":"save_ffmpeg_external\\(\\): Invalid instance dimensions for file '(.+?)'\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68680,"sourceCode":"    **/\n    const CImgList<T>& save_ffmpeg_external(const char *const filename, const unsigned int fps=25,\n                                            const char *const codec=0, const unsigned int bitrate=2048) const {\n      if (!filename)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"save_ffmpeg_external(): Specified filename is (null).\",\n                                    cimglist_instance);\n      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n\n      const char\n        *const ext = cimg::split_filename(filename),\n        *const _codec = codec?codec:\n        !cimg::strcasecmp(ext,\"flv\")?\"flv\":\n        !cimg::strcasecmp(ext,\"mp4\")?\"h264\":\"mpeg2video\";\n\n      CImg<charT> command(1024), filename_tmp(256), filename_tmp2(256);\n      CImgList<charT> filenames;\n      cimglist_for(*this,l) if (!_data[l].is_sameXYZ(_data[0]))\n        throw CImgInstanceException(_cimglist_instance\n                                    \"save_ffmpeg_external(): Invalid instance dimensions for file '%s'.\",\n                                    cimglist_instance,\n                                    filename);\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s\",\n                      cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());\n        cimg_snprintf(filename_tmp2,filename_tmp2._width,\"%s_000001.ppm\",filename_tmp._data);\n      } while (cimg::path_exists(filename_tmp2));\n      unsigned int frame = 1;\n      cimglist_for(*this,l) {\n        CImg<T>& src = _data[l];\n        cimg_forZ(src,z) {\n          cimg_snprintf(filename_tmp2,filename_tmp2._width,\"%s_%.6u.ppm\",filename_tmp._data,frame);\n          CImg<charT>::string(filename_tmp2).move_to(filenames);\n          CImg<T> _src = src._depth>1?src.get_slice(z):src.get_shared();\n          if (_src._width%2 || _src._height%2) // Force output to have an even number of columns and rows\n            _src.assign(_src.get_resize(_src._width + (_src._width%2),_src._height + (_src._height%2),1,-100,0),false);\n          if (_src._spectrum!=3) // Force output to be one slice, in color","sourceCodeStart":68662,"sourceCodeEnd":68698,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68662-L68698","documentation":"ffmpeg encodes a sequence of images that must all have identical dimensions; save_ffmpeg_external() verifies every list frame has the same X,Y,Z sizes as frame [0] and throws this instance exception when they differ.","triggerScenarios":"Calling save_ffmpeg_external() on a list whose frames have mismatched width/height/depth — e.g. mixed camera resolutions, appended frames of different sizes, or frames with non-zero depth (volume images).","commonSituations":"Recording from multiple cameras into one list; frames resized/cropped inconsistently; accidentally including 3D volumes in the list.","solutions":["Normalize all frames to one size (e.g. frames[l].resize(W,H)) before saving","Ensure every appended frame comes from the same capture geometry","Split differently-sized sequences into separate lists/files","Check _data[l].is_sameXYZ(_data[0]) yourself before calling"],"exampleFix":"// before\nframes.push_back(cam2_frame); // different resolution\nframes.save_ffmpeg_external(\"out.mp4\");\n// after\ncam2_frame.resize(frames[0].width(), frames[0].height());\nframes.push_back(cam2_frame);\nframes.save_ffmpeg_external(\"out.mp4\");","handlingStrategy":"validation","validationCode":"// C++\nbool uniform = true;\ncimglist_for(frames, l) if (!frames[l].is_sameXYZ(frames[0])) { uniform = false; break; }\nif (!uniform) normalizeSizes(frames);","typeGuard":"bool uniformDims(const CImgList<T>& l) { cimglist_for(l,i) if (!l[i].is_sameXYZ(l[0])) return false; return true; }","tryCatchPattern":"try { frames.save_ffmpeg_external(fname, fps, codec); }\ncatch (CImgInstanceException& e) { normalizeSizes(frames); frames.save_ffmpeg_external(fname, fps, codec); }","preventionTips":["Resize/crop every frame to a fixed resolution before appending","Keep volumes (depth>1) out of video frame lists","Assert is_sameXYZ against frame 0 when appending","Separate multi-camera streams into distinct lists"],"tags":["video","ffmpeg","dimensions","shape-mismatch"],"backgroundTag":"shape-mismatch","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"}