How to record audio in gstreamer for pre-defined t

2019-08-04 09:29发布

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条回答
乱世女痞
2楼-- · 2019-08-04 09:45

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()).

查看更多
登录 后发表回答