求java 视频转换为flv格式的demo rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.lgh.struts.util;import java.io.BufferedReader;import java.io.File;import java.io.InputStream;import java.io.InputStreamReader;public class ConvertVideo { public static boolean process(String PATH,String filename) { int type = checkContentType(PATH); boolean status = false; if (type==0) { status = processFLV(PATH,filename);// 直接将文件转为flv文件 } else if (type==1) { String avifilepath = processAVI(type,PATH,filename); if (avifilepath == null) return false;// avi文件没有得到 status = processFLV(avifilepath,filename);// 将avi转为flv } return status; } private static int checkContentType(String PATH) { 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,String PATH,String filename) { long lasting = System.currentTimeMillis(); String pathto = Community.webpath.replace("/", "\\")+"vedioavi\\"+filename+".avi"; String pathfrom = PATH.replace("/", "\\"); String patht = Community.webpath.replace("/", "\\")+"jmq\\WisMencoder\\mencoder.exe "; String commend=null; commend= patht+" -noodml "+pathfrom+" -subcp cp936 -font simhei.ttf -subfont-text-scale 4 -o "+pathto+" -ofps 20.000 -vf-add scale=640:-2 -ovc xvid -xvidencopts bitrate=500 -srate 44100 -oac mp3lame -lameopts vbr=0 -lameopts br=128 -lameopts vol=0 -lameopts mode=0 -lameopts aq=7 -lameopts padding=3 -af volnorm -xvidencopts max_bframes=0:nogmc:noqpel "; try{ Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(commend); new process(proc.getInputStream(),"INFO").start(); new process(proc.getErrorStream(),"ERROR").start(); int status = proc.waitFor(); if (status == 0) System.out.println("执行完毕"); else System.out.println("执行失败"); System.out.println("转换avi运行时间:" + (System.currentTimeMillis() - lasting) + "毫秒"); return pathto; }catch(Exception e){ e.printStackTrace(); return null; } }// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等) private static boolean processFLV(String oldfilepath,String filename) { long lasting = System.currentTimeMillis(); String path = Community.webpath.replace("/", "\\")+"vedioflv\\"; String commend=""; commend+=Community.webpath.replace("/", "\\")+"jmq\\Libs\\ffmpeg.exe "; commend+="-i "; commend+=oldfilepath; commend+=" -ar "; commend+="22050 "; commend+="-ab "; commend+="56 "; commend+="-f "; commend+="flv -qscale 6 "; commend+="-y "; commend+="-b "; commend+="320x240 "; commend+=" "+path+filename+".flv"; try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(commend); new process(proc.getInputStream(),"INFO").start(); new process(proc.getErrorStream(),"ERROR").start(); int status = proc.waitFor(); if (status == 0) System.out.println("执行完毕"); else System.out.println("执行失败"); System.out.println("转换flv运行时间:" + (System.currentTimeMillis() - lasting) + "毫秒"); /* ProcessBuilder builder = new ProcessBuilder(); builder.command(commend); builder.start();*/ return true; } catch (Exception e) { e.printStackTrace(); return false; } } } 你的去下载个转换器。String patht = Community.webpath.replace("/", "\\")+"jmq\\WisMencoder\\mencoder.exe "; http://www.onlinedown.net/soft/96317.htm下载一个flv视频转换器就可以了。 怎样禁止IE缓存 swf文件 web 高手请进 判断是不是GB2312! ASP.NET如何从sql数据库中获得的值赋值到Select标签的Option中??? javabean 变量命名问题 我想问一下,可能这个问题你也很关注,进来看看吧 bean无法编译错在哪? 急!急!急!请教高手!!我的JSP页面提交时,数据库操作时间很长,我想能提示用户正在操作,数据库操作完后,提示用户,操作完毕,如何 jboss 高手快来! jsp有点小错误,请大神帮忙,感激不敬 请教请教。。。! 做了个取色软件,大家都来看下吧!
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;public class ConvertVideo {
public static boolean process(String PATH,String filename) {
int type = checkContentType(PATH);
boolean status = false;
if (type==0) {
status = processFLV(PATH,filename);// 直接将文件转为flv文件
} else if (type==1) {
String avifilepath = processAVI(type,PATH,filename);
if (avifilepath == null)
return false;// avi文件没有得到
status = processFLV(avifilepath,filename);// 将avi转为flv
}
return status;
}
private static int checkContentType(String PATH) {
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,String PATH,String filename) {
long lasting = System.currentTimeMillis();
String pathto = Community.webpath.replace("/", "\\")+"vedioavi\\"+filename+".avi";
String pathfrom = PATH.replace("/", "\\");
String patht = Community.webpath.replace("/", "\\")+"jmq\\WisMencoder\\mencoder.exe ";
String commend=null;
commend= patht+" -noodml "+pathfrom+" -subcp cp936 -font simhei.ttf -subfont-text-scale 4 -o "+pathto+" -ofps 20.000 -vf-add scale=640:-2 -ovc xvid -xvidencopts bitrate=500 -srate 44100 -oac mp3lame -lameopts vbr=0 -lameopts br=128 -lameopts vol=0 -lameopts mode=0 -lameopts aq=7 -lameopts padding=3 -af volnorm -xvidencopts max_bframes=0:nogmc:noqpel ";
try{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(commend);
new process(proc.getInputStream(),"INFO").start();
new process(proc.getErrorStream(),"ERROR").start();
int status = proc.waitFor();
if (status == 0)
System.out.println("执行完毕");
else
System.out.println("执行失败");
System.out.println("转换avi运行时间:" + (System.currentTimeMillis() - lasting)
+ "毫秒");
return pathto;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
private static boolean processFLV(String oldfilepath,String filename) {
long lasting = System.currentTimeMillis();
String path = Community.webpath.replace("/", "\\")+"vedioflv\\";
String commend="";
commend+=Community.webpath.replace("/", "\\")+"jmq\\Libs\\ffmpeg.exe ";
commend+="-i ";
commend+=oldfilepath;
commend+=" -ar ";
commend+="22050 ";
commend+="-ab ";
commend+="56 ";
commend+="-f ";
commend+="flv -qscale 6 ";
commend+="-y ";
commend+="-b ";
commend+="320x240 ";
commend+=" "+path+filename+".flv";
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(commend);
new process(proc.getInputStream(),"INFO").start();
new process(proc.getErrorStream(),"ERROR").start();
int status = proc.waitFor();
if (status == 0)
System.out.println("执行完毕");
else
System.out.println("执行失败");
System.out.println("转换flv运行时间:" + (System.currentTimeMillis() - lasting)
+ "毫秒");
/* ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.start();*/
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
String patht = Community.webpath.replace("/", "\\")+"jmq\\WisMencoder\\mencoder.exe ";
下载一个flv视频转换器就可以了。