Ruby/GStreamer and querying file duration

Hi,

can anyone provide working example for querying duration of an audio
file
using Ruby/GStreamer?

Code in gstreamer/src/samples/ is completely outdated and IMHO should be
removed from the repository.

I attach my current code below, but I always got an error like
“Gst::QueryType::Type isn’t supported”, doesn’t matter what kind of
query I
pass to pad.query. Even if I pass attributes taken from pad.query_types!
It
seems that’s a bug?


m.

CODE:

#!/usr/bin/ruby
require ‘gst’

Gst.init

class DurationMeter
def initialize
@pipeline = Gst::Pipeline.new(“durationmeter”)

@source = Gst::ElementFactory.make("filesrc")
@source.location = ARGV[0]

@convertor = Gst::ElementFactory.make("audioconvert")

@sink = Gst::ElementFactory.make("fakesink")

@decoder = Gst::ElementFactory.make("decodebin")
@decoder.signal_connect("new-decoded-pad") do | dbin, pad, is_last |
  pad.link @convertor.get_pad("sink")
  @convertor >> @sink

  @sinkpad = @sink.get_pad("sink")
  @sinkpad.signal_connect("notify::caps") do |pad, args|
    if pad.negotiated_caps
      puts pad.query Gst::QueryType::DURATION


    end
  end
end



@pipeline.add @source, @decoder, @convertor, @sink
@source >> @decoder

@pipeline.bus.add_watch do | bus, message |
  case message.type
    when Gst::Message::Type::ERROR
      puts "Error"
      puts message.structure["debug"]

      @pipeline.stop

      exit 1

    when Gst::Message::Type::EOS
      puts "EOS"
      @pipeline.stop
      exit 0

    when Gst::Message::Type::ELEMENT
      puts "Message from #{message.source.name}"
  end
  true
end

end

def play
@pipeline.play
end

def stop
@pipeline.stop
end
end

meter = DurationMeter.new
meter.play

mainloop = GLib::MainLoop.new GLib::MainContext.default, true
mainloop.run

OK, I found that.

Proof-of-concept app is submitted to the hiki:
http://ruby-gnome2.sourceforge.jp/hiki.cgi?gst-duration-seek-position

m.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs