Skip to content
Advertisement

How to run VLC stream on Linux server using Java code?

I am trying to run vlc stream from my Java code on Debian server. Simple commands as given in the example below works fine both from java code as well as terminal.

String cmd = "/Applications/ video.avi"
Process p = Runtime.getRuntime().exec(cmd);

But I try to run more advanced command with multiple options”

vlc -vvv http://umevakameran.net.umea.se/mjpg/video.mjpg --no-audio --sout '#transcode{vcodec=MJPG,venc=ffmpeg{strict=1}}:standard{access=http{mime=image/jpeg},mux=mpjpeg,dst=xxxxx:25000}'

This is my main class:

NewCamera obj = new NewCamera();
...
String mobile_command = "vlc -d -vvv " + camera.getUrl() + 
" --no-audio --sout"
+ " '#transcode{vcodec=MJPG,venc=ffmpeg{strict=1}}:"
+ "standard{access=http{mime=image/jpeg},mux=mpjpeg,dst="
+ camera.getServerName() + ":"
+ camera.getMobilePort() + "}'";

obj.executeCommand(mobile_command);
logger.info("New mobile stream started");

and this is class for executing shell commands:

    private String executeCommand(String command) {

    StringBuffer output = new StringBuffer();

    Process p;
    try {
        p = Runtime.getRuntime().exec(command);
        logger.info(command);
        p.waitFor();
        BufferedReader reader = 
                        new BufferedReader(new InputStreamReader(p.getInputStream()));

                    String line = "";           
        while ((line = reader.readLine())!= null) {
            output.append(line + "n");

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    logger.info(output.toString());
    return output.toString();

}

Process in Linux is created, but the stream is I will say “offline”, because I cannot connect and get it. Executing the same command directly from command line in Linux works and creates stream.

Any ideas?

Advertisement

Answer

You should use VLCJ instead of calling vlc by shell.

http://www.capricasoftware.co.uk/projects/vlcj/faq.html

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement