Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用(Python)Gstreamer解码音频(到PCM数据)_Python_Audio_Decode_Gstreamer_Pcm - Fatal编程技术网

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

使用(Python)Gstreamer解码音频(到PCM数据),python,audio,decode,gstreamer,pcm,Python,Audio,Decode,Gstreamer,Pcm,我正在编写一个应用程序,它使用Python Gstreamer绑定来播放音频,但我现在也尝试对音频进行解码——也就是说,我希望使用一个原始PCM缓冲区读取数据并接收原始PCM缓冲区。具体地说,我希望以增量方式读取文件块,而不是将整个文件读入内存 一些具体问题:如何使用Gstreamer实现这一点?特别是pygst?是否需要使用特定的“sink”元素从流中读取数据?是否有从数据库读取数据的首选方法?如何控制使用数据的速率(而不仅仅是进入“主循环”)?要将数据返回到应用程序中,建议使用以下方法 基于

我正在编写一个应用程序,它使用Python Gstreamer绑定来播放音频,但我现在也尝试对音频进行解码——也就是说,我希望使用一个原始PCM缓冲区读取数据并接收原始PCM缓冲区。具体地说,我希望以增量方式读取文件块,而不是将整个文件读入内存


一些具体问题:如何使用Gstreamer实现这一点?特别是pygst?是否需要使用特定的“sink”元素从流中读取数据?是否有从数据库读取数据的首选方法?如何控制使用数据的速率(而不仅仅是进入“主循环”)?

要将数据返回到应用程序中,建议使用以下方法


基于一个简单的音频播放器,如(用decodebin&capsfilter替换oggdemux/vorbisdec为caps=“audio/x-raw-int”),将autoaudiosink更改为appsink,并将signal连接到python函数+将“emit signals”设置为True。该函数将接收已解码的PCM/int数据块。解码速率取决于您解码和消费的速率。由于新的缓冲区信号在Gstreamer线程上下文中,您可以在该函数中休眠/等待以控制或降低解码速度。

谢谢!我不知道appsink的事。这很有帮助!尝试此操作后,还有一个额外的注意事项(供将来参考):似乎需要将appsink的“sync”属性设置为false,以便尽快获取数据。否则,您将实时使用数据;相反,您需要调用appsink.emit('pull-buffer')。更多未来参考:这是我(在elmarco的帮助下)提出的解决方案,它可能在其他项目中也很有用。