[pygtk] truncated file when recording with pygst
Pablo Rodríguez
oinos at web.de
Sun Oct 26 20:20:34 WST 2008
Hi there,
(since it seems that Python GStreamer or even GStreamer don't seem to
have mailing lists to ask for questions such as the following one, I
hope the Python GStreamer maintainers are subscribed to this list or any
kind person would help me with this.)
I'm a Python newbie (and I don't know other programming language). Using
the script provided bellow to record sound to a WAV file. Everything
works fine excepting that when recording is stopped, the resulting file
is truncated.
If I'm not wrong, here might be the cause: the GStreamer documentation
describes the "Controlled shutdown of live sources in applications"
(http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer-libs/html/GstBaseSrc.html)
and proposes the following solution:
"Since GStreamer 0.10.16 an application may send an EOS event to a
source element to make it perform the EOS logic (send EOS event
downstream or post a GST_MESSAGE_SEGMENT_DONE on the bus). This can
typically be done with the gst_element_send_event() function on the
element or its parent bin."
What I understand from the previous explanation is that I should replace
the last line of code "self.player.set_state(gst.STATE_NULL)" with an
EOS event. How could I do this?
Thanks,
Pablo
def __init__(self):
self.player = gst.Pipeline("player")
self.clock = self.player.get_clock()
self.source = gst.element_factory_make("alsasrc", "alsa-source")
self.encoder = gst.element_factory_make("wavenc", "wavenc")
self.fileout = gst.element_factory_make("filesink", "sink")
self.fileout.set_property("location", self.filename + "-audio.wav")
self.player.add(self.source, self.encoder, self.fileout)
gst.element_link_many(self.source, self.encoder, self.fileout)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect('message', self.on_message)
self.playing = False
self.recording_time = self.player.get_last_stream_time()
def on_message(self, bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
self.player.set_state(gst.STATE_NULL)
elif t == gst.MESSAGE_ERROR:
err, debug = message.parse_error()
print "Error: %s" % err, debug
self.player.set_state(gst.STATE_NULL)
def on_key_press_event(self, widget, event):
if (event.keyval == gtk.keysyms.space):
if self.playing == False:
self.playing = True
self.player.set_state(gst.STATE_PLAYING)
elif self.playing == True:
self.player.set_state(gst.STATE_NULL)
More information about the pygtk
mailing list