Commits

Eric Floehr committed c1359ac

Making movies easy

Comments (0)

Files changed (3)

+# Running image loading in parallel
+for d in `find /data/pics -type d -name "131?" | sort`; do django- insertpics $d; done
+
+
+import subprocess
+import tempfile
+
+mencoder_exe = "/usr/bin/mencoder"
+mencoder_options = [
+    "-nosound",
+    "-ovc", "lavc",
+    "-lavcopts", "vcodec=mpeg4:trell:mbd=2",
+    ]
+
+class ImageSequence(object):
+    def __init__(self):
+        self.images = []
+
+    def add_image(self, filepath):
+        self.images.append(filepath)
+    
+    def add_picture(self, picture):
+        self.images.append(picture.filepath)
+
+    def add_pictureset(self, pictureset):
+        for picture in pictureset:
+            self.add_picture(picture)
+
+    def write_to_file(self, fileobj):
+        for image in self.images:
+            fileobj.write(image)
+            fileobj.write('\n')
+
+    def make_timelapse(self, name, fps=25):
+        tmpfile = tempfile.NamedTemporaryFile()
+        self.write_to_file(tmpfile)
+
+        execall = []
+        execall.append(mencoder_exe)
+        execall.extend(mencoder_options)
+        execall.append("mf://@{0}".format(tmpfile.name))
+        execall.extend(["-mf", "type=jpeg:fps={0}".format(fps)])
+        execall.extend(["-o", "{name}.mp4".format(name=name)])
+
+        return subprocess.call(execall)
+
+from movies import ImageSequence
+from pics.models import Picture
+
+ims = ImageSequence()
+
+pics = Picture.objects.filter(timestamp__contains='06:00',valid=True).order_by('timestamp')
+
+ims.add_pictureset(pics)
+ims.make_timelapse('/tmp/sevenpm')
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.