java 中的 vlcj 网络摄像头流

vlcj webcam stream in 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

我做错了什么?

也可以参考这个:-

https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-examples/webcam-capture-live-streaming

简单替换

String media = "/dev/video0";

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

现在可以使用了。