Skip to content

Instantly share code, notes, and snippets.

@thomasfillon
Created October 15, 2014 13:14
Show Gist options
  • Save thomasfillon/8271be5d936a94f565bd to your computer and use it in GitHub Desktop.
Save thomasfillon/8271be5d936a94f565bd to your computer and use it in GitHub Desktop.
Generate audio samples with Gstreamer 'audiotestsrc' element
# -*- 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