سؤال

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?

هل كانت مفيدة؟

المحلول

You should use VLCJ instead of calling vlc by shell.

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

نصائح أخرى

I changed approach:

vlc -d -vvv http://camera_ip/mjpg/video.mjpg --no-audio --sout '#transcode{vcodec=MJPG,venc=ffmpeg{strict=1}}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=server_name:port}' &

with this it works fine. Also I changed approach to run shell scripts. Now I use Process Builder instead of simple Process.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top