Back to development
[platform/upstream/gstreamer.git] / subprojects / gst-python / old_examples / tagsetter.py
1 #!/usr/bin/env python
2 # -*- Mode: Python -*-
3 # vi:si:et:sw=4:sts=4:ts=4
4
5 # gst-python
6 # Copyright (C) 2009 Stefan Kost   <ensonic@user.sf.net>
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Library General Public
10 # License as published by the Free Software Foundation; either
11 # version 2 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Library General Public License for more details.
17 #
18 # You should have received a copy of the GNU Library General Public
19 # License along with this library; if not, write to the
20 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 # Boston, MA 02110-1301, USA.
22 #
23
24 import sys
25
26 import gobject
27 gobject.threads_init()
28
29 import pygst
30 pygst.require('0.10')
31 import gst
32
33
34 mainloop = gobject.MainLoop()
35
36 def on_eos(bus, msg):
37    mainloop.quit()
38
39 def main(args):
40    "Tagsetter test, test result with:"
41    "gst-launch -t playbin uri=file://$PWD/test.avi"
42
43    # create a new bin to hold the elements
44    bin = gst.parse_launch('audiotestsrc num-buffers=100 ! ' +
45                           'lame ! ' +
46                           'avimux name=mux ! ' +
47                           'filesink location=test.avi')
48
49    mux = bin.get_by_name('mux')
50
51    bus = bin.get_bus()
52    bus.add_signal_watch()
53    bus.connect('message::eos', on_eos)
54
55    # prepare
56    bin.set_state(gst.STATE_READY)
57    
58    # send tags
59    l = gst.TagList()
60    l[gst.TAG_ARTIST] = "Unknown Genius"
61    l[gst.TAG_TITLE] = "Unnamed Artwork"
62    mux.merge_tags(l, gst.TAG_MERGE_APPEND)
63
64    # start playing
65    bin.set_state(gst.STATE_PLAYING)
66
67    try:
68       mainloop.run()
69    except KeyboardInterrupt:
70       pass
71
72    # stop the bin
73    bin.set_state(gst.STATE_NULL)
74
75 if __name__ == '__main__':
76    sys.exit(main(sys.argv))
77