视频录制功能
This commit is contained in:
parent
727d347c71
commit
84b3154cdd
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package com.tuoheng.steam.dos;
|
||||
|
||||
public enum ProcessType {
|
||||
RECORD,MERGE
|
||||
RECORD,MERGE,PIC
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue