| | |
| | | import com.whyc.service.VideoService; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.FileUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | |
| | | @EnableScheduling |
| | | @Component |
| | | @Slf4j |
| | | public class VideoScheduleService { |
| | | |
| | | @Autowired |
| | |
| | | * 3.考虑意外情况:突然程序死机或者电脑断电重启,需要延时启动录像,因为视频推流服务还未完成,延时20s开始检测 |
| | | * |
| | | * */ |
| | | //@Scheduled(cron = "0/2 * * * * ? ") |
| | | @Scheduled(fixedRate = 2000,initialDelay = 20000) |
| | | public void startRecordAndCheck(){ |
| | | ThreadPoolExecutorFactory.getPoolExecutor().execute(()->{ |
| | | List<String> videoStreamIds = YamlProperties.videoStreamIds; |
| | | Response4Http streamIdsOnlineRes = service.getVideoStreamIds(); |
| | | List<String> streamIdsOnline = (List<String>) streamIdsOnlineRes.getData2()==null?new ArrayList<>():(List<String>) streamIdsOnlineRes.getData2(); |
| | | |
| | | if(streamIdsOnlineRes.getCode() == 1 && ((boolean) streamIdsOnlineRes.getData())){ |
| | | videoStreamIds.forEach(streamId->{ |
| | | if(!streamIdsOnline.contains(streamId)){ //流不存在 |
| | |
| | | |
| | | Response4Http response2 = service.startRecord(streamId); |
| | | if(!(response2.getCode() ==1 && ((boolean) response2.getData()))){ |
| | | System.out.println("流id为:"+streamId+"的信息:"+response2.getMsg()); |
| | | log.info("流id为:"+streamId+"的信息:"+response2.getMsg()); |
| | | }else{ |
| | | System.out.println("流id为:"+streamId+"的信息:"+response2.getData()); |
| | | log.error("流id为:"+streamId+"的信息:"+response2.getData()); |
| | | } |
| | | }else{ //流存在 |
| | | //检查是否在录制状态 |
| | |
| | | if(!(boolean)recordingRes.getData()){ //不在录制,则进行录制 |
| | | Response4Http response2 = service.startRecord(streamId); |
| | | if(!(response2.getCode() ==1 && ((boolean) response2.getData()))){ |
| | | System.out.println("流id为:"+streamId+"的信息:"+response2.getMsg()); |
| | | log.error("流id为:"+streamId+"的信息:"+response2.getMsg()); |
| | | }else{ |
| | | System.out.println("流id为:"+streamId+"的信息:"+response2.getData()); |
| | | log.info("流id为:"+streamId+"的信息:"+response2.getData()); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 录像保持3天 |
| | | * 录像保持7天 |
| | | */ |
| | | @Scheduled(cron= "0 0 3 * * ?") |
| | | @Scheduled(cron= "0 0 7 * * ?") |
| | | public void recordRecycle(){ |
| | | System.out.println("-----------执行录像循环----------:"+ DateUtil.YYYY_MM_DD_HH_MM_SS.format(new Date())); |
| | | log.info("-----------执行录像循环----------:"+ DateUtil.YYYY_MM_DD_HH_MM_SS.format(new Date())); |
| | | //文件夹路径 /battery_system/video_system/Debug/www/record/rtp/{streamId}/{day}} |
| | | List<String> videoStreamIds = YamlProperties.videoStreamIds; |
| | | videoStreamIds.forEach(streamId ->{ |
| | | String dirPath = "/battery_system/video_system/Debug/www/record/rtp/"+streamId; |
| | | String dirPath = "/battery_system/video_system/ZLMediaKit/www/record/rtp/"+streamId; |
| | | //String dirPath = "/batterySystem/videoSystem/ZLMediaKit/www/record/rtp/"+streamId; |
| | | File dirFile = new File(dirPath); |
| | | String[] dirList = dirFile.list(); |
| | | List<String> dirList2 = Arrays.asList(dirList); |
| | | |
| | | for (int i = 0; i < dirList2.size()-3; i++) { |
| | | //按顺序删除,保留最后3个day的视频录像文件夹 |
| | | //按顺序删除,保留最后7个day的视频录像文件夹 |
| | | String dirPath2Remove = dirPath + File.separator + dirList2.get(i); |
| | | File dir2Remove = new File(dirPath2Remove); |
| | | FileUtil.deleteFile(dir2Remove); |
| | | log.info("删除录像文件夹:"+dirPath2Remove); |
| | | } |
| | | }); |
| | | } |