Yalantis/uCrop · error · CImgIOException
load_video(): File '%s', unable to detect format of video fi
Error message
load_video(): File '%s', unable to detect format of video file.
What it means
After allocating a cv::VideoCapture for the given filename, CImg checks isOpened(). If OpenCV cannot open the file (unsupported codec, corrupt container, unreadable file), the capture is destroyed and this CImgIOException is thrown after verifying the file can at least be fopen-ed. It effectively means 'OpenCV could not detect a readable video format for this file'.
Source
Thrown at ucrop/src/main/jni/CImg.h:67382
throw CImgArgumentException(_cimglist_instance
"load_video(): No already open video reader found. You must specify a "
"non-(null) filename argument for the first call.",
cimglist_instance);
else { cimg::mutex(9); cimglist_for(filenames,l) if (!filenames[l]) { index = l; break; } cimg::mutex(9,0); }
if (index<0)
throw CImgIOException(_cimglist_instance
"load_video(): File '%s', no video reader slots available. "
"You have to release some of your previously opened videos.",
cimglist_instance,filename);
cimg::mutex(9);
captures[index] = new cv::VideoCapture(filename);
positions[index] = 0;
if (!captures[index]->isOpened()) {
delete captures[index];
captures[index] = 0;
cimg::mutex(9,0);
cimg::fclose(cimg::fopen(filename,"rb")); // Check file availability
throw CImgIOException(_cimglist_instance
"load_video(): File '%s', unable to detect format of video file.",
cimglist_instance,filename);
}
CImg<charT>::string(filename).move_to(filenames[index]);
cimg::mutex(9,0);
}
cimg::mutex(9);
const unsigned int nb_frames = (unsigned int)std::max(0.,captures[index]->get(_cimg_cap_prop_frame_count));
cimg::mutex(9,0);
assign();
// Skip frames if requested.
bool go_on = true;
unsigned int &pos = positions[index];
while (pos<first_frame) {
cimg::mutex(9);
if (!captures[index]->grab()) { cimg::mutex(9,0); go_on = false; break; }View on GitHub (pinned to f788b534b4)
Solutions
- Verify the file is a real video (e.g. run ffprobe/ffmpeg on it) and re-encode to a widely supported codec such as H.264 in an MP4 container.
- Check that the path is a plain filesystem path readable by native code (copy content:// URIs to local storage first).
- Ensure the OpenCV build includes the FFmpeg/GStreamer video-io backend for the codecs you need.
- Fall back to CImgList::load_ffmpeg_external() (external ffmpeg binary) which uses ffmpeg's own demuxers.
Example fix
// before
list.load_video("media/clip.mov"); // codec unsupported by OpenCV backend
// after
// shell: ffmpeg -i media/clip.mov -c:v libx264 -pix_fmt yuv420p clip.mp4
list.load_video("media/clip.mp4"); // H.264/MP4 opens reliably Defensive patterns
Strategy: validation
Validate before calling
// pre-check: file readable and plausibly a video
bool loadableVideo(const char* p) {
std::ifstream f(p, std::ios::binary);
if (!f) return false;
char hdr[12] = {0};
f.read(hdr, 12);
return std::string(hdr).find("ftyp") != std::string::npos ||
std::string(hdr).find("RIFF") != std::string::npos;
} Try / catch
try {
list.load_video(path);
} catch (CImgIOException&) {
// try ffmpeg external fallback
list.load_ffmpeg_external(path);
} Prevention
- Re-encode videos to H.264/MP4 before handing them to CImg.
- Copy content:// URIs to a local file before loading on Android.
- Ensure the OpenCV build has FFmpeg video-io enabled for your codecs.
When it happens
Trigger: load_video() with a path that exists but is not a decodable video (wrong extension, unsupported codec/container, truncated file), on an OpenCV-enabled CImg build.
Common situations: Android apps passing content:// URIs or app-internal paths that the NDK OpenCV build cannot decode; videos encoded with codecs missing from the bundled FFmpeg/OpenCV; corrupted downloads.
Related errors
- load_video() : File '%s', arguments 'first_frame', 'last_fra
- load_video(): No already open video reader found. You must s
- load_video(): File '%s', no video reader slots available. Yo
- load_video(): File '%s', unable to locate frame %u.
- save_video(): File '%s', unable to initialize video writer w
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/8d25f0b11ff7c049.
Report an issue: GitHub.