问题描述
我正在写使用Python的Gstreamer绑定播放音频的应用,但现在我想也只是去code声音 - 那就是,我想用来读取数据的<一个href=\"http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-components-de$c$cbin.html\"><$c$c>de$c$cbin$c$c>并获得原始PCM缓冲区。具体而言,我想读取文件的块增量而不是读整个文件到内存中。
I'm writing an application that uses the Python Gstreamer bindings to play audio, but I'm now trying to also just decode audio -- that is, I'd like to read data using a decodebin
and receive a raw PCM buffer. Specifically, I want to read chunks of the file incrementally rather than reading the whole file into memory.
一些具体的问题:我怎样才能做到这一点在GStreamer?随着pygst特别?是否有一个特定的汇元素我需要使用从流中读取数据?是否有一个preferred办法读取从?我该如何去控制在哪个我消耗数据(而不仅仅是进入一个主循环)率是多少?
Some specific questions: How can I accomplish this with Gstreamer? With pygst specifically? Is there a particular "sink" element I need to use to read data from the stream? Is there a preferred way to read data from a pygst Buffer
object? How do I go about controlling the rate at which I consume data (rather than just entering a "main loop")?
推荐答案
要取回数据的应用程序时,推荐的方法是appsink.
To get the data back in your application, the recommended way is appsink.
根据一个简单的音频播放器如(并更换oggdemux / vorbisdec由德codeBIN&放大器; capsfilter与帽=音频/ X-RAW-INT),变更为autoaudiosink appsink,并连接\"new-buffer\"信号到蟒蛇功能+设置发出-信号为True。该函数将接收PCM / int数据的德codeD块。解码的速率将取决于在它可以解除code和消耗的速率。由于新的缓冲信号是GStreamer的线程上下文,你可能只是睡觉/等待该功能来控制或减缓解码速度。
Based on a simple audio player like this one (and replace the oggdemux/vorbisdec by decodebin & capsfilter with caps = "audio/x-raw-int"), change autoaudiosink to appsink, and connect "new-buffer" signal to a python function + set "emit-signals" to True. The function will receive decoded chunks of PCM/int data. The rate of the decoding will depend on the rate at which you can decode and consume. Since the new-buffer signal is in the Gstreamer thread context, you could just sleep/wait in that function to control or slow down the decoding speed.
这篇关于使用(蟒蛇)的Gstreamer脱code音频(为PCM数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!