Yalantis/uCrop · warning
load_yuv(): File '%s' contains incomplete data or given imag
Error message
load_yuv(): File '%s' contains incomplete data or given image dimensions (%u,%u) are incorrect.
What it means
Warning from CImgList<T>::load_yuv() when reading the luminance (Y) plane of a raw YUV video/image file. CImg fread()s exactly width*height bytes for the Y channel; if the returned count differs (but is >0), the loader sets stop_flag and warns that the file contains incomplete data or the requested dimensions (size_x,size_y) are incorrect. The load still returns what was read, so downstream code may see zero-filled/partial data.
Source
Thrown at ucrop/src/main/jni/CImg.h:67235
if (nfirst_frame) {
err = cimg::fseek(nfile,(uint64T)nfirst_frame*(YUV._width*YUV._height + 2*UV._width*UV._height),SEEK_CUR);
if (err) {
if (!file) cimg::fclose(nfile);
throw CImgIOException(_cimglist_instance
"load_yuv(): File '%s' doesn't contain frame number %u.",
cimglist_instance,
filename?filename:"(FILE*)",nfirst_frame);
}
}
unsigned int frame;
for (frame = nfirst_frame; !stop_flag && frame<=nlast_frame; frame+=nstep_frame) {
YUV.get_shared_channel(0).fill(0);
// *TRY* to read the luminance part, do not replace by cimg::fread!
err = (int)std::fread((void*)(YUV._data),1,(size_t)YUV._width*YUV._height,nfile);
if (err!=(int)(YUV._width*YUV._height)) {
stop_flag = true;
if (err>0)
cimg::warn(_cimglist_instance
"load_yuv(): File '%s' contains incomplete data or given image dimensions "
"(%u,%u) are incorrect.",
cimglist_instance,
filename?filename:"(FILE*)",size_x,size_y);
} else {
UV.fill(0);
// *TRY* to read the luminance part, do not replace by cimg::fread!
err = (int)std::fread((void*)(UV._data),1,(size_t)UV.size(),nfile);
if (err!=(int)(UV.size())) {
stop_flag = true;
if (err>0)
cimg::warn(_cimglist_instance
"load_yuv(): File '%s' contains incomplete data or given image dimensions "
"(%u,%u) are incorrect.",
cimglist_instance,
filename?filename:"(FILE*)",size_x,size_y);
} else {
const ucharT *ptrs1 = UV._data, *ptrs2 = UV.data(0,0,0,1);View on GitHub (pinned to f788b534b4)
Solutions
- Pass the exact width and height the YUV file was encoded with; confirm with the producer of the raw data.
- Check the file size against the expected frame size for the YUV scheme (e.g. 1.5*size_x*size_y for 4:2:0) and re-obtain the file if truncated.
- Try candidate resolutions and compare file size modulo frame size to infer the true dimensions.
- Validate with a known tool (e.g. ffplay -f rawvideo -pixel_format yuv420p -video_size WxH) before loading in CImg.
- Handle the partial read: stop consuming further frames when stop_flag is set and use only fully read frames.
Example fix
// before: dimensions guessed, file is 640x480 4:2:0
CImgList<ucharT> frames;
frames.load_yuv("capture.yuv", 1280, 720);
// after: correct dimensions for the file
CImgList<ucharT> frames;
frames.load_yuv("capture.yuv", 640, 480);
Defensive patterns
Strategy: validation
Validate before calling
// Validate file size vs expected YUV frame layout before load_yuv
std::error_code ec;
auto sz = std::filesystem::file_size(path, ec);
size_t frameBytes = size_x * size_y * 3 / 2; // 4:2:0
if (ec || sz == 0 || sz % frameBytes != 0)
throw std::runtime_error("YUV file size does not match dimensions/scheme"); Try / catch
// load_yuv warns instead of throwing; check read completeness list.load_yuv(path, W, H); // if warning fired, only fully-read frames are usable; stop consuming further frames
Prevention
- Never guess width/height for raw YUV; get them from the encoder or probe with ffprobe.
- Sanity-check file size against the expected frame byte count for the chroma scheme.
- Re-verify transfers of large raw video dumps with checksums.
- Expect stop_flag semantics: treat a warned load as truncated and drop the partial frame.
When it happens
Trigger: Calling load_yuv(filename,size_x,size_y) (or load_yuv with per-frame loop) on a file whose byte count is not a multiple of the expected frame size implied by size_x*size_y and the YUV scheme; most commonly size_x/size_y passed do not match the actual resolution of the raw file, so the Y read hits EOF early.
Common situations: Wrong width/height passed to load_yuv for a raw dump (e.g. 640x480 file loaded as 1280x720); raw YUV file truncated during capture/transfer; guessing dimensions instead of knowing the encoder's resolution; reading the last partial frame of a streamed capture.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- load_pnm(): PNM header not found in file '%s'.
- load_yuv(): Specified filename is (null).
- load_yuv(): Specified chroma subsampling %u is invalid, for
- load_yuv(): Specified dimensions (%u,%u) are invalid, for fi
- load_yuv(): File '%s' doesn't contain frame number %u.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/07ac4f3a84c8053f.
Report an issue: GitHub.