whycxzp
2021-04-15 e4e8380597b5abdd2ede656cf5291c5d760b1149
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//package com.whyc.video;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.ApplicationArguments;
//import org.springframework.boot.ApplicationRunner;
//import org.springframework.stereotype.Component;
//
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//
//@Component
//public class ConvertVideoPakcet implements ApplicationRunner {
//
//    public Process process;
//
//    public Integer pushVideoAsRTSP(String id, String fileName){
//        int flag = -1;
//        // ffmpeg位置,最好写在配置文件中
//        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(">>>>>>>>>>推流视频切换<<<<<<<<<<");
//            }
//            // 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);
//
//            // 运行cmd命令,获取其进程
//            process = Runtime.getRuntime().exec(command);
//            // 输出ffmpeg推流日志
//            BufferedReader br= new BufferedReader(new InputStreamReader(process.getErrorStream()));
//            String line = "";
//            while ((line = br.readLine()) != null) {
//                System.out.println("视频推流信息[" + line + "]");
//            }
//            flag = process.waitFor();
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        return flag;
//    }
//
//    @Override
//    public void run(ApplicationArguments args) throws Exception {
//        ConvertVideoPakcet convertVideoPakcet = new ConvertVideoPakcet();
//        convertVideoPakcet.pushVideoAsRTSP("rtsp://admin:a123456789@192.168.10.3:554/Streaming/Channels/101", "http://127.0.0.1:8090/rtsp/receive");
//
//    }
//}