2017-03-29 90 views
0

我想做一個簡單的程序,將從我的攝像頭直播流。vlcj在java攝像頭流

public static void main(String[] args) throws Exception 
{ 
    int port = nextAvailable(); 
    //String media = "/root/Desktop/525600.mp4"; 
    String media = "/dev/video0"; 
    String[] options = {":sout=#duplicate{dst=rtp{sdp=rtsp://:"+port+"/stream},dst=display}", ":sout-all", ":sout-keep"}; 
    MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args); 
    HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer(); 
    mediaPlayer.playMedia(media,options); 
    System.out.println("Using port: "+port); 
    Thread.currentThread().join(); 
} 

如果我使用註釋媒體(/root/Desktop/525600.mp4),則該流的工作原理沒有任何問題。但是,我不知道如何從網絡攝像頭進行流式傳輸。我嘗試了/ dev/video0,但它給出了以下錯誤:

[00007fae70008f78] core access error: read error: Invalid argument

[00007fae70008f78] filesystem access error: read error: Invalid argument

[00007fae7000d3d8] core stream error: cannot pre fill buffer

我在做什麼錯?你

+0

請在這篇文章中看看:[Java Video Streaming](http://stackoverflow.com/questions/5574143/stream-video-in-javahttp://) –

+0

我會調查一下Xuggler ......謝謝! – amaiKy

回答

0

簡單地更換

String media = "/dev/video0"; 

String media = "v4l2:///dev/video0"; 

和現在的工作。