Compare commits

...

2 Commits

Author SHA1 Message Date
孙小云 84b3154cdd 视频录制功能 2025-03-22 16:31:22 +08:00
孙小云 727d347c71 修改分页开始地址 2025-03-17 13:32:07 +08:00
7 changed files with 104 additions and 15 deletions

View File

@ -34,6 +34,23 @@ public class StreamRecordController {
@Autowired
IRecordService iRecordService;
@GetMapping("pic")
public Response<String> startPic(@RequestParam String streamUrl) {
System.out.println("启动视频拍照 :"+streamUrl);
if(Objects.isNull(streamUrl)) {
return Response.fail(-1);
}
String outfile = taskService.startPic(streamUrl);
if(Objects.nonNull(outfile)) {
return Response.success(outfile);
}else {
return Response.fail(-1);
}
}
@GetMapping("start")
public Response<StreamTask> startRecording(@RequestParam String streamUrl) {
System.out.println("启动录制 :"+streamUrl);

View File

@ -10,10 +10,10 @@ public class PageInfo <T> implements Serializable {
public PageInfo(List<T> list,int page,int pageSize) {
this.total = list.size();
this.pageSize = pageSize;
this.pageIndex = page;
this.pageIndex = page ;
// 计算分页数据
int fromIndex = page * pageSize; // 起始索引
int fromIndex = (page - 1) * pageSize; // 起始索引
int toIndex = Math.min(fromIndex + pageSize, total); // 结束索引
// 检查页码是否超出范围

View File

@ -1,5 +1,5 @@
package com.tuoheng.steam.dos;
public enum ProcessType {
RECORD,MERGE
RECORD,MERGE,PIC
}

View File

@ -6,6 +6,8 @@ public interface ITaskService {
public StreamTask startTask(String streamUrl);
public String startPic(String streamUrl);
public StreamTask stopTask(String streamUrl);
public StreamTask getLastTask(String streamUrl);

View File

@ -118,6 +118,34 @@ public class TaskService implements ITaskService{
}, 60, 60, TimeUnit.SECONDS);
}
public String startPic(String streamUrl) {
try {
StreamProcess streamProcess = processService.takePic(streamUrl);
String outFileName = streamProcess.getFileName();
/*
注册进程
*/
ProcessManager.registerProcess(streamProcess.getInnerProcessId());
logger.info("streamUrl {} startPicProcess {} ", streamUrl,streamProcess.getInnerProcessId());
CompletableFuture<Process> future = streamProcess.onExit();
future.thenRun(() -> {
logger.info("streamUrl {} startPicProcess {} Over ", streamUrl,streamProcess.getInnerProcessId());
streamProcess.setStopTime(TimeUtils.formatDateToString(new Date()));
ProcessManager.unRegisterProcess(streamProcess.getInnerProcessId());
}).exceptionally(ex -> {
logger.info("streamUrl {} startPicProcess {} Exceptionally ", streamUrl,streamProcess.getInnerProcessId());
streamProcess.setStopTime(TimeUtils.formatDateToString(new Date()));
ProcessManager.unRegisterProcess(streamProcess.getInnerProcessId());
return null;
});
return outFileName;
}catch (Exception e) {
logger.info("streamUrl {} ", streamUrl,e);
}
return null;
}
public StreamTask startTask(String streamUrl) {
/*

View File

@ -97,6 +97,48 @@ public class ProcessService {
}
public StreamProcess takePic(String streamUrl) throws IOException {
String outFileName = targetPath + "/" +UUID.randomUUID().toString() +".jpg";
String command = String.format(
ffmpeg+ " -i %s -vf fps=1 -frames:v 1 -q:v 2 %s",
streamUrl, outFileName);
logger.info("takePic {}", command);
List<String> rcommand = new ArrayList<>();
rcommand.add(ffmpeg); // ffmpeg 路径
rcommand.add("-i");
rcommand.add(streamUrl); // 流地址
rcommand.add("-vf");
rcommand.add("fps=1");
rcommand.add("-frames:v");
rcommand.add("1");
rcommand.add("-q:v");
rcommand.add("2");
rcommand.add(outFileName); // 输出文件名
ProcessBuilder pb = new ProcessBuilder(rcommand);
pb.redirectErrorStream(true);
Process process = pb.start();
loggingService.execute(new Runnable() {
@Override
public void run() {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
logger.info("recordStream-------- {}",line);
}
} catch (IOException e) {
logger.info("takePic-------- Over");
}
}
});
return new StreamProcess(process,outFileName, ProcessType.PIC);
}
public StreamProcess recordStream(String streamUrl) throws IOException {
String recordFileName = splitPath+'/'+UUID.randomUUID().toString() +".ts";

View File

@ -1,14 +1,14 @@
spring.application.name=demo
server.port = 8989
srs.splitPath=/data/java/srs/stream_server/temp
srs.targetPath=/data/java/srs/srs/trunk/objs/nginx/html
ffmpeg=/data/ffmpeg/bin/ffmpeg
recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
livedates=8
#server.port = 8989
#srs.splitPath=/data/java/srs/stream_server/temp
#srs.targetPath=/data/java/srs/srs/trunk/objs/nginx/html
#ffmpeg=/data/ffmpeg/bin/ffmpeg
#recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
#livedates=8
#server.port = 8080
#srs.splitPath=/Users/sunpeng/workspace/stream/temp
#srs.targetPath=/Users/sunpeng/workspace/stream/html
#ffmpeg=ffmpeg
#recordPath=/Users/sunpeng/workspace/stream/record
#livedates=7
server.port = 8080
srs.splitPath=/Users/sunpeng/workspace/stream/temp
srs.targetPath=/Users/sunpeng/workspace/stream/html
ffmpeg=ffmpeg
recordPath=/Users/sunpeng/workspace/stream/record
livedates=7