#!/usr/bin/python import os, sys, subprocess filename_formats = [ "%06d.png", "frame%08d.jpg", ] def section(*args, **kwargs): return (args, kwargs) class First2m: input_framerate = 20 output_framerate = 20 sections = [ section("diffusion", "0:00", "0:07"), section("annular", "0:30", "0:35"), section("grid", "1:00", "1:05"), section("scalefree", "0:00", "0:05"), section("shapespace", "0:05", "0:10"), section("occoids.phw", "0:04", "0:15"), # initial formation section("occoids.phw", "1:20", "1:30"), # hawks section("occoids.phw", "1:55", "2:05"), # food section("occoids.narrow", "1:40", "1:50"), section("cylons.32-both", "0:00", "0:20"), section("cylons.256-0", "0:10", "0:15"), section("cylons.256-1", "0:10", "0:15"), section("tuna.standalone", "0:45", "0:50"), section("tuna.cluster", "0:00", "0:05"), section("parrot-attack", "0:05", "0:17"), ] class First3m: input_framerate = 20 output_framerate = 20 sections = [ section("diffusion", "0:00", "0:06"), section("annular", "0:30", "0:35"), section("grid", "1:00", "1:04"), section("scalefree", "0:00", "0:05"), section("shapespace", "0:05", "0:07"), section("occoids.phw", "0:04", "0:15"), # initial formation section("occoids.phw", "1:20", "1:30"), # hawks section("occoids.phw", "1:55", "2:05"), # food section("occoids.narrow", "1:40", "2:00"), section("cylons.32-both", "0:00", "0:20"), section("cylons.256-0", "0:10", "0:20"), section("cylons.256-1", "0:10", "0:20"), section("tuna.standalone", "0:45", "1:04"), # rotate, cut wound section("tuna.standalone", "1:24", "1:27"), # close-up section("tuna.standalone", "2:08", "2:13"), # big wound section("tuna.standalone", "3:58", "4:03"), # big wound clotted section("tuna.cluster", "0:00", "0:05"), # whole big tube section("tuna.cluster", "0:35", "0:38"), # close-up on wound section("breakout", "1:00", "1:05"), # bouncing across the top section("parrot-attack", "0:05", "0:27"), ] class Showreel2010: input_framerate = 25 output_framerate = 25 sections = [ section("occoids", "0:00", "0:20", caption="Bird flocking"), section("occoids.narrow", "0:00", "0:50", skip=6, caption="Bird flocking"), section("lymphocytes", "0:42", "0:52", caption="Lymphocyte rolling"), # normal section("lymphocytes", "1:19", "1:37", caption="Lymphocyte rolling"), # chase cam section("robots", "0:00", "0:20", skip=2, caption="CO538: Cylons"), section("lom", "0:11", "0:23", caption="CO538: Life on Mars"), section("stickfigures", "0:00", "0:10", caption="CO538: Dining Philosophers"), section("zombies", "0:20", "0:40", skip=2, caption="CO538: Dining Philosophers"), section("shootrocks", "0:25", "0:32", caption="CO538: Dining Philosophers"), section("physicists", "1:55", "2:15", skip=2, caption="CO538: Dining Philosophers"), # black hole ] xsections = [ section("shootrocks", "0:25", "0:32", caption="CO538: Dining Philosophers"), ] video = Showreel2010() sections = video.sections def parse_time(s): (min, sec) = [int(p) for p in s.split(":")] return ((min * 60) + sec) * video.input_framerate def output_time(frame): sec = (frame * 1.0) / video.output_framerate hun = int(100 * (sec - int(sec))) sec = int(sec) min = sec / 60 sec = sec % 60 hour = min / 60 min = min % 60 return "%02d:%02d:%02d.%02d" % (hour, min, sec, hun) os.system("rm -rf output-frames") os.system("mkdir output-frames") subfn = "output.sub" subf = open(subfn, "w") subf.write("""[INFORMATION] [END INFORMATION] [SUBTITLE] """) frame = 0 extension = None for section in sections: (dir, start, end) = section[0] kwargs = section[1] frameskip = kwargs.get("skip", 1) print "From %s at %d" % (dir, frame) format = None for f in filename_formats: if os.access(("%s/" + f) % (dir, 0), os.F_OK): format = f break if format is None: print "Can't find filename format for dir %s" % dir sys.exit(1) this_ext = os.path.splitext(format)[1][1:] if extension is None: extension = this_ext elif extension != this_ext: print "Extension mismatch: %s, %s" % (extension, this_ext) sys.exit(1) firstframe = frame for i in range(parse_time(start), parse_time(end), frameskip): os.symlink(("../%s/" + format) % (dir, i), "output-frames/frame%08d.%s" % (frame, extension)) frame += 1 if "caption" in kwargs: subf.write("%s,%s\n%s\n\n" % (output_time(firstframe), output_time(frame - 1), kwargs["caption"])) total_secs = frame / video.output_framerate print "Total length = %d:%02d" % (total_secs / 60, total_secs % 60) subf.close() for vpass in (1, 2): if vpass == 1: ofn = "/dev/null" else: ofn = "output.avi" cmd = [ "mencoder", "mf://output-frames/*.%s" % extension, "-mf", "fps=%d:type=%s" % (video.output_framerate, extension), # "-vf", "unsharp=l3x3:-0.4", "-fontconfig", "-font", "Liberation Sans:pixelsize=20:weight=bold", "-sub", subfn, "-subpos", "5", "-ovc", "lavc", "-lavcopts", "vcodec=mpeg4:vbitrate=3000:mbd=2:trell=yes:v4mv=yes:vpass=%d" % vpass, "-oac", "copy", "-o", ofn, ] subprocess.call(cmd) #os.unlink(subfn)