Skip to content

Instantly share code, notes, and snippets.

@eagsalazar
Created July 17, 2010 22:00
Show Gist options
  • Save eagsalazar/479882 to your computer and use it in GitHub Desktop.
Save eagsalazar/479882 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os, sys, optparse
import clutter
import gtk
import gst
import cluttergst
import gobject
gobject.threads_init()
class AwesomeVideoActor:
def OnDynamicPad(self, dbin, pad, islast):
pad.link(self.colorspace.get_pad("sink"))
def __init__(self, video_file, stage, scale, loopTime):
# Controls depth
self.foward = True
self.stage = stage
self.scale = scale
self.loopTime = loopTime
def bus_handler(unused_bus, message):
if message.type == gst.MESSAGE_ERROR:
pass
return gst.BUS_PASS
# Creates a gstreamer texture
self.video_texture = clutter.Texture()
self.pipeline = gst.Pipeline()
self.bus = self.pipeline.get_bus()
self.bus.add_signal_watch()
self.bus.connect("message", bus_handler)
if video_file == 'none':
self.src = gst.element_factory_make("v4l2src", "src")
else:
self.src = gst.element_factory_make("filesrc", "filesrc")
self.src.set_property("location", video_file)
self.decode = gst.element_factory_make("decodebin", "decode")
self.colorspace = gst.element_factory_make("ffmpegcolorspace", "colorspace")
# Attaches the output texture to gstreamer sink
self.sink = cluttergst.VideoSink(self.video_texture)
self.pipeline.add(self.src, self.decode, self.colorspace, self.sink)
self.decode.connect("new-decoded-pad", self.OnDynamicPad)
gst.element_link_many(self.src, self.decode)
gst.element_link_many(self.colorspace, self.sink)
self.pipeline.set_state(gst.STATE_PLAYING)
self.timeline = clutter.Timeline(self.loopTime)
self.timeline.set_loop(True)
self.timeline.connect("completed", self.timeline_completed)
alpha = clutter.Alpha(self.timeline, clutter.EASE_IN_OUT_SINE)
self.behaviour_scale = clutter.BehaviourScale(alpha=alpha, x_scale_start=(self.scale*1.0), x_scale_end=(self.scale*1.5), y_scale_start=(self.scale*1.0), y_scale_end=(self.scale*1.6))
# self.behaviour_opacity = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=0xdd)
self.behaviour_scale.apply(self.video_texture)
# self.behaviour_opacity.apply(self.video_texture)
self.stage.add(self.video_texture)
self.timeline_completed(self)
# Change the direction
def timeline_completed(self,data=[]):
if self.foward:
x_scale_start = (self.scale*0.7)
x_scale_end = (self.scale*1)
y_scale_start = (self.scale*0.7)
y_scale_end = (self.scale*1)
self.foward = False
opacity_start = 0
opacity_end = 0xdd
else:
x_scale_start = (self.scale*1)
x_scale_end = (self.scale*0.7)
y_scale_start = (self.scale*1)
y_scale_end = (self.scale*0.7)
self.foward = True
opacity_start = 0xdd
opacity_end = 0
self.behaviour_scale.set_property("x_scale_start", x_scale_start)
self.behaviour_scale.set_property("x_scale_end", x_scale_end)
self.behaviour_scale.set_property("y_scale_start", y_scale_start)
self.behaviour_scale.set_property("y_scale_end", y_scale_end)
# self.behaviour_opacity.set_property('opacity_start', opacity_start)
# self.behaviour_opacity.set_property('opacity_end', opacity_end)
self.timeline.rewind()
self.timeline.start()
if __name__ == "__main__":
usage = """ pudovkin -i [file] """
parser = optparse.OptionParser(usage=usage)
parser.add_option("-a", "--input1", action="store", type="string", \
dest="video_file1", help="Input video file #1", default="")
parser.add_option("-b", "--input2", action="store", type="string", \
dest="video_file2", help="Input video file #2", default="")
(options, args) = parser.parse_args()
video_file1 = options.video_file1
if not os.path.exists(options.video_file1):
print "%s was not found" % options.video_file1
os._exit(2)
video_file2 = options.video_file2
if not os.path.exists(options.video_file2):
print "%s was not found" % options.video_file2
os._exit(2)
stage = clutter.Stage()
stage.set_color(clutter.color_from_string("#000000"))
stage.set_title("Awesome")
stage.connect('destroy', clutter.main_quit)
stage.connect('key-press-event', clutter.main_quit)
stage.set_size(800, 600)
awesome = AwesomeVideoActor(video_file1, stage, 1.5, 5400)
awesome2 = AwesomeVideoActor(video_file2, stage, 0.4, 1500)
stage.show_all()
clutter.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment