Yalantis/uCrop · error · CImgIOException

load_yuv(): File '%s' doesn't contain frame number %u.

Error message

load_yuv(): File '%s' doesn't contain frame number %u.

What it means

To start at first_frame > 0, load_yuv() seeks past (frame_size * first_frame) bytes; if fseek fails, the file is too short to contain that frame. CImg closes the file and throws CImgIOException naming the missing frame index.

Source

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

        nfirst_frame = first_frame<last_frame?first_frame:last_frame,
        nlast_frame = first_frame<last_frame?last_frame:first_frame,
        nstep_frame = step_frame?step_frame:1;

      if (!size_x || !size_y || size_x%cfx || size_y%cfy)
        throw CImgArgumentException(_cimglist_instance
                                    "load_yuv(): Specified dimensions (%u,%u) are invalid, for file '%s'.",
                                    cimglist_instance,
                                    size_x,size_y,filename?filename:"(FILE*)");

      CImg<ucharT> YUV(size_x,size_y,1,3), UV(size_x/cfx,size_y/cfy,1,2);
      std::FILE *const nfile = file?file:cimg::fopen(filename,"rb");
      bool stop_flag = false;
      int err;
      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);

View on GitHub (pinned to f788b534b4)

Solutions

  1. Compute the frame count as filesize / (size_x*size_y + 2*(size_x/cfx)*(size_y/cfy)) and choose first_frame < count
  2. Verify size_x, size_y and chroma_subsampling match the actual file - wrong values shift the seek arithmetic
  3. Re-download/re-export the file if it is truncated
  4. Start from frame 0 to confirm the file parses, then adjust first_frame

Example fix

// before
imgs.load_yuv("clip.yuv", 640, 480, 420, 100, ~0U); // clip has 50 frames
// after
const unsigned int n = fileSize("clip.yuv") / (640*480 + 2*(320*240));
unsigned int first = std::min(100u, n - 1);
imgs.load_yuv("clip.yuv", 640, 480, 420, first, ~0U);
Defensive patterns

Strategy: validation

Validate before calling

uint64_t frameSize = (uint64_t)w*h + 2*((uint64_t)(w/cfx)*(h/cfy));
uint64_t nFrames = fileSize(path) / frameSize;
if (firstFrame >= nFrames) firstFrame = nFrames ? nFrames - 1 : 0; // clamp

Try / catch

try { imgs.load_yuv(path, w, h, cs, first, last); }
catch (CImgIOException& e) { fprintf(stderr, "frame out of range: %s\n", e.what()); imgs.assign(); }

Prevention

When it happens

Trigger: load_yuv(filename, w, h, cs, first_frame, ...) with first_frame beyond the number of frames actually present; wrong frame_size assumption (incorrect width/height/subsampling) making the computed seek offset overshoot the file; a truncated file.

Common situations: Hardcoding a start frame from a longer clip; using wrong dimensions so frame_size math is wrong even though the frame exists; truncated download/copy; looping over frames without knowing the file length.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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