{"record":{"id":"6bc45580e797ca74","repo":"Yalantis/uCrop","slug":"load-ffmpeg-external-failed-to-open-file-s-w","errorCode":null,"errorMessage":"load_ffmpeg_external(): Failed to open file '%s' with external command 'ffmpeg'.","messagePattern":"load_ffmpeg_external\\(\\): Failed to open file '(.+?)' with external command 'ffmpeg'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67472,"sourceCode":"    **/\n    CImgList<T>& load_ffmpeg_external(const char *const filename) {\n      if (!filename || !cimg::is_file(filename))\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_ffmpeg_external(): Specified filename is (null) or does not exist.\",\n                                    cimglist_instance);\n      CImg<charT> command(1024), filename_tmp(256), filename_tmp2(256);\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s\",\n                      cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());\n        cimg_snprintf(filename_tmp2,filename_tmp2._width,\"%s_000001.ppm\",filename_tmp._data);\n      } while (cimg::path_exists(filename_tmp2));\n      cimg_snprintf(filename_tmp2,filename_tmp2._width,\"%s_%%6d.ppm\",filename_tmp._data);\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -v -8 -i \\\"%s\\\" \\\"%s\\\"\",\n                    cimg::ffmpeg_path(),\n                    CImg<charT>::string(filename)._system_strescape().data(),\n                    CImg<charT>::string(filename_tmp2)._system_strescape().data());\n      if (cimg::system(command,cimg::ffmpeg_path())!=0)\n        throw CImgIOException(_cimglist_instance\n                              \"load_ffmpeg_external(): Failed to open file '%s' with external command 'ffmpeg'.\",\n                              cimglist_instance,\n                              filename);\n      const unsigned int omode = cimg::exception_mode();\n      cimg::exception_mode(0);\n      assign();\n      unsigned int i = 1;\n      for (bool stop_flag = false; !stop_flag; ++i) {\n        cimg_snprintf(filename_tmp2,filename_tmp2._width,\"%s_%.6u.ppm\",filename_tmp._data,i);\n        CImg<T> img;\n        try { img.load_pnm(filename_tmp2); }\n        catch (CImgException&) { stop_flag = true; }\n        if (img) { img.move_to(*this); std::remove(filename_tmp2); }\n      }\n      cimg::exception_mode(omode);\n      if (is_empty())\n        throw CImgIOException(_cimglist_instance\n                              \"load_ffmpeg_external(): Failed to open file '%s' with external command 'ffmpeg'.\",","sourceCodeStart":67454,"sourceCodeEnd":67490,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67454-L67490","documentation":"load_ffmpeg_external() builds a command line invoking the external ffmpeg binary to decode the video into temporary PPM images. If cimg::system() returns non-zero (ffmpeg missing or it failed to open/decode the input), CImg throws this CImgIOException. It indicates the external ffmpeg invocation failed, not necessarily that the file is absent (that check happened earlier).","triggerScenarios":"cimg::ffmpeg_path() points to a non-existent or non-executable ffmpeg; ffmpeg exits with error because the codec/container is unsupported or the file is corrupt; quoting/escaping issues with exotic filenames.","commonSituations":"Docker/CI images without ffmpeg installed; ffmpeg version too old for the video codec; PATH set differently inside the app (Android) than in the shell.","solutions":["Install ffmpeg or set cimg::ffmpeg_path() to the correct binary location before calling load_video/load_ffmpeg_external.","Run the same ffmpeg command manually on the file to see the real decode error (codec, permissions, corruption).","Re-encode the video with ffmpeg to H.264/MP4, or use the OpenCV backend (cimg_use_opencv) instead.","Verify ffmpeg_path is executable (check version output) from the same process/user context."],"exampleFix":"// before\ncimg::ffmpeg_path(\"/usr/local/bin/ffmpeg\"); // binary absent in container\nlist.load_ffmpeg_external(\"clip.mp4\");\n\n// after\nif (cimg::system(CImg<char>::string(cimg::ffmpeg_path()) + \" -version\") == 0) {\n  list.load_ffmpeg_external(\"clip.mp4\");\n} else {\n  // fall back: re-encode elsewhere or use OpenCV-backed load_video\n}","handlingStrategy":"fallback","validationCode":"// ensure ffmpeg is present and runnable before attempting load\nbool ffmpegAvailable() {\n  return cimg::system(\n    CImg<char>::string(cimg::ffmpeg_path()) + \" -version\") == 0;\n}","typeGuard":null,"tryCatchPattern":"if (!ffmpegAvailable()) { /* use OpenCV backend or fail fast */ }\ntry {\n  list.load_ffmpeg_external(file);\n} catch (CImgIOException&) {\n  list.load_video(file); // OpenCV backend fallback\n}","preventionTips":["Install ffmpeg in your image/container and set cimg::ffmpeg_path() explicitly.","Check ffmpeg -version works from the same process/user before loading.","Normalize input videos to H.264/MP4 to avoid codec-specific ffmpeg failures."],"tags":["cimg","video","ffmpeg","external-tool","process-exit-code"],"backgroundTag":"external-command-failed","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"}