gstlal  0.8.1
 All Classes Namespaces Files Functions Variables Pages
gstlal_launch
1 #!/usr/bin/env python
2 
3 ## @file
4 # A replacement for gst-launch that allows seeks
5 
6 """
7 gst-launch with goodies
8 
9 It allows to seek in the pipeline.
10 """
11 
12 # JBC. April 2011.
13 
14 import sys
15 from optparse import OptionParser
16 
17 parser = OptionParser(version='%prog 1.0', usage='%prog [options]',
18  description=__doc__)
19 
20 parser.add_option('--start', type='int', help='start time')
21 parser.add_option('--end', type='int', help='end time')
22 
23 opts, rest = parser.parse_args()
24 
25 
26 #
27 # Initialization
28 #
29 
30 import pygtk
31 pygtk.require('2.0')
32 import pygst
33 pygst.require('0.10')
34 import gobject, gst
35 from gstlal import simplehandler
36 
37 
38 #
39 # Create the pipeline (yes, it's *that* easy)
40 #
41 
42 mainloop = gobject.MainLoop()
43 pipeline = gst.parse_launch(' '.join(rest))
44 
45 
46 #
47 # Make it start playing at the appropriate time
48 #
49 
50 if opts.start is not None:
51  start_seektype = gst.SEEK_TYPE_SET
52  start_ns = opts.start * 1e9
53 else:
54  start_seektype = gst.SEEK_TYPE_NONE
55  start_ns = 0 # not used anyway
56 
57 if opts.end is not None:
58  end_seektype = gst.SEEK_TYPE_SET
59  end_ns = opts.end * 1e9
60 else:
61  end_seektype = gst.SEEK_TYPE_NONE
62  end_ns = 0 # not used anyway
63 
64 for src in pipeline.iterate_sources():
65  src.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH,
66  start_seektype, start_ns,
67  end_seektype, end_ns)
68 
69 
70 #
71 # Boilerplate
72 #
73 
74 handler = simplehandler.Handler(mainloop, pipeline)
75 if pipeline.set_state(gst.STATE_PLAYING) == gst.STATE_CHANGE_FAILURE:
76  raise RuntimeError("pipeline failed to enter PLAYING state")
77 mainloop.run()