summaryrefslogtreecommitdiff
path: root/bindings/python/examples/effect.py
blob: fc3f82d8a70fc21615b163cf7253b87502c76875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
#
#       effect.py
#
# Copyright (C) 2011 Mathieu Duponchelle <seeed@laposte.net>
# Copyright (C) 2011 Luis de Bethencourt <luis.debethencourt@collabora.co.uk>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.

import sys
import optparse

import glib
import gobject
gobject.threads_init()

import gst
import ges

class Effect:
    def __init__(self, effects):
        ges.init()
        self.mainloop = glib.MainLoop()

        self.timeline = ges.timeline_new_audio_video()
        layer = ges.TimelineLayer()
        self.src = ges.TimelineTestSource()
        self.src.set_start(long(0))

        self.src.set_duration(long(3000000000))
        self.src.set_vpattern("smpte75")
        layer.add_object(self.src)
        self.timeline.add_layer(layer)

        self.add_effects(effects)

        self.pipeline = ges.TimelinePipeline()
        self.pipeline.add_timeline(self.timeline)
        bus = self.pipeline.get_bus()
        bus.set_sync_handler(self.bus_handler)

    def add_effects(self, effects):
        for e in effects:
            effect = ges.TrackParseLaunchEffect(e)
            self.src.add_track_object(effect)
            for track in self.timeline.get_tracks():
                if track.get_caps().to_string() == \
                        "video/x-raw-yuv; video/x-raw-rgb":
                    print "setting effect: " + e
                    track.add_object(effect)

    def bus_handler(self, unused_bus, message):
        if message.type == gst.MESSAGE_ERROR:
            print "ERROR"
            self.mainloop.quit()
        elif message.type == gst.MESSAGE_EOS:
            print "Done"
            self.mainloop.quit()

        return gst.BUS_PASS

    def run(self):
        if (self.pipeline.set_state(gst.STATE_PLAYING) == \
                gst.STATE_CHANGE_FAILURE):
            print "Couldn't start pipeline"

        self.mainloop.run()

def main(args):
    usage = "usage: %s effect_name-1 .. effect_name-n\n" % args[0]

    if len(args) < 2:
        print usage + "using aging tv as a default instead"
        args.append("agingtv")

    parser = optparse.OptionParser (usage=usage)
    (opts, args) = parser.parse_args ()

    effect = Effect(args)
    effect.run()

if __name__ == "__main__":
    main(sys.argv)