From 516c3afd526c8e02db75e9115f4412b57296cc8a Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期二, 26 九月 2023 17:12:55 +0800
Subject: [PATCH] 流媒体增加音频转码 流媒体适配mediaMTX新版本1.1.1
---
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java | 11 +++++++----
ard-work/src/main/java/com/ruoyi/device/hiksdk/controller/SdkController.java | 2 +-
ard-work/src/main/resources/templates/preview.html | 13 +++++++------
3 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/controller/SdkController.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/controller/SdkController.java
index fcc65a1..1d8ad07 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/controller/SdkController.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/controller/SdkController.java
@@ -65,7 +65,7 @@
}
@RequestMapping("/media")
private String media() {
- return "mediaMTX";
+ return "preview2";
}
@GetMapping("/list")
public @ResponseBody
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
index da32835..a66c1a8 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
@@ -71,7 +71,7 @@
@Override
public Map<String,String> addPath(String name, String sourceUrl, String mode, String isCode) {
- String rtspUrl = "rtsp://" + mediamtxHost + ":7554/" + name;
+ String rtspUrl = "rtsp://" + mediamtxHost + ":8554/" + name;
String rtmpUrl = "rtmp://" + mediamtxHost + ":1935/" + name;
String webrtcUrl = "http://" + mediamtxHost + ":8889/" + name;
@@ -87,14 +87,17 @@
// -i //鐢ㄤ簬鎸囧畾杈撳叆濯掍綋鏂囦欢鎴栬緭鍏ユ祦鐨勫湴鍧�
// -bf 0 绂佺敤B甯э紝鍥犱负webrtc鍦ㄧ綉椤佃皟鐢ㄦ椂鎺у埗鍙颁竴鐩磋緭鍑� WebRTC doesn鈥檛 support H264 streams with B-frames
//-f rtsp //杩欎釜閫夐」鍛婅瘔 FFmpeg 杈撳嚭涓� RTSP 鏍煎紡銆�
+ //-acodec opus //闊抽杞爜opus
+ //-acodec pcm_alaw //闊抽杞爜PCMA(G711A)
+ //-strict 閫夐」鐢ㄤ簬璁剧疆闊抽缂栬В鐮佺殑涓ユ牸绾у埆锛岃�� -2 鏄叾鍙傛暟涔嬩竴銆傚湪鏃╂湡鐗堟湰鐨� FFmpeg 涓紝-strict 閫夐」鐢ㄤ簬璁剧疆闊抽缂栬В鐮佸櫒鐨勮涓猴紝鍏朵腑 -2 琛ㄧず浣跨敤闈炲父涓ユ牸鐨勬ā寮忋��
//CPU杞В鐮佺紪鐮�
//String cmd = rootPath + "/lib/mediamtx/" +"ffmpeg -rtsp_transport tcp -i " + rtspPath + " -vcodec libx264 -preset:v ultrafast -r 25 -threads 4 -b:v 2048k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
//GPU纭В鐮佺紪鐮� -hwaccel cuvid -c:v h264_cuvid 浣跨敤cuda瑙g爜 -c:v h264_nvenc 浣跨敤cuda缂栫爜
//String cmd = rootPath + "/lib/mediamtx/" + "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport udp -i " + rtspPath + " -c:v h264_nvenc -r 25 -threads 4 -b:v 2048k -bf 0 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
if (isCode.equals("1")) {
- String cmd = "ffmpeg -rtsp_transport tcp -i " + sourceUrl + " -vcodec libx264 -preset:v ultrafast -r 25 -keyint_min 25 -g 25 -sc_threshold 0 -threads 6 -b:v 2048k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
+ String cmd = "ffmpeg -rtsp_transport tcp -i " + sourceUrl + " -vcodec libx264 -preset:v ultrafast -r 25 -keyint_min 25 -g 25 -sc_threshold 0 -threads 6 -b:v 2048k -acodec pcm_alaw -strict -2 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
if (!softwareDecoding) {
- cmd = "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport tcp -i " + sourceUrl + " -c:v h264_nvenc -r 25 -g 60 -threads 6 -b:v 2048k -bf 0 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
+ cmd = "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport tcp -i " + sourceUrl + " -c:v h264_nvenc -r 25 -g 60 -threads 6 -b:v 2048k -bf 0 -acodec opus -strict -2 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
}
if (mode.equals("0")) {
mediaInfo.setRunondemand(cmd);
@@ -120,7 +123,7 @@
@Override
public Map<String, String> editPath(String name, String sourceUrl, String mode, String isCode) {
- String rtspUrl = "rtsp://" + mediamtxHost + ":7554/" + name;
+ String rtspUrl = "rtsp://" + mediamtxHost + ":8554/" + name;
String rtmpUrl = "rtmp://" + mediamtxHost + ":1935/" + name;
String webrtcUrl = "http://" + mediamtxHost + ":8889/" + name;
diff --git a/ard-work/src/main/resources/templates/preview.html b/ard-work/src/main/resources/templates/preview.html
index a115bf1..ee775ac 100644
--- a/ard-work/src/main/resources/templates/preview.html
+++ b/ard-work/src/main/resources/templates/preview.html
@@ -174,9 +174,9 @@
}
class WHEPClient {
- constructor(wurl, videoId) {
+ constructor(whepUrl, videoId) {
this.video = videoId;
- this.url = new URL('whep', wurl);
+ this.wurl = new URL('whep', whepUrl);
this.pc = null;
this.restartTimeout = null;
this.eTag = '';
@@ -186,7 +186,7 @@
start() {
console.log("requesting ICE servers");
- fetch(this.url, {
+ fetch(this.wurl, {
method: 'OPTIONS',
})
.then((res) => this.onIceServers(res))
@@ -223,7 +223,7 @@
console.log("sending offer");
- fetch(this.url, {
+ fetch(this.wurl, {
method: 'POST',
headers: {
'Content-Type': 'application/sdp',
@@ -234,7 +234,8 @@
if (res.status !== 201) {
throw new Error('bad status code');
}
- this.eTag = res.headers.get('E-Tag');
+ // this.eTag = res.headers.get('ETag');
+ this.eTag = res.headers.get("ETag") || res.headers.get('E-Tag');
return res.text();
})
.then((sdp) => this.onRemoteAnswer(new RTCSessionDescription({
@@ -288,7 +289,7 @@
}
sendLocalCandidates(candidates) {
- fetch(this.url, {
+ fetch(this.wurl, {
method: 'PATCH',
headers: {
'Content-Type': 'application/trickle-ice-sdpfrag',
--
Gitblit v1.9.3