欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java调用ffmpeg直播流

程序员文章站 2022-06-15 22:44:28
...
public static void getThumb() throws IOException,
            InterruptedException {

        //ffmpeg -re -i /Users/samson/Desktop/apple-iphone4-design_video-us-20100607_848x480.mov -vcodec copy -f flv rtmp://localhost:1935/live1/room2
        ProcessBuilder processBuilder = new ProcessBuilder("ffmpeg",
                "-re","-i", "/Users/samson/Desktop/apple-iphone4-design_video-us-20100607_848x480.mov",
                "-vcodec", "copy" ,
                "-f", "flv","rtmp://localhost:1935/live1/room2");

        Process process = processBuilder.start();

        InputStream stderr = process.getErrorStream();
        InputStreamReader isr = new InputStreamReader(stderr);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) ;
        process.waitFor();

        if (br != null)
            br.close();
        if (isr != null)
            isr.close();
        if (stderr != null)
            stderr.close();
    }

    public static void main(String[] args) {
        try {
            getThumb();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
相关标签: java ffmpeg