From 07b70ab819d5ac3ff934ff35d7045e8efe98ee01 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: Tue, 26 Sep 2023 11:16:06 +0800
Subject: [PATCH] 流媒体转码增加音频
---
ard-work/src/main/resources/templates/test.html | 1 +
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java | 5 +++--
2 files changed, 4 insertions(+), 2 deletions(-)
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 676071c..da32835 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
@@ -136,15 +136,16 @@
// -i //用于指定输入媒体文件或输入流的地址
// -bf 0 禁用B帧,因为webrtc在网页调用时控制台一直输出 WebRTC doesn’t support H264 streams with B-frames
//-f rtsp //这个选项告诉 FFmpeg 输出为 RTSP 格式。
+ //-acodec opus //音频转码opus
//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解码 -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")) {
mediaInfo.setSource("publisher");
- 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 opus -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 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
}
if (mode.equals("0")) {
mediaInfo.setRunondemand(cmd);
diff --git a/ard-work/src/main/resources/templates/test.html b/ard-work/src/main/resources/templates/test.html
index 25ea102..5b3d7d9 100644
--- a/ard-work/src/main/resources/templates/test.html
+++ b/ard-work/src/main/resources/templates/test.html
@@ -134,6 +134,7 @@
var cameraId, opt, optOpen, optClose, token;
window.onload = function () {
+ console.log(RTCRtpReceiver.getCapabilities('video').codecs)
$.ajax({
url: "../hik/list",
type: "get",
--
Gitblit v1.9.3