javavlcjwebcam-capture

Is webcam detection still supported vlcj-4.7.3


Is webcam detection still supported? The MediaDiscovererTest.java file does not seem to detect any capture devices. (win/mac) It seems to me that the device detection was working with earlier versions of vlcj on MAC webcam-capture driver for vlcj

...
MediaPlayerFactory mediaPlayerFactory = createMediaPlayerFactory();
MediaDiscoverer videoMediaDiscoverer = mediaPlayerFactory.newVideoMediaDiscoverer();
MediaList videoDeviceList = videoMediaDiscoverer.getMediaList();
List<MediaListItem> videoDevices = videoDeviceList.items();
...

VLC is able to detect the capture devices.

Device capture from VLC

Thanks in advance for your help.

#edit1

Using the following code in vlcj-4.7.3 does not seem to return the webcam. But maybe I missed something.

MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
List<MediaDiscovererDescription> videoDevices = mediaPlayerFactory.mediaDiscoverers().discoverers(MediaDiscovererCategory.DEVICES);

#edit 2

When i run this following code;

List<MediaDiscovererDescription> discoverers = factory.mediaDiscoverers().discoverers(MediaDiscovererCategory.DEVICES);

Under Windows 10 I get the following list: (no Video Capture)

[MediaDiscovererDescription[name=disc,longName=Discs,category=DEVICES],
 MediaDiscovererDescription[name=disc,longName=Discs,category=DEVICES]

On MacOs 12.4 I get an empty list...

#edit 3

Capture device detection only works under linux


Solution

  • With vlcj-4.7.x, the API to discover video capture devices looks like this:

    List<MediaDiscovererDescription> discoverers = factory.mediaDiscoverers().discoverers(MediaDiscovererCategory.DEVICES);
    

    When I run that code, I see something like this:

    [DEVICES     ] v4l                  "Video capture"
    [DEVICES     ] disc                 "Discs"
    [DEVICES     ] xcb_apps             "Screen capture"
    [DEVICES     ] mtp                  "MTP devices"
    [DEVICES     ] pulse                "Audio capture"
    

    In this case, on Linux, the discoverer ID is "v4l".

    So now you find the "v4l" discoverer in the list of discoverer descriptions. Once you have that discoverer instance you can invoke methods on it to get the actual capture devices.

    If you know the discoverer ID in advance, which in all (?) cases you will, you can do this instead:

    MediaDiscoverer discoverer = factory.mediaDiscoverers().discoverer("v4l");
    

    You then get the media list from that discoverer and add listeners to that media list.

    Finally you must start() the discoverer.

    The listener will be triggered when a capture device is added/removed (or 'detected').

    MediaList list = discoverer.newMediaList();
    
    list.events().addMediaListEventListener(new MediaListEventAdapter() {
        @Override
        public void mediaListItemAdded(MediaList mediaList, MediaRef item, int index) {
            System.out.println(name + ": added " + item);
        }
    
        @Override
        public void mediaListItemDeleted(MediaList mediaList, MediaRef item, int index) {
            System.out.println(name + ": deleted " + item);
        }
    });
    
    discoverer.start();
    

    The vlcj MediaDiscovererTest class shows all of this.

    The MediaRef instance is the MRL of the capture device, which you can then use to build a menu to select to play one of them or whatever.