| | |
| | | String processName = "mediamtx.exe"; |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args){ |
| | | public void run(ApplicationArguments args) { |
| | | try { |
| | | log.info("开始加载流媒体列表"); |
| | | List<StreamInfo> paths = paths(); |
| | |
| | | for (Vtdu v : vtduList) { |
| | | addPath(v.getName(), v.getRtspUrl(), v.getCodeType(), v.getIsCode()); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.error("加载流媒体列表异常:"+ex.getMessage()); |
| | | } catch (Exception ex) { |
| | | log.error("加载流媒体列表异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @PostConstruct |
| | | public void initMediaMtx() { |
| | | if (mediamtxEnabled) { |
| | |
| | | public String addPath(String name, String rtspPath, String mode, String isCode) { |
| | | String rtspUrl = "rtsp://" + mediamtxHost + ":7554/" + name; |
| | | Conf mediaInfo = new Conf(); |
| | | String rootPath = System.getProperty("user.dir").replaceAll("\\\\", "/")+ "/lib/mediamtx/"; |
| | | String rootPath = System.getProperty("user.dir").replaceAll("\\\\", "/") + "/lib/mediamtx/"; |
| | | //-vcodec libx264 //指定视频编码器为 libx264,使用 H.264 编码格式进行视频压缩 |
| | | //-preset ultrafast //--preset的参数主要调节编码速度和质量的平衡,有ultrafast(转码速度最快,视频往往也最模糊)、superfast、veryfast、faster、fast、medium、slow、slower、veryslow、placebo这10个选项,从快到慢 |
| | | //-r 25 //设置输出视频的帧率为 25 帧/秒 |
| | | //-g 20 //关键帧间隔20 |
| | | //-sc_threshold 0 //将其设置为0(-sc_threshold 0)禁用场景变化检测 |
| | | //-rtsp_transport tcp //这个选项告诉 FFmpeg 使用 TCP 作为 RTSP 的传输协议 |
| | | //-threads 4: 指定要使用的线程数为 4。//这允许 FFmpeg 在多核处理器上使用多个线程来进行视频编码,以加快速度。 |
| | | // -i //用于指定输入媒体文件或输入流的地址 |
| | |
| | | //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 = "ffmpeg -rtsp_transport tcp -i " + rtspPath + " -vcodec libx264 -preset:v ultrafast -r 25 -g 20 -threads 6 -b:v 2048k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH"; |
| | | String cmd = rootPath + "ffmpeg -rtsp_transport tcp -i " + rtspPath + " -vcodec libx264 -preset:v ultrafast -r 25 -keyint_min 20 -g 20 -sc_threshold 0 -threads 6 -b:v 2048k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH"; |
| | | if (!softwareDecoding) { |
| | | cmd = "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"; |
| | | cmd = rootPath + "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport tcp -i " + rtspPath + " -c:v h264_nvenc -r 25 -g 60 -threads 6 -b:v 2048k -bf 0 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH"; |
| | | } |
| | | if (mode.equals("1")) { |
| | | if (mode.equals("0")) { |
| | | mediaInfo.setRunondemand(cmd); |
| | | mediaInfo.setRunondemandrestart(true); |
| | | } else { |
| | |
| | | String runondemand = item.getConf().getRunondemand(); |
| | | if (StringUtils.isNotEmpty(runondemand)) { |
| | | runoninit = item.getConf().getRunondemand(); |
| | | info.setMode("1"); |
| | | info.setMode("0"); |
| | | } else { |
| | | runoninit = item.getConf().getRunoninit(); |
| | | info.setMode("0"); |
| | | info.setMode("1"); |
| | | } |
| | | //RTSP源地址 |
| | | String regex = "rtsp://[^\\s\"]+"; |
| | |
| | | String runondemand = item.getConf().getRunondemand(); |
| | | if (StringUtils.isNotEmpty(runondemand)) { |
| | | runoninit = item.getConf().getRunondemand(); |
| | | info.setMode("1"); |
| | | info.setMode("0"); |
| | | } else { |
| | | runoninit = item.getConf().getRunoninit(); |
| | | info.setMode("0"); |
| | | info.setMode("1"); |
| | | } |
| | | //RTSP源地址 |
| | | String regex = "rtsp://[^\\s\"]+"; |