go - GStreamer 应用程序接收器比文件接收器慢得多
问题描述
我正在尝试使用 golang 中的 GStreamer 将 MP3 文件转换为 wave。这是createPipeline()
功能:
func createPipeline() (*gst.Pipeline, error) {
gst.Init(nil)
// Create a pipeline
pipeline, err := gst.NewPipelineFromString(
"appsrc name=src ! decodebin ! audioresample ! audioconvert ! audio/x-raw,format=S16LE,rate=16000 ! wavenc ! appsink name=sink")
if err != nil {
return nil, err
}
srcElem, err := pipeline.GetElementByName("src")
if err != nil {
return nil, err
}
src := app.SrcFromElement(srcElem)
src.SetCallbacks(&app.SourceCallbacks{
NeedDataFunc: func(self *app.Source, _ uint) {
// If we've reached the end of the palette, end the stream.
bytes, _ := os.ReadFile("/tmp/a.mp3")
buffer := gst.NewBufferFromBytes(bytes)
self.PushBuffer(buffer)
src.EndStream()
},
})
sinkElem, err := pipeline.GetElementByName("sink")
if err != nil {
return nil, err
}
sink := app.SinkFromElement(sinkElem)
sink.SetCallbacks(&app.SinkCallbacks{
// Add a "new-sample" callback
NewSampleFunc: func(sink *app.Sink) gst.FlowReturn {
// Pull the sample that triggered this callback
sample := sink.PullSample()
if sample == nil {
return gst.FlowEOS
}
os.WriteFile("a.wav", sample.GetBuffer().Bytes(), 0644)
return gst.FlowOK
},
})
return pipeline, nil
}
我有两个选择。第一个是使用filesink
元素将结果保存到文件,第二个是使用appsink
元素并获取样本并写入文件。我认为这两种方法的性能应该几乎相同。但是当我使用appsink
它时,它比filesink
. 我正在使用GStreamer 的这个绑定。
解决方案
您可以尝试延迟跟踪器来检查管道元素之间的延迟。如果两条管道都一样,可能是磁盘io的原因,可以通过在写入磁盘前缓冲来解决。
推荐阅读
- javascript - 无法从本地读取 zip 文件
- excel - 从文件路径重命名文件时,如何将 CSV 文件转换为 XLSM?
- javascript - 在 Express 中动态更改路线
- dart - 是否有一种惯用的方法将 JSON 解析为具有共享基类但数据形状不同的对象?
- expression - 如何使用报表生成器中的表达式将儒略日期格式化为批号回到 YYMMDD 格式的日历日期
- python - DataFrame Pivot Table 在特定列上运行特定功能
- google-ads-api - 有没有办法通过 Google Ads API 获取每个响应式搜索广告组合的展示次数?
- reactjs - Docker 平台上的 elasticbeanstalk:react 应用程序的 502 Bad Gateway
- c# - 缺少 Windows 窗体和工具箱中的用户控件?
- dataweave - 存储参考数据 Mulesoft