免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2221 | 回复: 0
打印 上一主题 下一主题

ruby mp3一块儿给你转了 ogg [复制链接]

论坛徽章:
27
水瓶座
日期:2014-08-22 21:06:34程序设计版块每日发帖之星
日期:2015-11-25 06:20:0015-16赛季CBA联赛之新疆
日期:2015-12-19 19:05:48IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:3315-16赛季CBA联赛之上海
日期:2016-04-15 19:51:31程序设计版块每日发帖之星
日期:2016-04-17 06:23:29程序设计版块每日发帖之星
日期:2016-04-23 06:20:00程序设计版块每日发帖之星
日期:2016-05-26 06:20:00每日论坛发贴之星
日期:2016-05-26 06:20:0015-16赛季CBA联赛之辽宁
日期:2017-02-16 23:59:47
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-04-22 10:09 |只看该作者 |倒序浏览
本帖最后由 shijiang1130 于 2013-04-22 10:10 编辑
  1. require 'rubygems'
  2. require 'gst'

  3. def convert(s,d)

  4. pipeline = Gst::Pipeline.new "audio-player"
  5. source  = Gst::ElementFactory.make "filesrc",      "file-source"
  6. decoder = Gst::ElementFactory.make "mad",          "mp3-decoder"
  7. conv    = Gst::ElementFactory.make "audioconvert", "converter"
  8. encoder = Gst::ElementFactory.make "vorbisenc",    "vorbis-encoder"
  9. muxer   = Gst::ElementFactory.make "oggmux",       "ogg-muxer"
  10. sink    = Gst::ElementFactory.make "filesink",     "file-output"

  11. source.location = s
  12. sink.location = d

  13. main_loop = GLib::MainLoop.new

  14. pipeline.bus.add_watch do |bus, message|
  15.   case message.type
  16.   when Gst::Message::EOS
  17.     puts 'End of stream'
  18.     main_loop.quit
  19.   when Gst::Message::ERROR
  20.     puts message.parse.join ': '
  21.     main_loop.quit
  22.   when Gst::Message::INFO
  23.     puts "Info: #{message.parse}"
  24.   end
  25.   true
  26. end

  27. pipeline.add source, decoder, conv, encoder, muxer, sink
  28. source >> decoder >> conv >> encoder >> muxer >> sink

  29. pipeline.play
  30. puts 'Running...'

  31. begin
  32.   main_loop.run
  33. rescue Interrupt
  34. ensure
  35.   puts 'Returned, sopping playing'
  36.   pipeline.stop
  37. end
  38. end

  39. Dir.glob('/home/lookdata.cn/*.mp3').each { |mp3|
  40. ogg = File.basename(mp3,'.mp3')

  41. convert(mp3,"/home/lookdata.cn/Music/#{ogg}.ogg")

  42. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP