3
# vi:si:et:sw=4:sts=4:ts=4
5
# GStreamer python bindings
6
# Copyright (C) 2002 David I. Lehn <dlehn@users.sourceforge.net>
7
# 2004 Johan Dahlin <johan@gnome.org>
9
# filesrc.py: implements a file source element completely in python
11
# This library is free software; you can redistribute it and/or
12
# modify it under the terms of the GNU Library General Public
13
# License as published by the Free Software Foundation; either
14
# version 2 of the License, or (at your option) any later version.
16
# This library is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
# Library General Public License for more details.
21
# You should have received a copy of the GNU Library General Public
22
# License along with this library; if not, write to the
23
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24
# Boston, MA 02111-1307, USA.
30
class FileSource(gst.Element):
33
def __init__(self, name):
34
self.__gobject_init__()
36
self.srcpad = gst.Pad('src', gst.PAD_SRC)
37
self.srcpad.set_get_function(self.srcpad_get)
38
self.add_pad(self.srcpad)
40
def set_property(self, name, value):
41
if name == 'location':
42
self.fd = open(value, 'r')
44
def srcpad_get(self, pad):
45
data = self.fd.read(self.blocksize)
47
return gst.Buffer(data)
50
return gst.Event(gst.EVENT_EOS)
51
gobject.type_register(FileSource)
54
print 'This example is not finished yet.'
58
print 'Usage: %s input output' % (args[0])
61
bin = gst.Pipeline('pipeline')
63
filesrc = FileSource('filesource')
64
#filesrc = gst.Element('filesrc', 'src')
66
filesrc.set_property('location', args[1])
68
filesink = gst.element_factory_make('filesink', 'sink')
69
filesink.set_property('location', args[2])
71
bin.add_many(filesrc, filesink)
72
gst.element_link_many(filesrc, filesink)
74
bin.set_state(gst.STATE_PLAYING);
79
bin.set_state(gst.STATE_NULL)
81
if __name__ == '__main__':
82
sys.exit(main(sys.argv))