package com.sptg.video.cloud.api.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author zwx
 * @create 2020/10/27 21:35
 */
public class RtspPlayDemo {

    public Integer pushVideoAsRTSP(String rtspUrl, String nginxRtmpUrl){

        int flag = -1;
        try {
            // ffmpeg 已经在系统环境
            String command = "ffmpeg rtsp_transport tcp";
            command += " -i \"" + rtspUrl + "\"";
//        command += " -vcodec -acodec copy -f flv -s 800x600 " + nginxRtmpUrl;
            command += " -vcodec h264 -acodec -f flv " + nginxRtmpUrl;
            System.out.println("ffmpeg推流命令：" + command);

            Process process = Runtime.getRuntime().exec(command);
            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;
    }
}
