whycxzp
2021-04-19 3ce5138c7cb230c531c3e0ee43a6e9cb361719a1
src/main/java/com/whyc/video/WsHandler.java
@@ -32,7 +32,7 @@
    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        System.out.println("新的加入");
        //System.out.println("新的加入");
        this.session = session;
        //获取ws请求的参数
@@ -46,7 +46,7 @@
    @Override
    public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
        System.out.println(">>>>>>>>>>终止了连接<<<<<<<<<<");
        //System.out.println(">>>>>>>>>>终止了连接<<<<<<<<<<");
        Optional<String> first = clients.keySet().stream().filter(key -> key.contains(session.getId())).findFirst();
        clients.remove(first.get());
@@ -54,7 +54,7 @@
    @Override
    public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
        System.out.println(">>>>>>>>>>发生错误,终止了连接<<<<<<<<<<");
        //System.out.println(">>>>>>>>>>发生错误,终止了连接<<<<<<<<<<");
        Optional<String> first = clients.keySet().stream().filter(key -> key.contains(session.getId())).findFirst();
        clients.remove(first.get());
    }
@@ -65,19 +65,14 @@
        String ffmpegPath = "F:\\download\\ffmpeg-2021-04-11-git-309e3cc15c-essentials_build\\bin\\ffmpeg.exe ";
        //String ffmpegPath = "";
        try {
            // 视频切换时,先销毁进程,全局变量Process process,方便进程销毁重启,即切换推流视频
            /*if(process != null){
                process.destroy();
                System.out.println(">>>>>>>>>>推流视频切换<<<<<<<<<<");
            }*/
            System.out.println(">>>>>>>>>>推流视频新增<<<<<<<<<<");
            //System.out.println(">>>>>>>>>>推流视频新增<<<<<<<<<<");
            String id = "rtsp://admin:a123456789@"+ip+":554/Streaming/Channels/101";
            // cmd命令拼接,注意命令中存在空格
            String command = ffmpegPath; // ffmpeg位置
            command += "  "; // ffmpeg开头,-re代表按照帧率发送,在推流时必须有
            command += " -i \"" + id + "\""; // 指定要推送的视频
            command += " -q 0 -f mpegts -codec:v mpeg1video -s 800x600 " + fileName; // 指定推送服务器,-f:指定格式
            System.out.println("ffmpeg推流命令:" + command);
            //System.out.println("ffmpeg推流命令:" + command);
            //如果不存在进程,则建立ip对应的视频流进程
            if(!processMap.containsKey(ip)){