|
@@ -29,7 +29,7 @@ public class CameraUtil {
|
|
|
|
|
|
private static String url;
|
|
|
private static String historyUrl;
|
|
|
- private static String ffmpegPath = "C:\\Users\\Administrator.DESKTOP-0NUUTMM\\Downloads\\ffmpeg-5.1.2-essentials_build\\ffmpeg-5.1.2-essentials_build\\bin\\ffmpeg.exe";
|
|
|
+ private static String ffmpegPath;
|
|
|
private static String mappingUrl;
|
|
|
private static String flvPath;
|
|
|
private static String filePath;
|
|
@@ -168,99 +168,94 @@ public class CameraUtil {
|
|
|
*/
|
|
|
public static void convetor(List<String> fromVideoFileList,
|
|
|
String NewfilePath) throws IOException {
|
|
|
+ List<String> voidTS = new ArrayList<>();
|
|
|
+ Process process = null;
|
|
|
+ ProcessBuilder builder = null;
|
|
|
+ List<String> command = null;
|
|
|
|
|
|
-
|
|
|
- try {
|
|
|
- List<String> voidTS = new ArrayList<>();
|
|
|
- Process process = null;
|
|
|
- ProcessBuilder builder = null;
|
|
|
- List<String> command = null;
|
|
|
- for (int i = 0; i < fromVideoFileList.size(); i++) {
|
|
|
- String fromVideoFile = fromVideoFileList.get(i);
|
|
|
- command = new ArrayList<String>();
|
|
|
- command.add(ffmpegPath);
|
|
|
- command.add("-y");
|
|
|
- command.add("-i");
|
|
|
- command.add(fromVideoFile);
|
|
|
- command.add("-vcodec");
|
|
|
- command.add("copy");
|
|
|
- command.add("-bsf:v");
|
|
|
- command.add("h264_mp4toannexb");
|
|
|
- command.add("-f");
|
|
|
- command.add("mpegts");
|
|
|
- command.add(fromVideoFile.substring(0,
|
|
|
- fromVideoFile.lastIndexOf(".")) + ".ts");
|
|
|
- builder = new ProcessBuilder(command);
|
|
|
- voidTS.add(fromVideoFile.substring(0,
|
|
|
- fromVideoFile.lastIndexOf("."))
|
|
|
- + ".ts");
|
|
|
- try {
|
|
|
- process = builder.start();
|
|
|
- InputStream errorStream = process
|
|
|
- .getErrorStream();
|
|
|
- InputStreamReader inputStreamReader = new InputStreamReader(
|
|
|
- errorStream);
|
|
|
- BufferedReader br = new BufferedReader(
|
|
|
- inputStreamReader);
|
|
|
- String line = "";
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- while ((line = br.readLine()) != null) {
|
|
|
- sb.append(line);
|
|
|
- }
|
|
|
- String regexDuration = "Duration: (.*?), start: (.*?), bitrate: (\\d*) kb\\/s";
|
|
|
- Pattern pattern = Pattern
|
|
|
- .compile(regexDuration);
|
|
|
- Matcher m = pattern.matcher(sb.toString());
|
|
|
- System.out.println(sb.toString());
|
|
|
- br.close();
|
|
|
- inputStreamReader.close();
|
|
|
- errorStream.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- List<String> dos = new ArrayList<>();
|
|
|
- StringBuffer tsPath = new StringBuffer();
|
|
|
- tsPath.append(ffmpegPath);
|
|
|
- tsPath.append(" -i ");
|
|
|
- tsPath.append("concat:");
|
|
|
- for (int t = 0; t < voidTS.size(); t++) {
|
|
|
- if (t != voidTS.size() - 1) {
|
|
|
- tsPath.append(voidTS.get(t) + "|");
|
|
|
- } else {
|
|
|
- tsPath.append(voidTS.get(t));
|
|
|
- }
|
|
|
- }
|
|
|
- tsPath.append(" -vcodec ");
|
|
|
- tsPath.append(" copy ");
|
|
|
- tsPath.append(" -bsf:a ");
|
|
|
- tsPath.append(" aac_adtstoasc ");
|
|
|
- tsPath.append(" -movflags ");
|
|
|
- tsPath.append(" +faststart ");
|
|
|
- tsPath.append(NewfilePath);
|
|
|
- Process pr = Runtime.getRuntime().exec(
|
|
|
- tsPath.toString());
|
|
|
- process.getInputStream();
|
|
|
- pr.getOutputStream().close();
|
|
|
- pr.getInputStream().close();
|
|
|
- pr.getErrorStream().close();
|
|
|
+ for (int i = 0; i < fromVideoFileList.size(); i++) {
|
|
|
+ String fromVideoFile = fromVideoFileList.get(i);
|
|
|
+ command = new ArrayList<String>();
|
|
|
+ command.add(ffmpegPath);
|
|
|
+ command.add("-y");
|
|
|
+ command.add("-i");
|
|
|
+ command.add(fromVideoFile);
|
|
|
+ command.add("-vcodec");
|
|
|
+ command.add("copy");
|
|
|
+ command.add("-bsf:v");
|
|
|
+ command.add("h264_mp4toannexb");
|
|
|
+ command.add("-f");
|
|
|
+ command.add("mpegts");
|
|
|
+ fromVideoFile = fromVideoFile.substring(fromVideoFile.lastIndexOf("/") + 1, fromVideoFile.length());
|
|
|
+ String n = flvPath + fromVideoFile.substring(0,
|
|
|
+ fromVideoFile.lastIndexOf("."));
|
|
|
+ command.add(n + ".ts");
|
|
|
+ builder = new ProcessBuilder(command);
|
|
|
+ voidTS.add(n + ".ts");
|
|
|
try {
|
|
|
- pr.waitFor();
|
|
|
- Thread.sleep(1000);
|
|
|
- pr.destroy();
|
|
|
- } catch (InterruptedException e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
+ process = builder.start();
|
|
|
+ InputStream errorStream = process
|
|
|
+ .getErrorStream();
|
|
|
+ InputStreamReader inputStreamReader = new InputStreamReader(
|
|
|
+ errorStream);
|
|
|
+ BufferedReader br = new BufferedReader(
|
|
|
+ inputStreamReader);
|
|
|
+ String line = "";
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
+ sb.append(line);
|
|
|
+ }
|
|
|
+ String regexDuration = "Duration: (.*?), start: (.*?), bitrate: (\\d*) kb\\/s";
|
|
|
+ Pattern pattern = Pattern
|
|
|
+ .compile(regexDuration);
|
|
|
+ Matcher m = pattern.matcher(sb.toString());
|
|
|
+ System.out.println(sb.toString());
|
|
|
+ br.close();
|
|
|
+ inputStreamReader.close();
|
|
|
+ errorStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- //删除生成的ts文件
|
|
|
- for (String filePath : voidTS) {
|
|
|
- File file = new File(filePath);
|
|
|
- file.delete();
|
|
|
- pr.destroy();
|
|
|
+ }
|
|
|
+ List<String> dos = new ArrayList<>();
|
|
|
+ StringBuffer tsPath = new StringBuffer();
|
|
|
+ tsPath.append(ffmpegPath);
|
|
|
+ tsPath.append(" -i ");
|
|
|
+ tsPath.append("concat:");
|
|
|
+ for (int t = 0; t < voidTS.size(); t++) {
|
|
|
+ if (t != voidTS.size() - 1) {
|
|
|
+ tsPath.append(voidTS.get(t) + "|");
|
|
|
+ } else {
|
|
|
+ tsPath.append(voidTS.get(t));
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
+ }
|
|
|
+ tsPath.append(" -vcodec ");
|
|
|
+ tsPath.append(" copy ");
|
|
|
+ tsPath.append(" -bsf:a ");
|
|
|
+ tsPath.append(" aac_adtstoasc ");
|
|
|
+ tsPath.append(" -movflags ");
|
|
|
+ tsPath.append(" +faststart ");
|
|
|
+ tsPath.append(NewfilePath);
|
|
|
+ Process pr = Runtime.getRuntime().exec(
|
|
|
+ tsPath.toString());
|
|
|
+ process.getInputStream();
|
|
|
+ pr.getOutputStream().close();
|
|
|
+ pr.getInputStream().close();
|
|
|
+ pr.getErrorStream().close();
|
|
|
+ try {
|
|
|
+ pr.waitFor();
|
|
|
+ Thread.sleep(1000);
|
|
|
+ pr.destroy();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ //删除生成的ts文件
|
|
|
+ for (String filePath : voidTS) {
|
|
|
+ File file = new File(filePath);
|
|
|
+ file.delete();
|
|
|
+ pr.destroy();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|