How to record audio in gstreamer for pre-defined time?

谁都会走 提交于 2019-12-11 08:25:40

问题


I have python gstreamer - 1.0 code that records audio using "autoaudiosrc" element. My question is to stop the pipeline after few 'predefined' seconds and preferably I want to add it in gstelement format .

The current pipeline used to record :

gst-launch-1.0 autoaudiosrc num-buffers=100 ! audioconvert ! vorbisenc ! oggmux ! filesink location="sit.ogg"

corresponding python code

import sys, os


import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, Gtk
GObject.threads_init()
Gst.init(None)

pipeline = Gst.Pipeline()
current_state = "STATE_NULL"

autoaudiosrc = Gst.ElementFactory.make("autoaudiosrc", "autoaudiosrc")
audioconvert = Gst.ElementFactory.make("audioconvert", "audioconvert")
vorbisenc = Gst.ElementFactory.make("vorbisenc", "vorbisenc")
oggmux = Gst.ElementFactory.make("oggmux", "oggmux")
filesink = Gst.ElementFactory.make("filesink", "filesink")
url = "1.ogg"
filesink.set_property("location",url)
pipeline.add( autoaudiosrc)
pipeline.add( audioconvert)
pipeline.add( vorbisenc)
pipeline.add( oggmux)
pipeline.add( filesink)

autoaudiosrc.link( audioconvert)
audioconvert.link( vorbisenc)
vorbisenc.link( oggmux)
oggmux.link( filesink)

pipeline.set_state(Gst.State.PLAYING)
Gtk.main()

~


回答1:


Yes. You can start a timer (g_timeout_add or using the gstreamer clock via gst_clock_new_single_shot_id). When the timer/clock callback fires, send an eos event to the pipeline (gst_element_send_event(pipeline, gst_event_new_eos()).



来源:https://stackoverflow.com/questions/21253064/how-to-record-audio-in-gstreamer-for-pre-defined-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!