def gencomp(num: int = 10, path: str = "comp", matrix: str = "709", firstnum: int = 1, **clips: vs.VideoNode) -> None: lens = set(c.num_frames for c in clips.values()) if len(lens) != 1: raise ValueError("gencomp: 'Clips must be equal length!'") frames = sorted(random.sample(range(lens.pop()), num)) print("Sample frames: " + str(frames)) if os.path.exists(path): shutil.rmtree(path) os.makedirs(path) for name, clip in clips.items(): log.status(f"Rendering clip {name}") splice = clip[frames[0]] for f in frames[1:]: splice += clip[f] splice = splice.resize.Bicubic(format=vs.RGB24, matrix_in_s=matrix) \ .imwri.Write("PNG", os.path.join(path, f"{name}%0{len(str(num))}d.png"), firstnum=firstnum) [splice.get_frame(f) for f in range(splice.num_frames)]
def save(*frames: int, rand: int = 0, folder: bool = False, zoom: int = 1, **clips: vs.VideoNode): """ Writes frames as named RGB24 PNG files for easy upload to slowpics.org. Running "save(17, 24, rand=2, folder=True, zoom=3, BD=bd, TV=tv)" will save four 3x-point-upscaled frames (17, 24, and 2 randoms) in folders named 'BD' and 'TV'. :param frames: frame number(s) to save :param rand: number of random frames to extract (Default value = 0) :param folder: saves images into named sub-folders (Default value = False) If True, saving will not prefix image files with clip name. :param zoom: zoom factor (Default value = 1) :param clips: comma separated pairs of name=clip to save frames from :bit depth: ANY :color family: ANY :float precision: ANY :sample type: ANY :subsampling: ANY """ frames = list(frames) if len(frames) == 0 and rand < 1: rand = 1 if rand > 0: max_frame = min(clip.num_frames for name, clip in clips.items()) - 1 if rand == 1: frames.append(randint(0, max_frame)) else: frames = frames + sample(range(max_frame), rand) if folder: for name, clip in clips.items(): os.makedirs(str(name), exist_ok=True) with _cd(str(name)): for f in frames: out = core.imwri.Write(clip[f].resize.Point( width=(zoom * clip.width), height=(zoom * clip.height), format=vs.RGB24, matrix_in_s='709', range=0, range_in=0, dither_type='error_diffusion'), 'PNG', '%06d.png', firstnum=f) out.get_frame(0) else: for name, clip in clips.items(): for f in frames: out = core.imwri.Write(clip[f].resize.Point( width=(zoom * clip.width), height=(zoom * clip.height), format=vs.RGB24, matrix_in_s='709', range=0, range_in=0, dither_type='error_diffusion'), 'PNG', f"{name}%06d.png", firstnum=f) out.get_frame(0)