{"record":{"id":"27a49cd47e942ff1","repo":"Yalantis/uCrop","slug":"save-ffmpeg-external-failed-to-save-file-s-w","errorCode":null,"errorMessage":"save_ffmpeg_external(): Failed to save file '%s' with external command 'ffmpeg'.","messagePattern":"save_ffmpeg_external\\(\\): Failed to save file '(.+?)' with external command 'ffmpeg'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68711,"sourceCode":"          cimg_snprintf(filename_tmp2,filename_tmp2._width,\"%s_%.6u.ppm\",filename_tmp._data,frame);\n          CImg<charT>::string(filename_tmp2).move_to(filenames);\n          CImg<T> _src = src._depth>1?src.get_slice(z):src.get_shared();\n          if (_src._width%2 || _src._height%2) // Force output to have an even number of columns and rows\n            _src.assign(_src.get_resize(_src._width + (_src._width%2),_src._height + (_src._height%2),1,-100,0),false);\n          if (_src._spectrum!=3) // Force output to be one slice, in color\n            _src.assign(_src.get_resize(-100,-100,1,3),false);\n          _src.save_pnm(filename_tmp2);\n          ++frame;\n        }\n      }\n      cimg_snprintf(command,command._width,\n                    \"\\\"%s\\\" -framerate %u -v -8 -y -i \\\"%s_%%6d.ppm\\\" -pix_fmt yuv420p -vcodec %s -b %uk -r %u \\\"%s\\\"\",\n                    cimg::ffmpeg_path(),\n                    fps,CImg<charT>::string(filename_tmp)._system_strescape().data(),\n                    _codec,bitrate,fps,\n                    CImg<charT>::string(filename)._system_strescape().data());\n      if (cimg::system(command,cimg::ffmpeg_path())!=0)\n        throw CImgIOException(_cimglist_instance\n                              \"save_ffmpeg_external(): Failed to save file '%s' with external command 'ffmpeg'.\",\n                              cimglist_instance,\n                              filename);\n      if (!cimg::path_exists(filename))\n        throw CImgIOException(_cimglist_instance\n                              \"save_ffmpeg_external(): Failed to save file '%s' with external command 'ffmpeg'.\",\n                              cimglist_instance,\n                              filename);\n      cimglist_for(*this,l) std::remove(filenames[l]);\n      return *this;\n    }\n\n    //! Serialize a CImgList<T> instance into a raw CImg<unsigned char> buffer.\n    /**\n       \\param is_compressed tells if zlib compression must be used for serialization\n       (this requires 'cimg_use_zlib' been enabled).\n       \\param header_size Reserve empty bytes as a starting header.\n    **/","sourceCodeStart":68693,"sourceCodeEnd":68729,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68693-L68729","documentation":"save_ffmpeg_external() pipes PPM frames to the external 'ffmpeg' binary and rebuilds the video. This error is thrown when the ffmpeg system command returns non-zero, or (second variant) when the output file does not exist afterwards, meaning ffmpeg failed or produced nothing.","triggerScenarios":"Calling save_ffmpeg_external() when the ffmpeg executable is missing/not at cimg::ffmpeg_path(), the requested -vcodec is unsupported by the installed ffmpeg, bad bitrate/fps arguments, disk full, or the output path is unwritable so no file appears after the run.","commonSituations":"Android/CI images without ffmpeg installed; ffmpeg builds lacking the chosen codec (e.g. h264/libx264 unavailable); codec name mismatch after upstream default change ('mpeg2video' fallback); SELinux blocking exec of ffmpeg.","solutions":["Install ffmpeg or point cimg::ffmpeg_path() (CIMG_FFMPEG_PATH env var) to an existing binary","Run 'ffmpeg -encoders' and pick a codec your build supports (e.g. mpeg4, mpeg2video)","Check ffmpeg's stderr from the system call for the exact encoding failure","Verify disk space and write permission on the target path"],"exampleFix":"// before\nframes.save_ffmpeg_external(\"out.mp4\", 25, \"h264\"); // no libx264 in ffmpeg build\n// after\nframes.save_ffmpeg_external(\"out.mp4\", 25, \"mpeg4\"); // encoder present in stock builds","handlingStrategy":"fallback","validationCode":"// C++\nbool ffmpegOk = cimg::path_exists(cimg::ffmpeg_path());\nbool writable = access(dir_of(fname), W_OK) == 0;\nif (!ffmpegOk || !writable) useInternalWriterInstead();","typeGuard":"bool ffmpeg_available() { return cimg::path_exists(cimg::ffmpeg_path()); }","tryCatchPattern":"try { frames.save_ffmpeg_external(fname, fps, codec); }\ncatch (CImgIOException& e) { fprintf(stderr, \"ffmpeg failed: %s\", e.what()); frames.save_video(fname, fps, \"mp4v\"); }","preventionTips":["Bundle/install ffmpeg or set CIMG_FFMPEG_PATH","Choose codecs verified with 'ffmpeg -encoders'","Check disk space before long encodes","Fall back to cv::VideoWriter-based save_video on headless images"],"tags":["video","ffmpeg","external-command","file-write"],"backgroundTag":"file-write-failed","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}