- 论坛徽章:
- 30
|
本帖最后由 shijiang1130 于 2013-04-22 10:10 编辑
- require 'rubygems'
- require 'gst'
- def convert(s,d)
- pipeline = Gst::Pipeline.new "audio-player"
- source = Gst::ElementFactory.make "filesrc", "file-source"
- decoder = Gst::ElementFactory.make "mad", "mp3-decoder"
- conv = Gst::ElementFactory.make "audioconvert", "converter"
- encoder = Gst::ElementFactory.make "vorbisenc", "vorbis-encoder"
- muxer = Gst::ElementFactory.make "oggmux", "ogg-muxer"
- sink = Gst::ElementFactory.make "filesink", "file-output"
- source.location = s
- sink.location = d
- main_loop = GLib::MainLoop.new
- pipeline.bus.add_watch do |bus, message|
- case message.type
- when Gst::Message::EOS
- puts 'End of stream'
- main_loop.quit
- when Gst::Message::ERROR
- puts message.parse.join ': '
- main_loop.quit
- when Gst::Message::INFO
- puts "Info: #{message.parse}"
- end
- true
- end
- pipeline.add source, decoder, conv, encoder, muxer, sink
- source >> decoder >> conv >> encoder >> muxer >> sink
- pipeline.play
- puts 'Running...'
- begin
- main_loop.run
- rescue Interrupt
- ensure
- puts 'Returned, sopping playing'
- pipeline.stop
- end
- end
- Dir.glob('/home/lookdata.cn/*.mp3').each { |mp3|
- ogg = File.basename(mp3,'.mp3')
- convert(mp3,"/home/lookdata.cn/Music/#{ogg}.ogg")
- }
复制代码 |
|