dashuju
This commit is contained in:
parent
15ce14f117
commit
0ba76855f0
|
|
@ -64,14 +64,14 @@ public class StreamRecordController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping({"start"})
|
@GetMapping({"start"})
|
||||||
public Response<StreamTask> startRecording(@RequestParam String streamUrl,@RequestParam String transaction) {
|
public Response<StreamTask> startRecording(@RequestParam String streamUrl) {
|
||||||
logger.info("启动录制 :" + streamUrl);
|
logger.info("启动录制 :" + streamUrl);
|
||||||
streamUrl = this.streamSwitch(streamUrl);
|
streamUrl = this.streamSwitch(streamUrl);
|
||||||
logger.info("启动录制_ :" + streamUrl);
|
logger.info("启动录制_ :" + streamUrl);
|
||||||
if (Objects.isNull(streamUrl)) {
|
if (Objects.isNull(streamUrl)) {
|
||||||
return Response.fail(-1);
|
return Response.fail(-1);
|
||||||
} else {
|
} else {
|
||||||
Response<StreamTask> response = Response.success(this.taskService.startTask(streamUrl,transaction));
|
Response<StreamTask> response = Response.success(this.taskService.startTask(streamUrl));
|
||||||
logger.info("启动录制返回 :" + JSON.toJSONString(response));
|
logger.info("启动录制返回 :" + JSON.toJSONString(response));
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import com.tuoheng.steam.dos.StreamTask;
|
||||||
*/
|
*/
|
||||||
public interface ITaskService {
|
public interface ITaskService {
|
||||||
|
|
||||||
public StreamTask startTask(String streamUrl,String transaction);
|
public StreamTask startTask(String streamUrl);
|
||||||
|
|
||||||
public String startPic(String streamUrl);
|
public String startPic(String streamUrl);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,12 +145,12 @@ public class TaskService implements ITaskService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamTask startTask(String streamUrl,String transaction) {
|
public StreamTask startTask(String streamUrl) {
|
||||||
if (this.runningTasks.containsKey(streamUrl)) {
|
if (this.runningTasks.containsKey(streamUrl)) {
|
||||||
return (StreamTask)this.runningTasks.get(streamUrl);
|
return (StreamTask)this.runningTasks.get(streamUrl);
|
||||||
} else {
|
} else {
|
||||||
StreamTask taskInstance = new StreamTask(streamUrl);
|
StreamTask taskInstance = new StreamTask(streamUrl);
|
||||||
taskInstance.setTransaction(transaction);
|
// taskInstance.setTransaction(transaction);
|
||||||
if (this.runningTasks.putIfAbsent(streamUrl, taskInstance) == null) {
|
if (this.runningTasks.putIfAbsent(streamUrl, taskInstance) == null) {
|
||||||
logger.info("streamUrl {} startTask {} transaction {}", streamUrl, taskInstance.getTaskId(), taskInstance.getTransaction());
|
logger.info("streamUrl {} startTask {} transaction {}", streamUrl, taskInstance.getTaskId(), taskInstance.getTransaction());
|
||||||
this.startTask(streamUrl, taskInstance);
|
this.startTask(streamUrl, taskInstance);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ public class ProcessService {
|
||||||
private String targetPath;
|
private String targetPath;
|
||||||
@Value("${recordPath}")
|
@Value("${recordPath}")
|
||||||
private String recordPath;
|
private String recordPath;
|
||||||
|
@Value("${video.bitrate:2000k}")
|
||||||
|
private String videoBitrate;
|
||||||
|
@Value("${audio.bitrate:128k}")
|
||||||
|
private String audioBitrate;
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ProcessService.class);
|
private static final Logger logger = LoggerFactory.getLogger(ProcessService.class);
|
||||||
ExecutorService loggingService = Executors.newCachedThreadPool();
|
ExecutorService loggingService = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
|
|
@ -144,7 +148,7 @@ public class ProcessService {
|
||||||
public StreamProcess recordStream(String streamUrl) throws IOException {
|
public StreamProcess recordStream(String streamUrl) throws IOException {
|
||||||
String var10000 = this.splitPath;
|
String var10000 = this.splitPath;
|
||||||
String recordFileName = var10000 + "/" + UUID.randomUUID().toString() + ".ts";
|
String recordFileName = var10000 + "/" + UUID.randomUUID().toString() + ".ts";
|
||||||
String command = String.format(this.ffmpeg + " -i %s -c copy -f mpegts -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 2 %s", Optional.of(streamUrl).filter((s) -> s.endsWith("_")).map((s) -> s.substring(0, s.length() - 1)).orElse(streamUrl), recordFileName);
|
String command = String.format(this.ffmpeg + " -i %s -c:v libx264 -b:v %s -c:a aac -b:a %s -f mpegts -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 2 %s", Optional.of(streamUrl).filter((s) -> s.endsWith("_")).map((s) -> s.substring(0, s.length() - 1)).orElse(streamUrl), this.videoBitrate, this.audioBitrate, recordFileName);
|
||||||
logger.info("recordStream {}", command);
|
logger.info("recordStream {}", command);
|
||||||
ProcessBuilder pb = new ProcessBuilder(command.split(" "));
|
ProcessBuilder pb = new ProcessBuilder(command.split(" "));
|
||||||
pb.redirectErrorStream(true);
|
pb.redirectErrorStream(true);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@ ffmpeg=ffmpeg
|
||||||
recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
|
recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
|
||||||
livedates=8
|
livedates=8
|
||||||
cangneiwai=true
|
cangneiwai=true
|
||||||
|
# 录制码率配置 (单位: kbps, 2000k = 2Mbps)
|
||||||
|
video.bitrate=4000k
|
||||||
|
audio.bitrate=128k
|
||||||
|
|
||||||
#本地测试
|
#本地测试
|
||||||
#spring.application.name=stream_server
|
#spring.application.name=stream_server
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue