JSP中如何实现在线将上传的AVI等格式视频转换为FLASH格式?
解决方案 »
- jqgrid展现数据疑问
- 网站引用google地图
- 关于JSP页面包含的问题
- 求助啊!!!!!!!好心人帮帮忙!!!
- 404错误
- 高分求助tomcat启动时的信息中有错误报告,谁能帮我解释一下。(在线等,问题解决马上结贴)
- 关于struts的<html select>提问
- strtus2 问题
- Sring MVC中 junit测试报错
- ajax请求session为什么会变!!!
- 求救mencoder问题,急!!!
- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).错误
import java.io.File;
import java.util.List;
public class ConvertVideo {
private final static String PATH = "e:\\output\\test.avi";
public static void main(String[] args) {
if(!checkfile(PATH)){
System.out.println(PATH+" is not file");
return;
}
if (process()) {
System.out.println("ok");
}
}
private static boolean process() {
int type = checkContentType();
boolean status = false;
if (type==0) {
status = processFLV(PATH);// 直接将文件转为flv文件
} else if (type==1) {
String avifilepath = processAVI(type);
if (avifilepath == null)
return false;// avi文件没有得到
status = processFLV(avifilepath);// 将avi转为flv
}
return status;
}
private static int checkContentType() {
String type = PATH.substring(PATH.lastIndexOf(".") + 1,
PATH.length()).toLowerCase();
//ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
if (type.equals("avi")) {
return 0;
} else if (type.equals("mpg")) {
return 0;
} else if (type.equals("wmv")) {
return 0;
} else if (type.equals("3gp")) {
return 0;
} else if (type.equals("mov")) {
return 0;
} else if (type.equals("mp4")) {
return 0;
} else if (type.equals("asf")) {
return 0;
} else if (type.equals("asx")) {
return 0;
} else if (type.equals("flv")) {
return 0;
}
//对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等), 可以先用别的工具(mencoder)转换为avi(ffmpeg能解析的)格式.
else if (type.equals("wmv9")) {
return 1;
} else if (type.equals("rm")) {
return 1;
} else if (type.equals("rmvb")) {
return 1;
}
return 9;
}
private static boolean checkfile(String path){
File file=new File(path);
if(!file.isFile()){
return false;
}
return true;
}
// 对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等), 可以先用别的工具(mencoder)转换为avi(ffmpeg能解析的)格式.
private static String processAVI(int type) {
List<String> commend=new java.util.ArrayList<String>();
commend.add("e:\\mencoder");
commend.add(PATH);
commend.add("-oac");
commend.add("lavc");
commend.add("-ovc");
commend.add("xvid");
commend.add("-xvidencopts");
commend.add("bitrate=600");
commend.add("-of");
commend.add("avi");
commend.add("-o");
commend.add("e:\\output\\temp.avi");
try{
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.start();
return "e:\\output\\temp.avi";
}catch(Exception e){
e.printStackTrace();
return null;
}
}
// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
private static boolean processFLV(String oldfilepath) {
if(!checkfile(PATH)){
System.out.println(oldfilepath+" is not file");
return false;
}
List<String> command=new java.util.ArrayList<String>();
command.add("e:\\ffmpeg");
command.add("-i");
command.add(oldfilepath);
command.add("-ab");
command.add("56");
command.add("-ar");
command.add("22050");
command.add("-b");
command.add("500");
command.add("-r");
command.add("15");
command.add("-y");
command.add("e:\\output\\test.flv");
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(command);
builder.start();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}