Read rtmp live streaming vido data using java code

こ雲淡風輕ζ 提交于 2019-12-11 19:52:42

问题


My requirement is that How to read and create mp4 file from live stream video URL.

I have did many R&D's for this topic but failed to get any answer. Following link also not useful to me. When I run ffmpeg command given in this question, it gives me an exception.

I want to use FFMPEG, not xuggle library

Thanks.


回答1:


Following is the java method which you can use to read data from rtmp url with the integration of FFMPEG library.

   public static void liveRtmpFeed() throws IOException, InterruptedException {
        ProcessBuilder processBuilder = new ProcessBuilder("ffmpeg", "-i",
                "rtmp://192.168.0.90/oflaDemo/livestream", "-ss", "00:00:00",
                "-t", "00:00:10", "-c", "copy", "/home/outputVideo.mp4");
        Process process = processBuilder.start();
        InputStream stderr = process.getErrorStream();
        InputStreamReader isr = new InputStreamReader(stderr);
        BufferedReader br = new BufferedReader(isr);
        while ((br.readLine()) != null)
            ;
        process.waitFor();

        try {
            process.destroy();
            isr.close();
            stderr.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


来源:https://stackoverflow.com/questions/22909434/read-rtmp-live-streaming-vido-data-using-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!