{"record":{"id":"16485fd0a246826d","repo":"Yalantis/uCrop","slug":"load-yuv-specified-dimensions-u-u-are-inval","errorCode":null,"errorMessage":"load_yuv(): Specified dimensions (%u,%u) are invalid, for file '%s'.","messagePattern":"load_yuv\\(\\): Specified dimensions \\(%u,%u\\) are invalid, for file '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67208,"sourceCode":"                           const unsigned int step_frame, const bool yuv2rgb) {\n      if (!filename && !file)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_yuv(): Specified filename is (null).\",\n                                    cimglist_instance);\n      if (chroma_subsampling!=420 && chroma_subsampling!=422 && chroma_subsampling!=444)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_yuv(): Specified chroma subsampling %u is invalid, for file '%s'.\",\n                                    cimglist_instance,\n                                    chroma_subsampling,filename?filename:\"(FILE*)\");\n      const unsigned int\n        cfx = chroma_subsampling==420 || chroma_subsampling==422?2:1,\n        cfy = chroma_subsampling==420?2:1,\n        nfirst_frame = first_frame<last_frame?first_frame:last_frame,\n        nlast_frame = first_frame<last_frame?last_frame:first_frame,\n        nstep_frame = step_frame?step_frame:1;\n\n      if (!size_x || !size_y || size_x%cfx || size_y%cfy)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_yuv(): Specified dimensions (%u,%u) are invalid, for file '%s'.\",\n                                    cimglist_instance,\n                                    size_x,size_y,filename?filename:\"(FILE*)\");\n\n      CImg<ucharT> YUV(size_x,size_y,1,3), UV(size_x/cfx,size_y/cfy,1,2);\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");\n      bool stop_flag = false;\n      int err;\n      if (nfirst_frame) {\n        err = cimg::fseek(nfile,(uint64T)nfirst_frame*(YUV._width*YUV._height + 2*UV._width*UV._height),SEEK_CUR);\n        if (err) {\n          if (!file) cimg::fclose(nfile);\n          throw CImgIOException(_cimglist_instance\n                                \"load_yuv(): File '%s' doesn't contain frame number %u.\",\n                                cimglist_instance,\n                                filename?filename:\"(FILE*)\",nfirst_frame);\n        }\n      }","sourceCodeStart":67190,"sourceCodeEnd":67226,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67190-L67226","documentation":"For the given subsampling, chroma planes are stored at size_x/cfx by size_y/cfy; this only works when the luma dimensions are divisible by cfx/cfy (2 for 420/422 horizontally, 2 for 420 vertically). Dimensions must also be nonzero. CImg validates this up front and throws CImgArgumentException.","triggerScenarios":"load_yuv(filename, w, h, cs, ...) where size_x or size_y is 0, or size_x % cfx != 0 / size_y % cfy != 0 - e.g. 853x480 with 420 (853 not divisible by 2), or any odd width with 422.","commonSituations":"Odd-resolution video encodes (common with H.264 crops to 853x480, 1279x720); swapped width/height arguments; passing frame counts or byte sizes instead of pixel dimensions; zero dimensions from an uninitialized variable.","solutions":["Use the real even dimensions of the stream (e.g. 854x480 instead of 853x480; raw YUV streams are effectively padded to even sizes)","Swap width/height if they were reversed (landscape/portrait mix-up)","Ensure nonzero, actual pixel dimensions are passed - check the variable initialization","If the source is truly odd-sized, pre-pad it (e.g. via ffmpeg -vf pad=ceil(iw/2)*2:ceil(ih/2)*2) and use the padded size"],"exampleFix":"// before\nimgs.load_yuv(\"video.yuv\", 853, 480, 420); // 853 % 2 != 0\n// after\nimgs.load_yuv(\"video.yuv\", 854, 480, 420); // even dimensions","handlingStrategy":"validation","validationCode":"unsigned int cfx = (cs == 420 || cs == 422) ? 2 : 1, cfy = (cs == 420) ? 2 : 1;\nif (w == 0 || h == 0 || w % cfx || h % cfy) { /* pad/reject before loading */ }","typeGuard":"bool validYuvSize(unsigned int w, unsigned int h, unsigned int cs) {\n  unsigned int cfx = (cs==420||cs==422)?2:1, cfy = cs==420?2:1;\n  return w && h && w % cfx == 0 && h % cfy == 0;\n}","tryCatchPattern":"try { imgs.load_yuv(path, w, h, cs); }\ncatch (CImgArgumentException& e) { fprintf(stderr, \"bad YUV dimensions %ux%u: %s\\n\", w, h, e.what()); }","preventionTips":["Pad odd-resolution streams to even dimensions at ingest time","Store width/height alongside raw YUV files in a sidecar manifest","Sanity-check dimension config values at startup"],"tags":["cimg","yuv","invalid-argument","dimensions","video-loading"],"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-14T05:17:10.506Z"}