2014-01-14 45 views
0

我想从Debian服务器上的Java代码运行vlc流。 下面的示例中给出的简单命令在Java代码以及终端都可以正常工作。如何使用Java代码在Linux服务器上运行VLC流?

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

但我尝试使用多个选项”

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}' 

这是我的主类运行更高级的命令:

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"); 

,这是类执行shell命令:

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被创建,但流是我会说“离线”,因为我无法连接并获得它。在Linux中直接从命令行执行相同的命令并创建流。

任何想法?

+0

p.waitFor()调用将会阻塞。你以后只消费流*,所以我不认为这是你想象的那样。我建议你在这里寻找一个可靠的解决方案:http://commons.apache.org/exec/ – caprica

回答

0

我改变做法:

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}' & 

这个它工作正常。我还改变了运行shell脚本的方法。现在我用Process Builder而不是简单的Process

相关问题