1个回答
展开全部
下载个MediaCoder-0.7.2.4506.exe 安装后就可以执行ffmpeg.exe命令了
public class ConvertVideo {
public static void convertVideo(String systemFileName) {
System.out.println(systemFileName);
String videoImg=systemFileName.substring(0,systemFileName.lastIndexOf("."))+".gif";
System.out.println(videoImg);
if(processImg(systemFileName,videoImg)){
System.out.println("ok");
};
String videoBigImg=systemFileName.substring(0,systemFileName.lastIndexOf("."))+".jpg";
if(processBigImg(systemFileName,videoBigImg)){
System.out.println("BigImg ok");
};
}
public static void main(String[] args) {
// String videoImg=args[0].substring(0,args[0].lastIndexOf("."))+"";
if(processImg("","")){
System.out.println("ok");
};
}
// 生成图片 参数String newfilename, String newimg
public static boolean processImg(String systemFileName ,String videoImg ) {
// System.out.println(newfilename + "->" + newimg);
List<String> commend = new java.util.ArrayList<String>();
commend.add("C:\\Program Files\\MediaCoder\\codecs\\ffmpeg.exe");
commend.add("-i");
// commend.add("g:\\test\\b.flv");
// commend.add("E:\\jboss-4.2.2.GA\\server\\default\\.\\deploy\\sell.war\\upload\\video\\1255593814968_zhangxiz.flv");
commend.add(systemFileName);
commend.add("-y");
commend.add("-f");
commend.add("image2");
commend.add("-ss");
commend.add("18");
commend.add("-t");
commend.add("0.001");
commend.add("-s");
commend.add("132x90");
// commend.add("g:\\test\\44.jpg");
commend.add(videoImg);
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
Process process = builder.start();
final InputStream is1 = process.getInputStream();
new Thread(new Runnable() {
public void run() {
BufferedReader br = new BufferedReader(new InputStreamReader(is1));
try {
while(br.readLine() != null) ;
} catch (IOException e) {
e.printStackTrace();
}
}
}).start(); // 启动单独的线程来清空process.getInputStream()的缓冲区
InputStream is2 = process.getErrorStream();
BufferedReader br2 = new BufferedReader(new InputStreamReader(is2));
StringBuilder buf = new StringBuilder(); // 保存输出结果流
String line = null;
while((line = br2.readLine()) != null) buf.append(line);
// builder.start();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
上面是我的代码 你看看自己调试下吧
public class ConvertVideo {
public static void convertVideo(String systemFileName) {
System.out.println(systemFileName);
String videoImg=systemFileName.substring(0,systemFileName.lastIndexOf("."))+".gif";
System.out.println(videoImg);
if(processImg(systemFileName,videoImg)){
System.out.println("ok");
};
String videoBigImg=systemFileName.substring(0,systemFileName.lastIndexOf("."))+".jpg";
if(processBigImg(systemFileName,videoBigImg)){
System.out.println("BigImg ok");
};
}
public static void main(String[] args) {
// String videoImg=args[0].substring(0,args[0].lastIndexOf("."))+"";
if(processImg("","")){
System.out.println("ok");
};
}
// 生成图片 参数String newfilename, String newimg
public static boolean processImg(String systemFileName ,String videoImg ) {
// System.out.println(newfilename + "->" + newimg);
List<String> commend = new java.util.ArrayList<String>();
commend.add("C:\\Program Files\\MediaCoder\\codecs\\ffmpeg.exe");
commend.add("-i");
// commend.add("g:\\test\\b.flv");
// commend.add("E:\\jboss-4.2.2.GA\\server\\default\\.\\deploy\\sell.war\\upload\\video\\1255593814968_zhangxiz.flv");
commend.add(systemFileName);
commend.add("-y");
commend.add("-f");
commend.add("image2");
commend.add("-ss");
commend.add("18");
commend.add("-t");
commend.add("0.001");
commend.add("-s");
commend.add("132x90");
// commend.add("g:\\test\\44.jpg");
commend.add(videoImg);
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
Process process = builder.start();
final InputStream is1 = process.getInputStream();
new Thread(new Runnable() {
public void run() {
BufferedReader br = new BufferedReader(new InputStreamReader(is1));
try {
while(br.readLine() != null) ;
} catch (IOException e) {
e.printStackTrace();
}
}
}).start(); // 启动单独的线程来清空process.getInputStream()的缓冲区
InputStream is2 = process.getErrorStream();
BufferedReader br2 = new BufferedReader(new InputStreamReader(is2));
StringBuilder buf = new StringBuilder(); // 保存输出结果流
String line = null;
while((line = br2.readLine()) != null) buf.append(line);
// builder.start();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
上面是我的代码 你看看自己调试下吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询