{"record":{"id":"8d25f0b11ff7c049","repo":"Yalantis/uCrop","slug":"load-video-file-s-unable-to-detect-format-o","errorCode":null,"errorMessage":"load_video(): File '%s', unable to detect format of video file.","messagePattern":"load_video\\(\\): File '(.+?)', unable to detect format of video file\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67382,"sourceCode":"          throw CImgArgumentException(_cimglist_instance\n                                      \"load_video(): No already open video reader found. You must specify a \"\n                                      \"non-(null) filename argument for the first call.\",\n                                      cimglist_instance);\n        else { cimg::mutex(9); cimglist_for(filenames,l) if (!filenames[l]) { index = l; break; } cimg::mutex(9,0); }\n        if (index<0)\n          throw CImgIOException(_cimglist_instance\n                                \"load_video(): File '%s', no video reader slots available. \"\n                                \"You have to release some of your previously opened videos.\",\n                                cimglist_instance,filename);\n        cimg::mutex(9);\n        captures[index] = new cv::VideoCapture(filename);\n        positions[index] = 0;\n        if (!captures[index]->isOpened()) {\n          delete captures[index];\n          captures[index] = 0;\n          cimg::mutex(9,0);\n          cimg::fclose(cimg::fopen(filename,\"rb\")); // Check file availability\n          throw CImgIOException(_cimglist_instance\n                                \"load_video(): File '%s', unable to detect format of video file.\",\n                                cimglist_instance,filename);\n        }\n        CImg<charT>::string(filename).move_to(filenames[index]);\n        cimg::mutex(9,0);\n      }\n\n      cimg::mutex(9);\n      const unsigned int nb_frames = (unsigned int)std::max(0.,captures[index]->get(_cimg_cap_prop_frame_count));\n      cimg::mutex(9,0);\n      assign();\n\n      // Skip frames if requested.\n      bool go_on = true;\n      unsigned int &pos = positions[index];\n      while (pos<first_frame) {\n        cimg::mutex(9);\n        if (!captures[index]->grab()) { cimg::mutex(9,0); go_on = false; break; }","sourceCodeStart":67364,"sourceCodeEnd":67400,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67364-L67400","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlist.load_video(\"media/clip.mov\"); // codec unsupported by OpenCV backend\n\n// after\n// shell: ffmpeg -i media/clip.mov -c:v libx264 -pix_fmt yuv420p clip.mp4\nlist.load_video(\"media/clip.mp4\"); // H.264/MP4 opens reliably","handlingStrategy":"validation","validationCode":"// pre-check: file readable and plausibly a video\nbool loadableVideo(const char* p) {\n  std::ifstream f(p, std::ios::binary);\n  if (!f) return false;\n  char hdr[12] = {0};\n  f.read(hdr, 12);\n  return std::string(hdr).find(\"ftyp\") != std::string::npos ||\n         std::string(hdr).find(\"RIFF\") != std::string::npos;\n}","typeGuard":null,"tryCatchPattern":"try {\n  list.load_video(path);\n} catch (CImgIOException&) {\n  // try ffmpeg external fallback\n  list.load_ffmpeg_external(path);\n}","preventionTips":["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."],"tags":["cimg","opencv","video","codec","file-format"],"backgroundTag":"unsupported-media-format","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"}