package com.boying.common;
|
|
import java.io.BufferedReader;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.InputStreamReader;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
public class ConvetorUtil {
|
private static String ffmpegEXE = "E:\\HK\\ffmpeg-7.0.1-essentials_build\\bin\\ffmpeg.exe";
|
public static void convetor(String videoInputPath, String videoOutPath) throws Exception {
|
List<String> command = new ArrayList<String>();
|
command.add(ffmpegEXE);
|
command.add("-i");
|
command.add(videoInputPath);
|
command.add("-c");
|
command.add("copy");
|
command.add("-an");
|
command.add(videoOutPath);
|
ProcessBuilder builder = new ProcessBuilder(command);
|
Process process = null;
|
try {
|
process = builder.start();
|
} catch (IOException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
// 使用这种方式会在瞬间大量消耗CPU和内存等系统资源,所以这里我们需要对流进行处理
|
InputStream errorStream = process.getErrorStream();
|
InputStreamReader inputStreamReader = new InputStreamReader(errorStream);
|
BufferedReader br = new BufferedReader(inputStreamReader);
|
String line = "";
|
while ((line = br.readLine()) != null) {
|
}
|
if (br != null) {
|
br.close();
|
}
|
if (inputStreamReader != null) {
|
inputStreamReader.close();
|
}
|
if (errorStream != null) {
|
errorStream.close();
|
}
|
|
}
|
}
|