CImgList<uint8_t>* ph_getKeyFramesFromVideo(const char *filename){ long N = GetNumberVideoFrames(filename); if (N < 0){ return NULL; } float frames_per_sec = 0.5*fps(filename); if (frames_per_sec < 0){ return NULL; } int step = (int)(frames_per_sec + ROUNDING_FACTOR(frames_per_sec)); long nbframes = (long)(N/step); float *dist = (float*)malloc((nbframes)*sizeof(float)); if (!dist){ return NULL; } CImg<float> prev(64,1,1,1,0); VFInfo st_info; st_info.filename = filename; st_info.nb_retrieval = 100; st_info.step = step; st_info.pixelformat = 0; st_info.pFormatCtx = NULL; st_info.width = -1; st_info.height = -1; CImgList<uint8_t> *pframelist = new CImgList<uint8_t>(); if (!pframelist){ return NULL; } int nbread = 0; int k=0; do { nbread = NextFrames(&st_info, pframelist); if (nbread < 0){ delete pframelist; free(dist); return NULL; } unsigned int i = 0; while ((i < pframelist->size()) && (k < nbframes)){ CImg<uint8_t> current = pframelist->at(i++); CImg<float> hist = current.get_histogram(64,0,255); float d = 0.0; dist[k] = 0.0; cimg_forX(hist,X){ d = hist(X) - prev(X); d = (d>=0) ? d : -d; dist[k] += d; prev(X) = hist(X); } k++; } pframelist->clear(); } while ((nbread >= st_info.nb_retrieval)&&(k < nbframes));