| | |
| | | **/ |
| | | @Service |
| | | @Slf4j(topic = "cmd") |
| | | @Order(1) |
| | | @Order(2) |
| | | public class MediaServiceImpl implements IMediaService, ApplicationRunner { |
| | | @Resource |
| | | VtduMapper vtduMapper; |
| | | @Resource |
| | | MediaClient mediaClient; |
| | | |
| | | @Value("${mediamtx.host}") |
| | | String mediamtxHost; |
| | | @Value("${mediamtx.enabled}") |
| | |
| | | |
| | | String processName = "mediamtx.exe"; |
| | | |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) throws Exception { |
| | | log.info("开始加载流媒体列表"); |
| | | List<StreamInfo> paths = paths(); |
| | | for(StreamInfo path:paths) |
| | | { |
| | | mediaClient.removePath(path.getName()); |
| | | public void run(ApplicationArguments args){ |
| | | try { |
| | | log.info("开始加载流媒体列表"); |
| | | List<StreamInfo> paths = paths(); |
| | | for (StreamInfo path : paths) { |
| | | mediaClient.removePath(path.getName()); |
| | | } |
| | | List<Vtdu> vtduList = vtduMapper.selectVtduList(new Vtdu()); |
| | | for (Vtdu v : vtduList) { |
| | | addPath(v.getName(), v.getRtspUrl(), v.getCodeType(), v.getIsCode()); |
| | | } |
| | | } |
| | | List<Vtdu> vtduList = vtduMapper.selectVtduList(new Vtdu()); |
| | | for (Vtdu v : vtduList) { |
| | | addPath(v.getName(), v.getRtspUrl(), v.getCodeType(), v.getIsCode()); |
| | | catch (Exception ex) |
| | | { |
| | | log.error("加载流媒体列表异常:"+ex.getMessage()); |
| | | } |
| | | } |
| | | @PostConstruct |
| | |
| | | //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 -threads 6 -b:v 1024k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH"; |
| | | 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"; |
| | | 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"; |
| | | } |