|
@@ -48,12 +48,21 @@ public class CameraUtil {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static String historyPlay(List<String> fromVideoFileList, String ph) throws IOException {
|
|
|
+ public static String historyPlay(List<String> fromVideoFileList, String ph) {
|
|
|
// 视频服务映射路径
|
|
|
String NewfilePath = flvPath + ph;
|
|
|
log.info("NewfilePath:{}", NewfilePath);
|
|
|
log.info("fromVideoFileList:{}", fromVideoFileList);
|
|
|
- convetor(fromVideoFileList, NewfilePath);
|
|
|
+ new Thread(() -> {
|
|
|
+ try {
|
|
|
+ myConvetor(fromVideoFileList, NewfilePath);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ // windows可以 linux不行
|
|
|
+// convetor(fromVideoFileList, NewfilePath);
|
|
|
return mappingUrl + "record/flv/hazard/" + ph;
|
|
|
}
|
|
|
|
|
@@ -107,12 +116,12 @@ public class CameraUtil {
|
|
|
|
|
|
public static String historyPlayListStr(String channel, Date startTm, Date endTm) {
|
|
|
List<String> list = historyPlayList(channel, startTm, endTm, filePath);
|
|
|
- String ph = "flv/" + DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date())
|
|
|
- + "-" + channel + "-"
|
|
|
+ String ph = "flv/" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())
|
|
|
+ + "/" + channel + "/"
|
|
|
+ UUID.randomUUID().toString() + ".flv";
|
|
|
try {
|
|
|
return historyPlay(list, ph);
|
|
|
- } catch (IOException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -257,6 +266,9 @@ public class CameraUtil {
|
|
|
log.info("文件不存在:{}", fromVideoFile);
|
|
|
}
|
|
|
}
|
|
|
+ for (String voidT : voidTS) {
|
|
|
+ Runtime.getRuntime().exec("chmod 777 " + voidT);
|
|
|
+ }
|
|
|
log.info("ffmpegPath:{}", ffmpegPath);
|
|
|
List<String> dos = new ArrayList<>();
|
|
|
StringBuffer tsPath = new StringBuffer();
|
|
@@ -299,6 +311,7 @@ public class CameraUtil {
|
|
|
} finally {
|
|
|
pr.destroy();
|
|
|
}
|
|
|
+
|
|
|
//删除生成的ts文件
|
|
|
// for (String filePath : voidTS) {
|
|
|
// File filet = new File(filePath);
|
|
@@ -307,6 +320,84 @@ public class CameraUtil {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static void myConvetor(List<String> fromVideoFileList,
|
|
|
+ String newfilePath) throws IOException {
|
|
|
+ /*
|
|
|
+ * for f in *.flv; do echo "file '$f'" >> mylist.txt; done
|
|
|
+ ffmpeg -f concat -i mylist.txt -c copy output.flv
|
|
|
+ * */
|
|
|
+
|
|
|
+ List<String> rspList = new ArrayList<String>();
|
|
|
+ File file = new File(newfilePath);
|
|
|
+ boolean flay = false;
|
|
|
+ if (!file.getParentFile().exists()) {
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
+ log.info("创建文件夹:{}", file.getParentFile().getPath());
|
|
|
+ flay = true;
|
|
|
+ }
|
|
|
+ log.info("newfilePath:{}", newfilePath);
|
|
|
+
|
|
|
+
|
|
|
+ StringBuffer sm = new StringBuffer("for f in ");
|
|
|
+ for (int t = 0; t < fromVideoFileList.size(); t++) {
|
|
|
+ File ft = new File(fromVideoFileList.get(t));
|
|
|
+ if (ft.exists()) {
|
|
|
+ if (t != fromVideoFileList.size() - 1) {
|
|
|
+ sm.append(fromVideoFileList.get(t) + " ");
|
|
|
+ } else {
|
|
|
+ sm.append(fromVideoFileList.get(t));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String substring = newfilePath.substring(0, newfilePath.lastIndexOf("."));
|
|
|
+ substring = substring + ".txt";
|
|
|
+ log.info("临时转化的文件:{}", substring);
|
|
|
+
|
|
|
+
|
|
|
+ sm.append("; do echo \"file '$f'\" >> " + substring + "; done");
|
|
|
+ String commit = sm.toString();
|
|
|
+ log.info("合并转化文件的命令:{}", commit);
|
|
|
+ Process proc = Runtime.getRuntime().exec("/bin/bash", null, null);
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
|
|
|
+ PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String commit1 = ffmpegPath + " -f concat -safe 0 -i " + substring + " -c copy " + newfilePath;
|
|
|
+ List<String> commands = new ArrayList<>();
|
|
|
+ if (flay) {
|
|
|
+ commands.add("chomd -R 777 " + file.getParentFile().getPath());
|
|
|
+ }
|
|
|
+ // 合并成一个临时文件
|
|
|
+ commands.add(commit);
|
|
|
+ // 临时文件转化为 flv
|
|
|
+ commands.add(commit1);
|
|
|
+ for (String line : commands) {
|
|
|
+ out.println(line);
|
|
|
+ }
|
|
|
+ out.println("exit");// 这个命令必须执行,否则in流不结束。
|
|
|
+ String rspLine = "";
|
|
|
+ while ((rspLine = in.readLine()) != null) {
|
|
|
+ System.out.println(rspLine);
|
|
|
+ rspList.add(rspLine);
|
|
|
+ }
|
|
|
+ int i = proc.waitFor();
|
|
|
+ log.info("执行结果:{}", i);
|
|
|
+ //删除生成的ts文件
|
|
|
+ File file1 = new File(substring);
|
|
|
+ if (file1.exists()) {
|
|
|
+ file1.delete();
|
|
|
+ }
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ in.close();
|
|
|
+ out.close();
|
|
|
+ proc.destroy();
|
|
|
+ }
|
|
|
+ log.info("返回结果:{}", rspList);
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
|
List<String> fromVideoFileList = new ArrayList();
|