`

MEIZU music card 魅族MP3 Linux视频转换工具

阅读更多

最近想尝试下在MP3上面看看视频的效果,就看了看功能。

MZ果然很XX,对支持格式的限制好大,而且视频播放还不允许快进什么的。无赖之下,只好自己写一个Linux的脚本转换工具。

这个工具主要是:

  1. 将视频转换成可以支持的视频格式
  2. 将视频切断

以下是代码,用Ruby实现的,需要mencoder 和ffmpeg支持。

#! /usr/bin/ruby
# The ruby script file
# Copyright(c) 2003-2009 Wang Pengcheng(wpc0000@gmail.com)
# http://qianjigui.iteye.com

# file is the filename
#  b_time is the begin time
#  length is the part-length
#  pie is the piece of the part
MEM_ENCODE_OPTION={
:first => "-oac mp3lame -lameopts preset=64 -ovc xvid -xvidencopts bitrate=600 -of avi",
:seconde => "-oac mp3lame -lameopts preset=standard -ovc xvid -lavcopts vcodec=mpeg4:vbitrate=1200:mbd=2:trell:v4mv -ffourcc XVID  -mc 0 -noskip",
:third => "-oac mp3lame -lameopts aq=7:vbr=2:q=6 -srate 32000 -vf scale=176:128,harddup -ovc xvid -xvidencopts fixed_quant=8"
}
MEM_OPTION = ""
file, b_time_s, length_s, pie= ARGV
b_time = b_time_s.to_i
length = length_s.to_i
if not File.exists? file then
  p "#{file} not be found"
else
  dir= "#{file}-dir"
  if  File.extname(file)=~/rm(vb)?/ then
  %x[mencoder #{file} #{MEM_ENCODE_OPTION[:first]} #{MEM_OPTION} -o #{file}.avi]
    file=file+".avi"
  end
  type= ".avi" #
  if not File.exists? dir then
    Dir.mkdir(dir)
  end
  for i in 1..pie.to_i do
    # How terrible, the MEIZU mp3 accept only a special video format
    # Below is the format information, XVID-MPEG4 176x128 with 20f/s
    %x[ffmpeg -i #{file} -s 176x128 -vcodec mpeg4 -vtag xvid -r 20 -y -ss #{b_time+length*(i-1)} -t #{length} #{dir}/#{i.to_s.rjust(pie.length,'0')}#{type}]
  end
end

 以上是基本的功能实现,后面如果有时间会继续添加配置,让这个脚本更健壮。

欢迎各位指正。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics