|
@@ -191,54 +191,69 @@ public class CameraUtil {
|
|
* **String NewfilePath 合并后的视频存放地址,如:E:/mergevideo.mp4***
|
|
* **String NewfilePath 合并后的视频存放地址,如:E:/mergevideo.mp4***
|
|
*/
|
|
*/
|
|
public static void convetor(List<String> fromVideoFileList,
|
|
public static void convetor(List<String> fromVideoFileList,
|
|
- String NewfilePath) throws IOException {
|
|
|
|
|
|
+ String newfilePath) throws IOException {
|
|
|
|
+ File file = new File(newfilePath);
|
|
|
|
+ if (!file.getParentFile().exists()) {
|
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
|
+ log.info("创建文件夹:{}", file.getParentFile().getPath());
|
|
|
|
+ }
|
|
|
|
+ log.info("newfilePath:{}", newfilePath);
|
|
|
|
+ Runtime.getRuntime().exec("chmod 777 " + file.getParentFile().getPath());
|
|
List<String> voidTS = new ArrayList<>();
|
|
List<String> voidTS = new ArrayList<>();
|
|
Process process = null;
|
|
Process process = null;
|
|
ProcessBuilder builder = null;
|
|
ProcessBuilder builder = null;
|
|
List<String> command = null;
|
|
List<String> command = null;
|
|
-
|
|
|
|
|
|
+ String substr = fromVideoFileList.get(0).substring(0, fromVideoFileList.get(0).lastIndexOf("/"));
|
|
|
|
+ log.info("substr:{}", substr);
|
|
|
|
+ Runtime.getRuntime().exec("chmod 777 " + substr);
|
|
for (int i = 0; i < fromVideoFileList.size(); i++) {
|
|
for (int i = 0; i < fromVideoFileList.size(); i++) {
|
|
String fromVideoFile = fromVideoFileList.get(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 {
|
|
|
|
- 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);
|
|
|
|
|
|
+ File file1 = new File(fromVideoFile);
|
|
|
|
+ if (file1.exists()) {
|
|
|
|
+ log.info("文件存在:{}", fromVideoFile);
|
|
|
|
+ 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) {
|
|
|
|
+ log.error(e.getMessage());
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
- 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();
|
|
|
|
|
|
+ } else {
|
|
|
|
+ log.info("文件不存在:{}", fromVideoFile);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
List<String> dos = new ArrayList<>();
|
|
List<String> dos = new ArrayList<>();
|
|
@@ -259,7 +274,7 @@ public class CameraUtil {
|
|
tsPath.append(" aac_adtstoasc ");
|
|
tsPath.append(" aac_adtstoasc ");
|
|
tsPath.append(" -movflags ");
|
|
tsPath.append(" -movflags ");
|
|
tsPath.append(" +faststart ");
|
|
tsPath.append(" +faststart ");
|
|
- tsPath.append(NewfilePath);
|
|
|
|
|
|
+ tsPath.append(newfilePath);
|
|
Process pr = Runtime.getRuntime().exec(
|
|
Process pr = Runtime.getRuntime().exec(
|
|
tsPath.toString());
|
|
tsPath.toString());
|
|
process.getInputStream();
|
|
process.getInputStream();
|
|
@@ -268,17 +283,16 @@ public class CameraUtil {
|
|
pr.getErrorStream().close();
|
|
pr.getErrorStream().close();
|
|
try {
|
|
try {
|
|
pr.waitFor();
|
|
pr.waitFor();
|
|
- Thread.sleep(1000);
|
|
|
|
- pr.destroy();
|
|
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
- // TODO Auto-generated catch block
|
|
|
|
|
|
+ log.error(e.getMessage());
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ pr.destroy();
|
|
}
|
|
}
|
|
//删除生成的ts文件
|
|
//删除生成的ts文件
|
|
for (String filePath : voidTS) {
|
|
for (String filePath : voidTS) {
|
|
- File file = new File(filePath);
|
|
|
|
- file.delete();
|
|
|
|
- pr.destroy();
|
|
|
|
|
|
+ File filet = new File(filePath);
|
|
|
|
+ filet.delete();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|