[*] 服务端录像

This commit is contained in:
acgist
2023-06-07 08:39:34 +08:00
parent 704e0383a1
commit b64d38a5e9
5 changed files with 88 additions and 83 deletions

View File

@@ -42,7 +42,8 @@
|:--|:--|:--|:--|
|Mediasoup|支持|完成|视频房间(会议)|
|控制|支持|完成|部分控制信令|
|录像|支持|完成|录像|
|拍照|支持|完成|拍照|
|录像|支持|未完成|录像|
### Android终端功能

View File

@@ -816,7 +816,7 @@ class Taoyao {
await audioTransport.connect({
ip : host,
port : audioPort,
rtcpPort: audioPort
rtcpPort: audioPort + 1
});
audioConsumer = await audioTransport.consume({
producerId: audioProducerId,
@@ -847,7 +847,7 @@ class Taoyao {
await videoTransport.connect({
ip : host,
port : videoPort,
rtcpPort: videoPort
rtcpPort: videoPort + 1
});
videoConsumer = await videoTransport.consume({
producerId: videoProducerId,
@@ -865,11 +865,12 @@ class Taoyao {
});
console.log("controlServerRecord video", videoTransportId, videoConsumerId, videoTransport.tuple, videoRtpParameters);
}
if(audioConsumer) {
await audioConsumer.resume();
}
if(videoConsumer) {
await videoConsumer.resume();
videoConsumer.requestKeyFrame();
}
if(audioConsumer) {
await audioConsumer.resume();
}
message.body = {
roomId : roomId,

View File

@@ -1,4 +1,14 @@
server:
# 使用反向代理建议不要配置HTTPS
ssl:
key-alias: taoyao
key-store: classpath:server.p12
key-store-type: PKCS12
key-store-password: 123456
key-password: 123456
taoyao:
ffmpeg:
host: 192.168.8.93
security:
permit:
- /
@@ -7,4 +17,5 @@ taoyao:
- /favicon.ico
- /v3/api-docs/**
- /swagger-ui/**
- /swagger-ui.html
- /swagger-ui.html

View File

@@ -2,12 +2,6 @@ server:
port: 8888
http2:
enabled: true
ssl:
key-alias: taoyao
key-store: classpath:server.p12
key-store-type: PKCS12
key-store-password: 123456
key-password: 123456
tomcat:
thread:
max: 256
@@ -17,9 +11,6 @@ server:
port-header: X-Forwarded-Port
protocol-header: X-Forwarded-Proto
remote-ip-header: X-Forwarded-For
# 服务前缀
# servlet:
# context-path: /taoyao
spring:
# 快速启动
# main:
@@ -58,11 +49,10 @@ taoyao:
description: 桃夭WebRTC信令服务
# 全局超时时间
timeout: 5000
# ID生成策略
id:
# 服务端
max-index: 999999
server-index: 0
# 终端
min-client-index: 10000
max-client-index: 99999
# 媒体配置
@@ -103,6 +93,7 @@ taoyao:
bitrate: 1200
frame-rate: 24
resolution: 1920*1080
# 音频质量
audios:
# 超清
fd-audio:
@@ -115,13 +106,14 @@ taoyao:
format: OPUS
bitrate: 128
sample-size: 24
sample-rate: 44100
sample-rate: 32000
# 标清
sd-audio:
format: OPUS
bitrate: 96
sample-size: 24
sample-rate: 32000
sample-rate: 16000
# 视频质量
videos:
# 4KUD=UHD=4K
ud-video:
@@ -153,6 +145,44 @@ taoyao:
bitrate: 800
frame-rate: 15
resolution: 720*480
# FFmpeg配置
ffmpeg:
# 录像SDPVP8 | H264
sdp: |
v=0
o=- 0 0 IN IP4 127.0.0.1
s=TaoyaoRecord
t=0 0
a=group:BUNDLE video audio
m=video %d RTP/AVP 101 102
c=IN IP4 0.0.0.0
a=rtpmap:101 VP8/90000
a=recvonly
m=audio %d RTP/AVP 100
c=IN IP4 0.0.0.0
a=rtpmap:100 OPUS/48000/2
a=recvonly
# 录像命令
record: ffmpeg -protocol_whitelist "file,rtp,udp" -y -thread_queue_size 1024 -i %s -c:a aac -c:v h264 %s
# 预览命令
preview: ffmpeg -y -i %s -ss %d -vframes 1 -f image2 %s
# 时长命令
duration: ffprobe -i %s -show_entries format=duration
# 存储目录
storage-path: /data/taoyao/storage
# 图片存储目录
storage-image-path: /data/taoyao/storage/image
# 视频存储目录
storage-video-path: /data/taoyao/storage/video
# 预览时间
preview-time: 4
# 时长提取
duration-regex: .*duration\=([0-9\.]+).*
# 录像地址
host: 127.0.0.1
# 端口范围
min-port: 50000
max-port: 59999
# Socket信令
socket:
enabled: true
@@ -168,16 +198,19 @@ taoyao:
keep-alive-time: 60000
buffer-size: 2048
max-buffer-size: 32768
# 脚本配置
script:
enabled: true
system-reboot: reboot
system-shutdown: shutdown now
platform-reboot: systemctl restart taoyao-signal-server
platform-shutdown: systemctl stop taoyao-signal-server
# WebRTC配置
webrtc:
# 是否加密E2E
encrypt: false
# STUN服务
stun:
# - host: 192.168.1.110
# port: 3478
# - host: 192.168.8.110
# port: 3478
- host: stun1.l.google.com
port: 19302
- host: stun2.l.google.com
@@ -217,54 +250,14 @@ taoyao:
ip-rewrite:
enabled: true
prefix: 24
# 重写规则
rule:
- network: 192.168.1.0
inner-host:
outer-host:
- network: 192.168.8.0
inner-host:
outer-host:
ffmpeg:
# SDPVP8 | H264
sdp: |
v=0
o=- 0 0 IN IP4 127.0.0.1
s=TaoyaoRecord
t=0 0
m=audio %d RTP/AVP 100
c=IN IP4 127.0.0.1
a=rtpmap:100 OPUS/48000/2
a=fmtp:100 sprop-stereo=1
m=video %d RTP/AVP 101
c=IN IP4 127.0.0.1
a=rtpmap:101 VP8/90000
# a=fmtp:101 packetization-mode=1
# 录像命令
record: ffmpeg -protocol_whitelist "file,rtp,udp" -y -i %s %s
# 预览命令
preview: ffmpeg -y -i %s -ss %d -vframes 1 -f image2 %s
# 时长命令
duration: ffprobe -i %s -show_entries format=duration
# 存储目录
storage-path: /data/taoyao/storage
# 图片存储目录
storage-image-path: /data/taoyao/storage/image
# 视频存储目录
storage-video-path: /data/taoyao/storage/video
# 预览时间
preview-time: 4
# 时长提取
duration-regex: .*duration\=([0-9\.]+).*
# 录像地址
#host: 127.0.0.1
host: 192.168.8.40
# 端口范围
min-port: 50000
max-port: 59999
# 脚本配置
script:
enabled: true
system-reboot: reboot
system-shutdown: shutdown now
platform-reboot: systemctl restart taoyao-signal-server
platform-shutdown: systemctl stop taoyao-signal-server
# - network: 192.168.1.0
# inner-host:
# outer-host:
# - network: 192.168.8.0
# inner-host:
# outer-host:
# 服务前缀
# servlet:
# context-path: /taoyao

View File

@@ -159,7 +159,7 @@ public class Recorder {
this.thread.setDaemon(true);
this.thread.setName("TaoyaoRecord");
this.thread.start();
log.info("开始录像:{}", this.folder);
log.info("开始媒体录像:{}", this.folder);
}
/**
@@ -186,16 +186,15 @@ public class Recorder {
*/
private void buildSdpfile() {
try {
this.audioPort = NetUtils.scanPort(this.ffmpegProperties.getMinPort(), this.ffmpegProperties.getMaxPort());
int minPort = this.ffmpegProperties.getMinPort();
int maxPort = this.ffmpegProperties.getMaxPort();
// 预留控制端口
this.videoPort = NetUtils.scanPort(this.audioPort + 16, this.ffmpegProperties.getMaxPort());
this.audioPort = NetUtils.scanPort(minPort, maxPort);
this.videoPort = NetUtils.scanPort(this.audioPort + 2, maxPort);
final String sdp = String.format(
this.ffmpegProperties.getSdp(),
// this.ffmpegProperties.getHost(),
this.audioPort,
// this.ffmpegProperties.getHost(),
this.videoPort
// this.ffmpegProperties.getHost()
this.videoPort,
this.audioPort
);
Files.write(
Paths.get(this.sdpfile),
@@ -255,7 +254,7 @@ public class Recorder {
if(this.scriptExecutor == null) {
return;
}
log.debug("结束媒体录像:{}", this.folder);
log.info("结束媒体录像:{}", this.folder);
this.scriptExecutor.stop("q");
this.preview();
this.duration();