{"record":{"id":"83fefbfc8e22171b","repo":"Yalantis/uCrop","slug":"save-video-file-s-no-video-writer-slots-ava","errorCode":null,"errorMessage":"save_video(): File '%s', no video writer slots available. You have to release some of your previously opened videos.","messagePattern":"save_video\\(\\): File '(.+?)', no video writer slots available\\. You have to release some of your previously opened videos\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68574,"sourceCode":"        if (filename) {\n          if (last_used_index>=0 && !std::strcmp(filename,filenames[last_used_index])) {\n            index = last_used_index;\n          } else cimglist_for(filenames,l) if (filenames[l] && !std::strcmp(filename,filenames[l])) {\n              index = l; break;\n            }\n        } else index = last_used_index;\n        cimg::mutex(9,0);\n\n        // Find empty slot for capturing video stream.\n        if (index<0) {\n          if (!filename)\n            throw CImgArgumentException(_cimglist_instance\n                                        \"save_video(): No already open video writer 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                                  \"save_video(): File '%s', no video writer slots available. \"\n                                  \"You have to release some of your previously opened videos.\",\n                                  cimglist_instance,filename);\n          if (is_empty())\n            throw CImgInstanceException(_cimglist_instance\n                                        \"save_video(): Instance list is empty.\",\n                                        cimglist_instance);\n          const unsigned int W = _data?_data[0]._width:0, H = _data?_data[0]._height:0;\n          if (!W || !H)\n            throw CImgInstanceException(_cimglist_instance\n                                        \"save_video(): Frame [0] is an empty image.\",\n                                        cimglist_instance);\n          const char\n            *const _codec = codec && *codec?codec:\"h264\",\n            codec0 = cimg::uppercase(_codec[0]),\n            codec1 = _codec[0]?cimg::uppercase(_codec[1]):0,\n            codec2 = _codec[1]?cimg::uppercase(_codec[2]):0,\n            codec3 = _codec[2]?cimg::uppercase(_codec[3]):0;","sourceCodeStart":68556,"sourceCodeEnd":68592,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68556-L68592","documentation":"save_video() keeps a fixed-size pool of concurrent cv::VideoWriter slots. When a new filename is given but every slot is occupied by an unreleased video, this IO exception is thrown telling you to release previously opened videos.","triggerScenarios":"Calling save_video() with a filename when writers[] has no free slot: more videos simultaneously open via save_video() than the pool size allows, without intervening close_save_video() calls.","commonSituations":"Long-running capture loops opening a new output file per camera/recording without closing finished ones; leaks of cv::VideoWriter slots across threads sharing mutex 9.","solutions":["Call close_save_video() (or pass filename and let slots free) for videos you no longer write","Reduce the number of simultaneously open video outputs","Reuse one output file instead of opening a new writer per segment","Audit code paths for missing close_save_video() on error exits"],"exampleFix":"// before\nfor (cam : cams) frames_of(cam).save_video(name(cam)); // slots exhausted\n// after\nfor (cam : cams) { frames_of(cam).save_video(name(cam)); frames_of(cam).close_save_video(); }","handlingStrategy":"validation","validationCode":"// C++\nif (openVideoCount() >= kMaxWriters) close_oldest_video();","typeGuard":null,"tryCatchPattern":"try { frames.save_video(fname, fps, codec); }\ncatch (CImgIOException& e) { frames.close_save_video(); frames.save_video(fname, fps, codec); }","preventionTips":["Close videos with close_save_video() as soon as recording ends","Limit concurrent outputs to the slot pool size","Audit error paths so writers are released on exceptions","Reuse a single output file for segmented recording"],"tags":["video","resource-exhaustion","opencv"],"backgroundTag":"resource-not-found","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"}