{"record":{"id":"d6e3ba4278f31da7","repo":"Yalantis/uCrop","slug":"save-video-frame-0-is-an-empty-image","errorCode":null,"errorMessage":"save_video(): Frame [0] is an empty image.","messagePattern":"save_video\\(\\): Frame \\[0\\] is an empty image\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68584,"sourceCode":"        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;\n          cimg::mutex(9);\n          writers[index] = new cv::VideoWriter(filename,_cimg_fourcc(codec0,codec1,codec2,codec3),fps,cv::Size(W,H));\n          if (!writers[index]->isOpened()) {\n            delete writers[index];\n            writers[index] = 0;\n            cimg::mutex(9,0);\n            throw CImgIOException(_cimglist_instance\n                                  \"save_video(): File '%s', unable to initialize video writer with codec '%c%c%c%c'.\",\n                                  cimglist_instance,filename,\n                                  codec0,codec1,codec2,codec3);","sourceCodeStart":68566,"sourceCodeEnd":68602,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68566-L68602","documentation":"Guard in CImgList<T>::save_video(): the first frame of the list (element [0]) is an empty image; the video writer needs valid frame dimensions derived from frame [0] to initialize the stream, so an empty first frame aborts saving.","triggerScenarios":"Calling save_video() where the first frame in the list is a 0-width or 0-height image (default-constructed CImg, or failed frame allocation).","commonSituations":"Appending default-constructed CImg placeholders into the list; camera delivering an empty first frame before streaming starts.","solutions":["Validate frames[0].width()>0 && frames[0].height()>0 before saving","Skip or replace empty frames when populating the list","Only append frames after confirming the capture succeeded"],"exampleFix":"// before\nframes.push_back(CImg<unsigned char>()); // empty placeholder\nframes.save_video(\"out.avi\", 25);\n// after\nif (!frame.is_empty()) frames.push_back(frame);\nframes.save_video(\"out.avi\", 25);","handlingStrategy":"validation","validationCode":"// C++\nbool valid = !frames.is_empty() && frames[0].width() > 0 && frames[0].height() > 0;\nif (!valid) return;","typeGuard":"bool hasSizedFrame(const CImgList<T>& l) { return !l.is_empty() && l[0].width() > 0 && l[0].height() > 0; }","tryCatchPattern":"try { frames.save_video(fname, fps, codec); }\ncatch (CImgInstanceException& e) { log(\"first frame empty, skipping save\"); }","preventionTips":["Never append default-constructed CImg placeholders","Drop frames where width()==0 || height()==0 at capture time","Assert frame dimensions when appending","Validate capture device output before recording"],"tags":["video","empty-data","opencv","dimensions"],"backgroundTag":"empty-required-field","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"}