实现转换视频的最简单groovy程序
转换视频,使用的是ffmpeg,因为是在ubuntu(目前是9.04版本)下做开发,需要事先安装ffmpeg,可参考ubuntu server安装ffmpeg支持3gp。
另外,groovy需要支持grape,具体配置,见在groovy中使用grape管理类库依赖。
代码很简单,VideoConvertor.groovy:
#!/usr/bin/env groovy
import groovy.lang.Grab;
import org.apache.log4j.*@Grab(group="log4j",module="log4j",version="1.2.12")
class Convertor{
private static Logger logger=Logger.getLogger(Convertor.class)
static{
PropertyConfigurator.configure("log4j.properties");
}
def convert(input,output){
def time=new Date().time
def file=new File(output)
if(file.exists()){
file.delete()
logger.debug("delete file ${output}.")
}
def process="ffmpeg -i ${input} ${output}".execute()
process.waitFor()
logger.debug("生成${output}成功,耗时${new Date().time-time}毫秒。")
}
}def input=’test.mov’
def output=’output.mp4′
new Convertor().convert(input,output)
源代码见:
这篇文章上的评论的 RSS feed TrackBack URI