From 82258b502bb39bd7621617d79c59d2973fd4b378 Mon Sep 17 00:00:00 2001 From: whycxzp <glperry@163.com> Date: 星期四, 09 一月 2025 11:29:24 +0800 Subject: [PATCH] 摄像头视频流相关接口 --- src/main/java/com/whyc/schedule/VideoScheduleService.java | 82 ++++++++++++++++++++++++++++++++++++---- 1 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/whyc/schedule/VideoScheduleService.java b/src/main/java/com/whyc/schedule/VideoScheduleService.java index e10fd1d..450e814 100644 --- a/src/main/java/com/whyc/schedule/VideoScheduleService.java +++ b/src/main/java/com/whyc/schedule/VideoScheduleService.java @@ -1,11 +1,23 @@ package com.whyc.schedule; +import com.whyc.constant.YamlProperties; +import com.whyc.dto.Response; +import com.whyc.dto.Response4Http; import com.whyc.factory.ThreadPoolExecutorFactory; import com.whyc.service.VideoService; +import com.whyc.util.DateUtil; +import com.whyc.util.FileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; @EnableScheduling @Component @@ -14,19 +26,71 @@ @Autowired private VideoService service; - /**鍑屾櫒0鐐规墽琛屼竴娆�,褰曞埗瑙嗛娴�*/ - @Scheduled(cron = "0 0 0 * * ? ") - public void getAndSaveB247(){ + /** + * 1.鐩戞帶褰曞埗,棰戞涓�2s. + * 2.瑙嗛褰曞埗鐨勫垽鏂�昏緫鏄�: + * 鏄惁瀛樺湪娴� + * 鏄惁鍦ㄥ綍鍒� + * 3.鑰冭檻鎰忓鎯呭喌:绐佺劧绋嬪簭姝绘満鎴栬�呯數鑴戞柇鐢甸噸鍚�,闇�瑕佸欢鏃跺惎鍔ㄥ綍鍍�,鍥犱负瑙嗛鎺ㄦ祦鏈嶅姟杩樻湭瀹屾垚,寤舵椂20s寮�濮嬫娴� + * + * */ + //@Scheduled(cron = "0/2 * * * * ? ") + @Scheduled(fixedRate = 2000,initialDelay = 20000) + public void startRecordAndCheck(){ ThreadPoolExecutorFactory.getPoolExecutor().execute(()->{ - //service.getAndSaveB247(); + 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<String> response = service.addStreamProxy(streamId); + + Response4Http response2 = service.startRecord(streamId); + if(!(response2.getCode() ==1 && ((boolean) response2.getData()))){ + System.out.println("娴乮d涓�:"+streamId+"鐨勪俊鎭�:"+response2.getMsg()); + }else{ + System.out.println("娴乮d涓�:"+streamId+"鐨勪俊鎭�:"+response2.getData()); + } + }else{ //娴佸瓨鍦� + //妫�鏌ユ槸鍚﹀湪褰曞埗鐘舵�� + Response4Http recordingRes = service.isRecording(streamId); + if(!(boolean)recordingRes.getData()){ //涓嶅湪褰曞埗,鍒欒繘琛屽綍鍒� + Response4Http response2 = service.startRecord(streamId); + if(!(response2.getCode() ==1 && ((boolean) response2.getData()))){ + System.out.println("娴乮d涓�:"+streamId+"鐨勪俊鎭�:"+response2.getMsg()); + }else{ + System.out.println("娴乮d涓�:"+streamId+"鐨勪俊鎭�:"+response2.getData()); + } + } + } + }); + } }); } - /**鍑屾櫒0鐐�0鍒�2绉掓墽琛屼竴娆�,鍋滄涓婃鐨勫綍鍒惰棰戞祦*/ - @Scheduled(cron = "2 0 0 * * ? ") - public void getAndSaveA250(){ - ThreadPoolExecutorFactory.getPoolExecutor().execute(()->{ - //service.getAndSaveA250(); + /** + * 褰曞儚淇濇寔3澶� + */ + @Scheduled(cron= "0 0 3 * * ?") + public void recordRecycle(){ + System.out.println("-----------鎵ц褰曞儚寰幆----------:"+ 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; + 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涓猟ay鐨勮棰戝綍鍍忔枃浠跺す + String dirPath2Remove = dirPath + File.separator + dirList2.get(i); + File dir2Remove = new File(dirPath2Remove); + FileUtil.deleteFile(dir2Remove); + } }); } -- Gitblit v1.9.1