def ProcessEditDecision(tmpFilePath, edit, width, height): """\ Prefab. Applies an edit decision - reading in the relevant video frames and applying the reframing. Outputs the reframed video frames out of the "outbox" outbox. Arguments: - tmpFilePath -- temp directory into which video frames have been saved - edit -- the edit instruction (dictionary containing: "start","end","left","top","right","bottom") - width -- width (in pixels) for output video frames - height -- height (in pixels) for output video frames Inboxes: - "inbox" -- NOT USED - "control" -- Shutdown signalling Outboxes: - "outbox" -- NOT USED - "signal" -- Shutdown signalling """ print " Video segment: ", edit filenames = [ tmpFilePath + "%08d.yuv" % i for i in range(edit["start"], edit["end"] + 1) ] newsize = (width, height) cropbounds = (edit["left"], edit["top"], edit["right"], edit["bottom"]) return Graphline( \ FILENAMES = ForwardIteratingChooser(filenames), FRAME_LOADER = Carousel( lambda filename : Pipeline( 2, MaxSpeedFileReader(filename,chunksize=1024*1024), 2, YUV4MPEGToFrame(), ), make1stRequest=False ), REFRAMING = Pipeline( 2, ToRGB_interleaved(), 2, CropAndScale(newsize, cropbounds), 2, ToYUV420_planar(), ), linkages = { ("FRAME_LOADER", "requestNext") : ("FILENAMES", "inbox"), ("FILENAMES", "outbox") : ("FRAME_LOADER", "next"), ("FRAME_LOADER", "outbox") : ("REFRAMING", "inbox"), ("REFRAMING", "outbox") : ("", "outbox"), ("FILENAMES", "signal") : ("FRAME_LOADER", "control"), ("FRAME_LOADER", "signal") : ("REFRAMING", "control"), ("REFRAMING", "signal") : ("", "signal"), }, boxsizes = { }, )
def capture_one(self): self.snapshot = None self.snapshot = self.camera.get_image() def main(self): self.camera.start() while 1: self.capture_one() self.send(self.snapshot, "outbox") time.sleep(self.delay) if __name__ == "__main__": from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.File.Writing import SimpleFileWriter from Kamaelia.Codec.Dirac import DiracEncoder from Kamaelia.Video.PixFormatConversion import ToYUV420_planar from Kamaelia.Util.PureTransformer import PureTransformer Pipeline( VideoCaptureSource(), PureTransformer(lambda F : \ {"rgb" : pygame.image.tostring(F, "RGB"), "size" : (352, 288), "pixformat" : "RGB_interleaved", }), ToYUV420_planar(), DiracEncoder(preset="CIF", encParams={"num_L1":0}), SimpleFileWriter("X.drc"), ).run()