Created
October 15, 2014 13:14
-
-
Save thomasfillon/8271be5d936a94f565bd to your computer and use it in GitHub Desktop.
Generate audio samples with Gstreamer 'audiotestsrc' element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Generate samples with Gstreamer 'audiotestsrc' element""" | |
import pygst | |
pygst.require("0.10") | |
import gobject | |
import gst | |
# Initialize gobject in a threading environment | |
gobject.threads_init() | |
# GStreamer main loop | |
mainloop = gobject.MainLoop() | |
pipeline = gst.Pipeline("pipeline") | |
audiotestsrc = gst.element_factory_make("audiotestsrc", "audio") | |
audiotestsrc.set_property('num-buffers', 150) | |
pipeline.add(audiotestsrc) | |
encoder = gst.element_factory_make('lame', 'encoder') | |
filesink = gst.element_factory_make('filesink', 'sink') | |
filesink.set_property('location', '/tmp/test.mp3') | |
pipeline.add(encoder, filesink) | |
gst.element_link_many(audiotestsrc, encoder, filesink) | |
pipeline.set_state(gst.STATE_PLAYING) | |
def on_eos_cb(bus, msg): | |
"""Calback on End-Of-Stream message""" | |
mainloop.quit() | |
pipeline.set_state(gst.STATE_NULL) | |
bus = pipeline.get_bus() | |
bus.add_signal_watch() | |
bus.connect('message::eos', on_eos_cb) | |
mainloop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment