@use_clip_fps_by_default
def detect_scenes(clip=None, luminosities=None, thr=10, progress_bar=False, fps=None):
 if (luminosities is None):
  luminosities = [f.sum() for f in clip.iter_frames(fps=fps, dtype='uint32', progress_bar=1)]
 luminosities = np.array(luminosities, dtype=float)
 if (clip is not None):
  end = clip.duration
 else:
  end = (len(luminosities) * (1.0 / fps))
 lum_diffs = abs(np.diff(luminosities))
 avg = lum_diffs.mean()
 luminosity_jumps = (1 + np.array(np.nonzero((lum_diffs > (thr * avg))))[0])
 tt = (([0] + list(((1.0 / fps) * luminosity_jumps))) + [end])
 cuts = [(t1, t2) for (t1, t2) in zip(tt, tt[1:])]
 return (cuts, luminosities)

@ use_clip_fps_by_default def detect_scenes ( clip = None , luminosities = None , thr = 10 , progress_bar = False , fps = None ) : if ( luminosities is None ) : luminosities = [ f . sum ( ) for f in clip . iter_frames ( fps = fps , dtype = 'uint32' , progress_bar = 1 ) ] luminosities = np . array ( luminosities , dtype = float ) if ( clip is not None ) : end = clip . duration else : end = ( len ( luminosities ) * ( 1.0 / fps ) ) lum_diffs = abs ( np . diff ( luminosities ) ) avg = lum_diffs . mean ( ) luminosity_jumps = ( 1 + np . array ( np . nonzero ( ( lum_diffs > ( thr * avg ) ) ) ) [ 0 ] ) tt = ( ( [ 0 ] + list ( ( ( 1.0 / fps ) * luminosity_jumps ) ) ) + [ end ] ) cuts = [ ( t1 , t2 ) for ( t1 , t2 ) in zip ( tt , tt [ 1 : ] ) ] return ( cuts , luminosities )
detects scenes of a clip based on luminosity changes .