Question

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.

Was it helpful?

Solution

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();
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top