def draw(comp, base, fine, W=3000, H=2000): arr = np.zeros((H, W, 3), np.uint8) segs = reduce( lambda x, y: x + y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) out_t = 0 duration = max([X.start + X.duration for X in segs]) for seg in segs: cv2.line(arr, (int(W * (out_t / duration)), 0), (int(W * (seg.start / duration)), H), (255, 255, 255)) out_t += seg.duration base = cv2.resize(numm.image2np(base), (W, H)) fine = cv2.resize(numm.image2np(fine), (W, H)) divisors = np.linspace(0, 1, H).reshape((-1, 1, 1)) comp = ((base * (1 - divisors)) + (fine * divisors)).astype(np.uint8) numm.np2image(comp, 'COMP.PNG') comp[arr == 0] = 0 return comp
def draw(comp, base, fine, W=3000, H=2000): arr = np.zeros((H,W,3), np.uint8) segs = reduce(lambda x,y: x+y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) out_t = 0 duration = max([X.start+X.duration for X in segs]) for seg in segs: cv2.line(arr, (int(W*(out_t/duration)), 0), (int(W*(seg.start/duration)), H), (255,255,255)) out_t += seg.duration base = cv2.resize(numm.image2np(base), (W,H)) fine = cv2.resize(numm.image2np(fine), (W,H)) divisors = np.linspace(0, 1, H).reshape((-1,1,1)) comp = ((base*(1-divisors)) + (fine*divisors)).astype(np.uint8) numm.np2image(comp, 'COMP.PNG') comp[arr==0] = 0 return comp
def do_image(args): print("Doing just the one frame, saved as an image") import numm # do_video with just one frame and save that args.frame_limit = 1 frames = fill_frames(args) image = frames[0] numm.np2image(image, args.inputvideofile + ".png")
def serialize(audiofile, directory=None): import os, time t0 = time.time() if directory is None: directory = audiofile + '.analysis' directory = os.path.join(directory, 'audio') if not os.path.isdir(directory): os.makedirs(directory) for idx,wform in enumerate(waveform(audiofile)): numm.np2image(wform, os.path.join(directory, "%06d.png" % (idx))) dt = time.time() - t0 dur = idx * 20 ratio = dur / dt print 'analyzed a ~%ds audio file in %ds (%.2fx)' % (dur, dt, ratio)
def do_video(args): import numm if args.output: output_fname = args.output else: output_fname = "%s_filled.mp4" % args.inputvideofile if args.np2video: frames = fill_frames(args) print("Now running numm.np2video to create video file (could be huge)") numm.np2video(frames, output_fname) return work_dir = tempfile.mkdtemp(suffix="_screenfiller_frames") print("Saving frames as .png files in batches of 100") global raw raw = load_video(args) if args.frame_limit: args.output_frames = args.frame_limit else: args.output_frames = len(raw) for coarse in range(0, args.output_frames, 100): args.frame_limit = 100 frames = fill_frames(args, start=coarse) for fnum in range(coarse, coarse+len(frames)): sys.stdout.write("\b" * 50) sys.stdout.write("saving frame: %d/%d" % (fnum, args.output_frames-1)) numm.np2image(frames[fnum-coarse], "%s/%d.png" % (work_dir, fnum)) print() print("Now running ffmpeg to create video file") os.system("ffmpeg -framerate 30 -i %s/%%d.png -r 30 -pix_fmt yuv420p -y %s" % (work_dir, output_fname)) print("Cleaning up...") shutil.rmtree(work_dir)
import compose def draw(comp, cover, W=1200, H=600): arr = np.zeros((H,W,3), np.uint8) covarr = cv2.resize(cover, (W,H)) segs = reduce(lambda x,y: x+y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) count = 0 duration = max([X.start+X.duration for X in segs]) total = W*H temparr = [] temparr2 = [] for i in range(len(covarr)): temparr.extend(covarr[i][:][:]) for seg in segs: a = int(total*(seg.start/duration)) b = int(total*((seg.start+seg.duration)/duration)) temparr2.extend(temparr[a:b]) for j in range(H): for i in range(W): if count < len(temparr2)-1: arr[j][i] = temparr2[count] count+=1 else: break return arr if __name__=='__main__': import sys comp = compose.Composition.fromfile(sys.argv[1]) cover = numm.image2np(sys.argv[2]) numm.np2image(draw(comp, cover), sys.argv[3])
def serialize(self, fpath): numm.np2image(self.peek(), fpath + "." + self.extension)
def process(self, frame): t = frame.timestamp / float(gst.SECOND) if t % self.nsecs < self.p % self.nsecs: numm.np2image(frame, self.outpattern % (t)) self.p = t
for nodestate in player._state_nodes: cv2.circle(initial, s(nodestate.node.pt), int(5*scale), (255, 255, 255), -1) # numm.np2image(initial, '%s-initial.png' % (side)) save(initial, '%s-initial.png' % (side)) # and accumulate a set of the first N edges out from the initial condition N = 150 edges = set() while len(edges) < N: player.next() for edgestate in player._state_edges: edges.add(edgestate.edge) inprog = base.copy() inprog[:] = 0 for edge in edges: cv2.line(inprog, s(edge.a.pt), s(edge.b.pt), (255, 255, 255), int(round(scale*thick*1.5))) # numm.np2image(inprog, '%s-edges.png' % (side)) save(inprog, '%s-edges.png' % (side)) # And finally render a merged image as a preview comp = base.copy() comp[:,:,1] = initial[:,:,1] comp[:,:,2] = inprog[:,:,2] numm.np2image(comp, '%s-comp.png' % (side))
def draw(comp, base, fine, W=3000, H=2000): arr = np.zeros((H,W,3), np.uint8) segs = reduce(lambda x,y: x+y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) out_t = 0 duration = max([X.start+X.duration for X in segs]) for seg in segs: cv2.line(arr, (int(W*(out_t/duration)), 0), (int(W*(seg.start/duration)), H), (255,255,255)) out_t += seg.duration base = cv2.resize(numm.image2np(base), (W,H)) fine = cv2.resize(numm.image2np(fine), (W,H)) divisors = np.linspace(0, 1, H).reshape((-1,1,1)) comp = ((base*(1-divisors)) + (fine*divisors)).astype(np.uint8) numm.np2image(comp, 'COMP.PNG') comp[arr==0] = 0 return comp if __name__=='__main__': import sys comp = compose.Composition.fromfile(sys.argv[1]) numm.np2image(draw(comp, sys.argv[2], sys.argv[3]), sys.argv[4])
covarr = cv2.resize(cover, (W, H)) segs = reduce( lambda x, y: x + y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) count = 0 duration = max([X.start + X.duration for X in segs]) total = W * H temparr = [] temparr2 = [] for i in range(len(covarr)): temparr.extend(covarr[i][:][:]) for seg in segs: a = int(total * (seg.start / duration)) b = int(total * ((seg.start + seg.duration) / duration)) temparr2.extend(temparr[a:b]) for j in range(H): for i in range(W): if count < len(temparr2) - 1: arr[j][i] = temparr2[count] count += 1 else: break return arr if __name__ == '__main__': import sys comp = compose.Composition.fromfile(sys.argv[1]) cover = numm.image2np(sys.argv[2]) numm.np2image(draw(comp, cover), sys.argv[3])
def process(self, frame): # t = frame.timestamp / float(gst.SECOND) t = self.p + 0.04 if t % self.nsecs < self.p % self.nsecs: numm.np2image(frame, self.outpattern % (t)) self.p=t
arr = np.zeros((H, W, 3), np.uint8) segs = reduce( lambda x, y: x + y, [X.getArrangement().getSequencePreview().segs for X in comp.rhythms]) out_t = 0 duration = max([X.start + X.duration for X in segs]) for seg in segs: cv2.line(arr, (int(W * (out_t / duration)), 0), (int(W * (seg.start / duration)), H), (255, 255, 255)) out_t += seg.duration base = cv2.resize(numm.image2np(base), (W, H)) fine = cv2.resize(numm.image2np(fine), (W, H)) divisors = np.linspace(0, 1, H).reshape((-1, 1, 1)) comp = ((base * (1 - divisors)) + (fine * divisors)).astype(np.uint8) numm.np2image(comp, 'COMP.PNG') comp[arr == 0] = 0 return comp if __name__ == '__main__': import sys comp = compose.Composition.fromfile(sys.argv[1]) numm.np2image(draw(comp, sys.argv[2], sys.argv[3]), sys.argv[4])