|
@@ -29,10 +29,10 @@ import java.util.stream.Collectors;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class CameraUtil {
|
|
public class CameraUtil {
|
|
|
|
|
|
- private static String url;
|
|
|
|
private static String historyUrl;
|
|
private static String historyUrl;
|
|
private static String ffmpegPath;
|
|
private static String ffmpegPath;
|
|
private static String filePath;
|
|
private static String filePath;
|
|
|
|
+ private static String webUrl;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private CaneraConfig caneraConfig;
|
|
private CaneraConfig caneraConfig;
|
|
@@ -62,10 +62,7 @@ public class CameraUtil {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}).start();
|
|
}).start();
|
|
- // windows可以 linux不行
|
|
|
|
-// convetor(fromVideoFileList, NewfilePath);
|
|
|
|
return Constants.RESOURCE_PREFIX + "/" + ph;
|
|
return Constants.RESOURCE_PREFIX + "/" + ph;
|
|
-// return mappingUrl + "record/flv/hazard/" + ph;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -76,7 +73,7 @@ public class CameraUtil {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static String getPlayFlv(String cameraCode, String channel) {
|
|
public static String getPlayFlv(String cameraCode, String channel) {
|
|
- return historyUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
|
|
|
|
|
|
+ return webUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -100,24 +97,17 @@ public class CameraUtil {
|
|
return historyUrl + "/api/record/flv/stop?id=" + taskId;
|
|
return historyUrl + "/api/record/flv/stop?id=" + taskId;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 实时播放
|
|
|
|
|
|
+ * 历史回放流(获取)
|
|
*
|
|
*
|
|
- * @param cameraCode
|
|
|
|
- * @param channel
|
|
|
|
|
|
+ * @param channel 相机通道
|
|
|
|
+ * @param startTm 开始时间
|
|
|
|
+ * @param endTm 结束时间
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static String play(String cameraCode, String channel) {
|
|
|
|
- if (StringUtils.isBlank(cameraCode) || StringUtils.isBlank(channel)) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- String param = "id=" + cameraCode + "&channel=" + channel;
|
|
|
|
- return HttpUtils.sendGet(url + "/gb28181/api/records", param);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
public static String historyPlayListStr(String channel, Date startTm, Date endTm) {
|
|
public static String historyPlayListStr(String channel, Date startTm, Date endTm) {
|
|
- List<String> list = historyPlayList(channel, startTm, endTm, filePath);
|
|
|
|
|
|
+ List<String> list = filterPlayList(channel, startTm, endTm, filePath);
|
|
String ph = "flv/" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())
|
|
String ph = "flv/" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())
|
|
+ "/" + channel + "/"
|
|
+ "/" + channel + "/"
|
|
+ UUID.randomUUID().toString() + ".flv";
|
|
+ UUID.randomUUID().toString() + ".flv";
|
|
@@ -135,7 +125,16 @@ public class CameraUtil {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public static List<String> historyPlayList(String channel, Date startTm, Date endTm, String mappingUrl) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 过滤符合条件的视频
|
|
|
|
+ *
|
|
|
|
+ * @param channel
|
|
|
|
+ * @param startTm
|
|
|
|
+ * @param endTm
|
|
|
|
+ * @param mappingUrl
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static List<String> filterPlayList(String channel, Date startTm, Date endTm, String mappingUrl) {
|
|
if (StringUtils.isBlank(channel)
|
|
if (StringUtils.isBlank(channel)
|
|
|| ObjectUtils.isEmpty(startTm)
|
|
|| ObjectUtils.isEmpty(startTm)
|
|
|| ObjectUtils.isEmpty(endTm)) {
|
|
|| ObjectUtils.isEmpty(endTm)) {
|
|
@@ -203,133 +202,11 @@ public class CameraUtil {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * * 参数:
|
|
|
|
- * **List<String> fromVideoFileList 需要合并的多视频url地址以List存放**
|
|
|
|
- * **String ffmpeg 此处是ffmpeg 配置地址,可写死如“E:/ffmpeg/bin/ffmpeg.exe”**
|
|
|
|
- * **String NewfilePath 合并后的视频存放地址,如:E:/mergevideo.mp4***
|
|
|
|
|
|
+ * 合并视频(转化文件)
|
|
|
|
+ * @param fromVideoFileList 视频路径
|
|
|
|
+ * @param newfilePath 生产新的视频文件路径
|
|
|
|
+ * @throws IOException
|
|
*/
|
|
*/
|
|
- public static void convetor(List<String> fromVideoFileList,
|
|
|
|
- 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<>();
|
|
|
|
- Process process = null;
|
|
|
|
- ProcessBuilder builder = 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);
|
|
|
|
- // 转化为临时文件 .ts 放入到 voidTS里面
|
|
|
|
- for (int i = 0; i < fromVideoFileList.size(); i++) {
|
|
|
|
- String fromVideoFile = fromVideoFileList.get(i);
|
|
|
|
- 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();
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- 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();
|
|
|
|
- tsPath.append(ffmpegPath);
|
|
|
|
- tsPath.append(" -i ");
|
|
|
|
- tsPath.append("concat:");
|
|
|
|
- log.info("voidTS:{}", voidTS);
|
|
|
|
- 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);
|
|
|
|
- log.info("执行的命令:{}", tsPath.toString());
|
|
|
|
- Process pr = Runtime.getRuntime().exec(
|
|
|
|
- tsPath.toString());
|
|
|
|
- process.getInputStream();
|
|
|
|
- pr.getOutputStream().close();
|
|
|
|
- pr.getInputStream().close();
|
|
|
|
- pr.getErrorStream().close();
|
|
|
|
- try {
|
|
|
|
- int i = pr.waitFor();
|
|
|
|
- System.out.println("********");
|
|
|
|
- log.info("********");
|
|
|
|
- System.out.println(i);
|
|
|
|
- log.info(i + "");
|
|
|
|
- log.info("********");
|
|
|
|
- System.out.println("********");
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- log.error(e.getMessage());
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- pr.destroy();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //删除生成的ts文件
|
|
|
|
-// for (String filePath : voidTS) {
|
|
|
|
-// File filet = new File(filePath);
|
|
|
|
-// filet.delete();
|
|
|
|
-// pr.destroy();
|
|
|
|
-// }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
public static void myConvetor(List<String> fromVideoFileList,
|
|
public static void myConvetor(List<String> fromVideoFileList,
|
|
String newfilePath) throws IOException {
|
|
String newfilePath) throws IOException {
|
|
/*
|
|
/*
|
|
@@ -429,28 +306,21 @@ public class CameraUtil {
|
|
String s = HttpUtils.sendGet("http://47.106.159.135/streams" + "/api/record/flv/list", param);
|
|
String s = HttpUtils.sendGet("http://47.106.159.135/streams" + "/api/record/flv/list", param);
|
|
}
|
|
}
|
|
|
|
|
|
- //工具类
|
|
|
|
-
|
|
|
|
- public static void queryRecords(String cameraCode, String channel, Date startTm, Date endTm) {
|
|
|
|
- if (StringUtils.isBlank(cameraCode)
|
|
|
|
- || StringUtils.isBlank(channel)
|
|
|
|
- || ObjectUtils.isEmpty(startTm)
|
|
|
|
- || ObjectUtils.isEmpty(endTm)) {
|
|
|
|
- throw new BaseException("参数为空");
|
|
|
|
- }
|
|
|
|
- String param = "id=" + cameraCode + "&channel=" + channel + "&startTime=" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTm) + "&endTm=" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTm);
|
|
|
|
- String s = HttpUtils.sendGet(historyUrl + "/api/gb28181/query/records", param);
|
|
|
|
- System.out.println(s);
|
|
|
|
- }
|
|
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
public void init() {
|
|
public void init() {
|
|
- url = caneraConfig.getUrl();
|
|
|
|
historyUrl = caneraConfig.getHistoryUrl();
|
|
historyUrl = caneraConfig.getHistoryUrl();
|
|
ffmpegPath = caneraConfig.getFfmpegPath();
|
|
ffmpegPath = caneraConfig.getFfmpegPath();
|
|
filePath = caneraConfig.getFilePath();
|
|
filePath = caneraConfig.getFilePath();
|
|
|
|
+ webUrl = caneraConfig.getWebUrl();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 定时任务参数flv文件
|
|
|
|
+ *
|
|
|
|
+ * @throws IOException
|
|
|
|
+ * @throws InterruptedException
|
|
|
|
+ */
|
|
public void deleteFlv() throws IOException, InterruptedException {
|
|
public void deleteFlv() throws IOException, InterruptedException {
|
|
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
|
|
Date date = new Date();
|
|
Date date = new Date();
|