问题描述
我有python gstreamer-使用"autoaudiosrc"元素记录音频的1.0代码.我的问题是在预定义"几秒钟后停止管道,最好以gstelement格式添加管道.
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 .
用于记录的当前管道:
gst-launch-1.0 autoaudiosrc num-buffers=100 ! audioconvert ! vorbisenc ! oggmux ! filesink location="sit.ogg"
对应的python代码
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()
〜
推荐答案
是.您可以启动计时器(g_timeout_add或通过gst_clock_new_single_shot_id使用gstreamer时钟).当计时器/时钟回调触发时,向管道发送一个eos事件(gst_element_send_event(pipeline,gst_event_new_eos()).
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()).
这篇关于如何在预定义的时间内在gstreamer中录制音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!