import java.io.File;
import java.util.List;
public class CodeConven {
private static String OldPath;
private static String NewPath;
private static String ImgPath;
public static boolean process() {
int type = checkContentType();
boolean status = false;
if (type == 0) {
status = processFLV(OldPath);// 直接将文件转为flv文件
ffmpegTransImage(OldPath);
}
return status;
}
private static int checkContentType() {
String type = OldPath.substring(OldPath.lastIndexOf(".") + 1,
OldPath.length()).toLowerCase();
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;
}
else if (type.equals("wmv9")) {
return 0;
} else if (type.equals("rm")) {
return 0;
} else if (type.equals("rmvb")) {
return 0;
}
return 9;
}
private static boolean checkfile(String OldPath) {
File file = new File(OldPath);
if (!file.isFile()) {
return false;
}
return true;
}
// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv,rmvb,rm等--*其他的格式没有试过了)
private static boolean processFLV(String oldfilepath) {
if (!checkfile(OldPath)) {
System.out.println(oldfilepath + " is not file");
return false;
}
System.out.println("过来了没");
List<String> commend = new java.util.ArrayList<String>();
commend.add("F:\\ffmpeg\\ffmpeg");
commend.add("-i");
commend.add("F:\\avs\\AviSynth 2.5\\Examples\\1.avs"); //avs存放路径
commend.add("-ab");
commend.add("64");
commend.add("-acodec");
commend.add("libmp3lame");
commend.add("-ac");
commend.add("2");
commend.add("-ar");
commend.add("22050");
commend.add("-r");
commend.add("24");
commend.add("-y");
commend.add(NewPath);
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.start();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public static boolean ffmpegTransImage(String imgPath) {
List<String> commend = new java.util.ArrayList<String>();
commend.add("F:\\ffmpeg\\ffmpeg.exe");
commend.add("-i");
commend.add(imgPath);
commend.add("-y");
commend.add("-f");
commend.add("image2");
commend.add("-ss");
commend.add("38");
commend.add("-t");
commend.add("1");
commend.add("-s");
commend.add("320x240");
commend.add(ImgPath);
System.out.print("到底截图了没.............");
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.start();
System.out.println("截完没?");
return true;
} catch (Exception e){
e.printStackTrace();
return false;
}
}
public String getImgPath() {
return ImgPath;
}
public void setImgPath(String imgPath) {
ImgPath = imgPath;
}
public String getOldPath() {
return OldPath;
}
public void setOldPath(String oldPath) {
OldPath = oldPath;
}
public String getNewPath() {
return NewPath;
}
public void setNewPath(String newPath) {
NewPath = newPath;
}
}
//avs的写法
LoadPlugin("C:/WINDOWS/system32/vsfilter.dll")
Video0 = DirectShowSource("D:/avi/6.avi",fps=23.976,convertfps=true)
Video0 = ConvertToRGB(Video0)
Video1 = Trim(Video0,1,122)
Logo_1 = ImageReader("F:/ffmpeg/logobai.png").ConvertToRGB32
Logo_2 = ImageReader("F:/ffmpeg/logohei.png").ConvertToRGB32
Logo_3 = Logo_1.mask(Logo_2)
Video0 = Trim(Video0,0,0).Layer(Logo_3,"add",255,0,0)
Video0 = ConvertToYV12(Video0)
return Video0
//avs第二种写法
LoadPlugin("C:/WINDOWS/system32/vsfilter.dll")
video = DirectShowSource("D:/avi/6.avi")
logo = ImageSource("F:/ffmpeg/logobai.png")
logomask = ImageSource("F:/ffmpeg/logohei.png")
overlay(video,logo,mask=logomask,opacity=0.8)