使用 (Python) Gstreamer 解码音频(为 PCM 数据)

发布于 2024-09-14 18:49:36 字数 513 浏览 7 评论 0原文

我正在编写一个使用 Python Gstreamer 绑定来播放音频的应用程序,但我现在也尝试解码音频 - 也就是说,我想使用 decodebin 并接收原始 PCM 缓冲区。具体来说,我想增量读取文件的块,而不是将整个文件读入内存。

一些具体问题:我如何使用 Gstreamer 来完成此任务?特别是 pygst 吗?我需要使用特定的“接收器”元素来从流中读取数据吗?是否有从 pygst Buffer 读取数据的首选方法对象?如何控制消耗数据的速率(而不是仅仅进入“主循环”)?

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.

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")?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千里故人稀 2024-09-21 18:49:36

要将数据返回到应用程序中,推荐的方法是 appsink

基于一个简单的音频播放器,例如这个(并替换oggdemux/vorbisdec 通过decodebin & capsfilter with caps = "audio/x-raw-int"),将autoaudiosink更改为appsink,并连接"new-buffer" 向 python 函数发送信号+ 将“发出信号”设置为 True。该函数将接收解码后的 PCM/int 数据块。解码的速率取决于您可以解码和消费的速率。由于 new-buffer 信号位于 Gstreamer 线程上下文中,因此您可以在该函数中休眠/等待来控制或减慢解码速度。

To get the data back in your application, the recommended way is appsink.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文