hello all, seems i'm missing something querying song duration through gstreamer. i've seen this post http://www.ruby-forum.com/topic/206849 , and the proof-of-concept app, as well as duration meters in other players (zik) which use the same method. this code however: ## pipeline = Gst::ElementFactory.make("playbin2") pipeline.uri= "file://home/jk/ruby/test.mp3" d = Gst::QueryDuration.new(Gst::Format::Type::TIME) pipeline.query(d) gstdur = d.parse[1]/1000000 p "gstdur= #{gstdur}" ## returns: ## "gstdur= -1" ## at the moment i'm using the gem 'mp3info' for duration, and querying the same file with mp3info, like this: ## audio = "/home/jk/ruby/test.mp3" Mp3Info.open(audio){|data| @infodur = data.length} p "infodur= #{@infodur}" ## returns: ## "infodur= 227.5791875" ## any ideas what i'm doing wrong in the gstreamer query? -jk
on 2011-03-07 16:45
on 2011-03-07 17:16
2011/3/7 J. K. <ruby-forum-incoming@andreas-s.net>: > pipeline.query(d) > the same file with mp3info, like this: > > any ideas what i'm doing wrong in the gstreamer query? I think you have fogotten to call play method on pipeline. > solutions. http://p.sf.net/sfu/progress-d2d > _______________________________________________ > ruby-gnome2-devel-en mailing list > ruby-gnome2-devel-en@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ruby-... > -- Vincent Carmona
on 2011-03-07 17:31
> I think you have fogotten to call play method on pipeline.
i had tried that, with the same result....
pipeline = Gst::ElementFactory.make("playbin2")
pipeline.uri= "file:/home/jk/ruby/test.mp3"
pipeline.play
d = Gst::QueryDuration.new(Gst::Format::Type::TIME)
pipeline.query(d)
gstdur = d.parse[1]/1000000
p "gstdur= #{gstdur}"
returns
"gstdur= -1"
strange
on 2011-03-07 17:50
this also returns the same value of -1
##
pipeline = Gst::ElementFactory.make("playbin2")
pipeline.uri= "file:/home/jk/ruby/test.mp3"
bus = pipeline.bus
bus.add_watch {|bus, message|
case message.type
when Gst::Message::DURATION
dur = message
p dur.parse[1]/1000000
end
true}
pipeline.play
##
-j
on 2011-03-07 18:08
2011/3/7 J. K. <ruby-forum-incoming@andreas-s.net>: > audio = "/home/jk/ruby/test.mp3" > pipeline = Gst::ElementFactory.make("playbin2") > pipeline.uri= "file://home/jk/ruby/test.mp3" I think you are missing "/" here. file:///home/jk/ruby/test.mp3 protocole(file)://path(/home/jk/ruby/test.mp3) > Posted via http://www.ruby-forum.com/. > -- Vincent Carmona
on 2011-03-07 18:14
Vincent Carmona wrote in post #985992: > 2011/3/7 J. K. <ruby-forum-incoming@andreas-s.net>: >> audio = "/home/jk/ruby/test.mp3" >> pipeline = Gst::ElementFactory.make("playbin2") >> pipeline.uri= "file://home/jk/ruby/test.mp3" > > I think you are missing "/" here. file:///home/jk/ruby/test.mp3 > protocole(file)://path(/home/jk/ruby/test.mp3) > i thought the same, but oddly i get an error with the extra '/', and the file doesn't play - pipeline.uri= "file://home/jk/ruby/test.mp3" [#<GLib::Error: Resource not found.>, "gstgiosrc.c(313): gst_gio_src_get_stream (): /GstPlayBin2:playbin20/GstURIDecodeBin:uridecodebin0/GstGioSrc:source:\nCould not open location file:///jk/ruby/test.mp3 for reading: Error opening file: No such file or directory"] when i remove the first '/', the file is found and plays... pipeline.uri= "file:/home/jk/ruby/test.mp3" #> "gstdur= -1" #> -1
on 2011-03-07 18:20
2011/3/7 J. K. <ruby-forum-incoming@andreas-s.net>: > i thought the same, but oddly i get an error with the extra '/', and > the file doesn't play - > > pipeline.uri= "file://home/jk/ruby/test.mp3" > > [#<GLib::Error: Resource not found.>, "gstgiosrc.c(313): > gst_gio_src_get_stream (): > /GstPlayBin2:playbin20/GstURIDecodeBin:uridecodebin0/GstGioSrc:source:\nCould > not open location file:///jk/ruby/test.mp3 for reading: Error opening > file: No such file or directory"] I guess you now miss "home" file:///home/jk/ruby/test.mp3 and not file:///jk/ruby/test.mp3 > Posted via http://www.ruby-forum.com/. > -- Vincent Carmona
on 2011-03-07 18:27
this:
audio = "/home/jk/ruby/test.mp3"
pipeline = Gst::ElementFactory.make("playbin2")
pipeline.uri= GLib.filename_to_uri(audio)
plays just fine, but my duration problem is not solved... i still
return
"gstdur= -1"
-1
any ideas?
on 2011-03-07 20:06
2011/3/7 J. K. <ruby-forum-incoming@andreas-s.net>: > "gstdur= -1" > -1 > > any ideas? > Maybe you need some gstreamer plugins. Did you try other files, other formats? > ruby-gnome2-devel-en@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ruby-... > -- Vincent Carmona
on 2011-03-07 22:00
Vincent Carmona wrote in post #986024: >> > Maybe you need some gstreamer plugins. Did you try other files, other > formats? > tried a different .mp3, .flac, .ogg, and .wav - all play fine, but give me the same "-1" duration. the plugins i have are the following: *gstreamer0.10-* ffmpeg pitfdll tools fluendo-plugins-mp3-partner v.7.0.20100316 esd nice gnonlin pulseaudio alsa plugins-base packagekit plugins-good x plugins-bad plugins-base-apps plugins-bad-multiverse plugins-ugly plugins-ugly-multiverse plugins-good-dbg plugins-base-dbg plugins-bad-multiverse-dbg plugins-ugly-multivers-dbg libgstreamer-plugins-base0.10(and -dev) gir1.0-gst-plugins-base-0.10 libgstreamer0.10-0(and -dev)
on 2011-03-19 03:54
hey all, SOLVED interesting, it turns out that there is a lag in the duration query (at least with 1.8.7, gtk2 0.19.3 and gstreamer 0.10.x.) when i put the query in the timeout loop for showing position, it would first show -1 a couple of times, and then show the duration parsed to seconds after a bit. i ended up solving my problem writing a simple getDuration method, which includes an 1/8 of a second sleep, to let the pipeline get rolling before the query takes place. def getDuration sleep 0.125 qd = Gst::QueryDuration.new(Gst::Format::Type::TIME) @pipeline.query(qd) @dur = qd.parse[1]/1000000000 end not the prettiest thing in the world, but works like a charm. -jk
on 2011-03-19 13:43
2011/3/19 J. K. <ruby-forum-incoming@andreas-s.net>: > before the query takes place. > > _______________________________________________ > ruby-gnome2-devel-en mailing list > ruby-gnome2-devel-en@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ruby-... > Instead of sleep I would have use GLib::Timeout.add method. It should allows other events to be processed during the 0.125 s. def getDuration GLib::Timeout.add(125){ qd = Gst::QueryDuration.new(Gst::Format::Type::TIME) @pipeline.query(qd) @dur = qd.parse[1]/1000000000 if @dur<0 true#TODO : add a limit for the number of queries else false end } -- Vincent Carmona
on 2011-03-19 17:09
hi vincent - nice solution - didn't like the sleep much myself, i'll give this a shot. thanks, -j
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.