ruby-gstreamer 不发送 EOS 消息

发布于 2024-08-31 22:46:24 字数 1057 浏览 6 评论 0原文

我已经设法让它播放声音,但它从未收到 EOS 消息。 因此脚本永远不会退出。

require 'gst'

main_loop = GLib::MainLoop.new

pipeline = Gst::Pipeline.new "audio-player"
source   = Gst::ElementFactory.make "filesrc",      "file-source"
source.location = "/usr/share/sounds/gnome/default/alerts/bark.ogg"
decoder  = Gst::ElementFactory.make "decodebin",    "decoder"
conv     = Gst::ElementFactory.make "audioconvert", "converter"
sink     = Gst::ElementFactory.make "alsasink",     "output"

pipeline.add source, decoder, conv, sink
source >> decoder
conv >> sink

decoder.signal_connect "pad-added" do |element, pad, data|
  pad >> conv['sink']
end

pipeline.bus.add_watch do |bus, message|
  puts "Message: #{message.inspect}"
  case message.type
  when Gst::Message::Type::ERROR
    puts message.structure["debug"]
    main_loop.quit
  when Gst::Message::Type::EOS
    puts 'End of stream'
    main_loop.quit
  end
end

pipeline.play

begin
  puts 'Running main loop'
  main_loop.run
ensure
  puts 'Shutting down main loop'
  pipeline.stop
end

I've managed to make it play sound but it never gets EOS message.
And thus script never exits.

require 'gst'

main_loop = GLib::MainLoop.new

pipeline = Gst::Pipeline.new "audio-player"
source   = Gst::ElementFactory.make "filesrc",      "file-source"
source.location = "/usr/share/sounds/gnome/default/alerts/bark.ogg"
decoder  = Gst::ElementFactory.make "decodebin",    "decoder"
conv     = Gst::ElementFactory.make "audioconvert", "converter"
sink     = Gst::ElementFactory.make "alsasink",     "output"

pipeline.add source, decoder, conv, sink
source >> decoder
conv >> sink

decoder.signal_connect "pad-added" do |element, pad, data|
  pad >> conv['sink']
end

pipeline.bus.add_watch do |bus, message|
  puts "Message: #{message.inspect}"
  case message.type
  when Gst::Message::Type::ERROR
    puts message.structure["debug"]
    main_loop.quit
  when Gst::Message::Type::EOS
    puts 'End of stream'
    main_loop.quit
  end
end

pipeline.play

begin
  puts 'Running main loop'
  main_loop.run
ensure
  puts 'Shutting down main loop'
  pipeline.stop
end

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

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

发布评论

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

评论(2

琉璃繁缕 2024-09-07 22:46:24

我找到了解决方案。与所有可能遇到同样问题的人分享。

真正的问题是该块没有返回true。它必须返回 true 才能保持监视。这在 GStreamer 文档的深处有记录,但在 ruby​​-gnome2 文档中没有提及。

I've found a solution. Sharing with everybody who may run into same problem.

The real problem was that block didn't return true. It has to return true to be kept in watch. This is documented somewhere deep in GStreamer docs but is not mentioned in ruby-gnome2 docs.

爱情眠于流年 2024-09-07 22:46:24
Gst::Message::Type::EOS

应该是:

Gst::Message::EOS

错误也一样

Gst::Message::Type::EOS

should be:

Gst::Message::EOS

same goes for ERROR

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