coding utf-8 import sys import gobject import pygst pygst require 10 i

 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
# -*- coding: utf-8 -*-
import sys
import gobject
import pygst
pygst.require('0.10')
import gst
class FileSource(gst.BaseSrc):
__gsttemplates__ = (
gst.PadTemplate("src",
gst.PAD_SRC,
gst.PAD_ALWAYS,
gst.caps_new_any()),
)
blocksize = 4096
fd = None
def __init__(self, name):
self.__gobject_init__()
self.curoffset = 0
self.set_name(name)
def set_property(self, name, value):
if name == 'location':
self.fd = open(value, 'r')
def do_create(self, offset, size):
if offset != self.curoffset:
self.fd.seek(offset, 0)
data = self.fd.read(self.blocksize)
if data:
self.curoffset += len(data)
return gst.FLOW_OK, gst.Buffer(data)
else:
return gst.FLOW_UNEXPECTED, None
gobject.type_register(FileSource)
def main(args):
if len(args) != 3:
print 'Usage: %s input output' % (args[0])
return -1
bin = gst.Pipeline('pipeline')
filesrc = FileSource('filesource')
assert filesrc
filesrc.set_property('location', args[1])
filesink = gst.element_factory_make('filesink', 'sink')
filesink.set_property('location', args[2])
bin.add(filesrc, filesink)
gst.element_link_many(filesrc, filesink)
bin.set_state(gst.STATE_PLAYING);
mainloop = gobject.MainLoop()
def bus_event(bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
mainloop.quit()
elif t == gst.MESSAGE_ERROR:
err, debug = message.parse_error()
print "Error: %s" % err, debug
mainloop.quit()
return True
bin.get_bus().add_watch(bus_event)
mainloop.run()
bin.set_state(gst.STATE_NULL)
if __name__ == '__main__':
sys.exit(main(sys.argv))