aijinhui
2023-08-31 6e54b432ab969eccb47b0aa388b95bf14e398790
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
@@ -48,6 +48,9 @@
    String processName = "mediamtx.exe";
    static{
    }
    @PostConstruct
    public void initMediaMtx() {
        if (mediamtxEnabled) {
@@ -68,6 +71,11 @@
//            String[] command = {"cmd","/c","start",exePath,ymlPath};
//            CmdUtils.commandStart(command);
            }
        }
        try {
            Thread.sleep(2000); // 等待5秒
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        List<StreamInfo> paths = paths();
        for(StreamInfo path:paths)
@@ -109,9 +117,9 @@
        //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")) {
            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";
            String cmd = rootPath + "/lib/mediamtx/" + "ffmpeg -rtsp_transport tcp -i " + rtspPath + " -vcodec libx264 -preset:v ultrafast -r 25 -threads 6  -b:v 1024k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
            if (!softwareDecoding) {
                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";
                cmd = rootPath + "/lib/mediamtx/" + "ffmpeg -hwaccel cuvid -c:v h264_cuvid  -rtsp_transport tcp  -i " + rtspPath + " -c:v h264_nvenc  -r 25 -threads 6  -b:v 2048k -bf 0 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
            }
            if (mode.equals("1")) {
                mediaInfo.setRunondemand(cmd);
@@ -123,7 +131,7 @@
        } else {
            mediaInfo.setSource(rtspPath);
        }
        mediaInfo.setSourceprotocol("udp");
        mediaInfo.setSourceprotocol("tcp");
        mediaClient.addPath(name, mediaInfo);
        return rtspUrl;
    }
@@ -141,7 +149,7 @@
            info.setMode("1");
        } else {
            runoninit = item.getConf().getRunoninit();
            info.setMode("2");
            info.setMode("0");
        }
        //RTSP源地址
        String regex = "rtsp://[^\\s\"]+";