Skip to content

Commit

Permalink
Update vlcj capture driver
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed May 22, 2014
1 parent e815620 commit dc33350
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 101 deletions.
28 changes: 15 additions & 13 deletions webcam-capture-drivers/driver-vlcj/README.md
@@ -1,24 +1,26 @@
# webcam-capture-driver-vlcj

This capture driver use [vlcj](http://caprica.github.io/vlcj/) as a
underlying capturing framework.

This driver should not be used when you need good performance and high
FPS rate. Because vlcj save each image to the file prior it's returned
by the API, the FPS rate is pretty small. In my case (HP Elitebook 8460p,
quad core, 4 GB RAM, fast SSD disk) it was about ~12 FPS, which is very
low when you compare it to the other capture drivers (e.g.
[gstreamer capture driver](https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-drivers/webcam-capture-driver-gstreamer) or
[openimaj capture driver](https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-drivers/webcam-capture-driver-openimaj), where both can easily
stream 30 FPS).
This is capture driver which uses [vlcj](http://www.capricasoftware.co.uk/projects/vlcj/index.html)
library from [Caprica Software Limited](http://www.capricasoftware.co.uk/)
to gain access to the camera device.

**NOTE!** This capture driver **does not** work on Windows.

Because vlcj saves every frame to the persistent storage (temporary directory on your hard drive)
before it is returned by the API method call,
the image capture rate is pretty small, indicated by tests to be around ~12 FPS, but it can pe
possibly higher or lower depending on the hardware used (e.g. different on hard drive, SSD and
flash memory).

The vlcj library is distributed according to the terms of the [GPL](http://www.gnu.org/licenses/gpl.html) license.

## Maven

Not yet available.

## License
## Capture Driver License

Copyright (C) 2012 - 2013 Bartosz Firyn <https://github.com/sarxos>
Copyright (C) 2012 - 2014 Bartosz Firyn <https://github.com/sarxos>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
38 changes: 34 additions & 4 deletions webcam-capture-drivers/driver-vlcj/pom.xml
Expand Up @@ -9,16 +9,22 @@
</parent>

<artifactId>webcam-capture-driver-vlcj</artifactId>
<packaging>jar</packaging>
<packaging>bundle</packaging>

<name>Webcam Capture - VLCj Driver</name>
<description>Webcam Capture driver using VLCj framework to grab frames from camera</description>
<description>Webcam Capture driver using VLCj framework to grab frames from camera device</description>

<dependencies>
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>com.nativelibs4java</groupId>
<artifactId>bridj</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>uk.co.caprica</groupId>
Expand All @@ -33,7 +39,31 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-DocURL>${project.url}</Bundle-DocURL>
<Import-Package>
*,
</Import-Package>
<Export-Package>
com.github.sarxos.webcam.ds.vlcj*,
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

</project>

This file was deleted.

Expand Up @@ -20,11 +20,11 @@ public static void main(String[] args) throws InterruptedException {
WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);

JFrame window = new JFrame("Webcam Panel using VLCj");
JFrame window = new JFrame("Webcam Panel");
window.add(panel);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
}
}
}
Expand Up @@ -224,64 +224,75 @@ public synchronized void open() {

LOG.info("Opening webcam device");

factory = new MediaPlayerFactory(VLC_ARGS);
player = factory.newHeadlessMediaPlayer();
try {

factory = getFactory();
player = factory.newHeadlessMediaPlayer();

// for nix systems this should be changed dshow -> ... !!

String[] options = null;

switch (OS.getOS()) {
case WIN:
options = new String[] {
":dshow-vdev=" + getName(),
":dshow-size=" + size.width + "x" + size.height,
":dshow-adev=none", // no audio device
};
break;
case NIX:
options = new String[] {
":v4l-vdev=" + getVDevice(),
":v4l-width=" + size.width,
":v4l-height=" + size.height,
":v4l-fps=30",
":v4l-quality=20",
":v4l-adev=none", // no audio device
};
break;
case OSX:
options = new String[] {
":qtcapture-vdev=" + getVDevice(),
":qtcapture-width=" + size.width,
":qtcapture-height=" + size.height,
":qtcapture-adev=none", // no audio device
};
break;
}

// for nix systems this should be changed dshow -> ... !!
player.startMedia(getMRL(), options);

String[] options = null;
// wait for images

switch (OS.getOS()) {
case WIN:
options = new String[] {
":dshow-vdev=" + getName(),
":dshow-size=" + size.width + "x" + size.height,
":dshow-adev=none", // no audio device
};
break;
case NIX:
options = new String[] {
":v4l-vdev=" + getVDevice(),
":v4l-width=" + size.width,
":v4l-height=" + size.height,
":v4l-fps=30",
":v4l-quality=20",
":v4l-adev=none", // no audio device
};
break;
case OSX:
options = new String[] {
":qtcapture-vdev=" + getVDevice(),
":qtcapture-width=" + size.width,
":qtcapture-height=" + size.height,
":qtcapture-adev=none", // no audio device
};
break;
}
int max = 0;
do {

player.startMedia(getMRL(), options);
BufferedImage im = player.getSnapshot(size.width, size.height);
if (im != null && im.getWidth() > 0) {
open = true;
LOG.info("Webcam device is now open: " + getName());
return;
}

// wait for images
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
return;
}

int max = 0;
do {
} while (max++ < 10);

BufferedImage im = player.getSnapshot(size.width, size.height);
if (im != null && im.getWidth() > 0) {
open = true;
LOG.info("Webcam device is now open: " + getName());
return;
}
} finally {

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
if (player != null) {
player.release();
}

} while (max++ < 10);

player.release();
factory.release();
if (factory != null) {
factory.release();
}
}

open = false;
}
Expand Down Expand Up @@ -316,6 +327,9 @@ public MediaPlayer getPlayer() {
}

public MediaPlayerFactory getFactory() {
if (factory == null) {
factory = new MediaPlayerFactory(VLC_ARGS);
}
return factory;
}
}
Expand Up @@ -11,29 +11,19 @@
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

import com.github.sarxos.webcam.WebcamDevice;
import com.github.sarxos.webcam.WebcamDiscoverySupport;
import com.github.sarxos.webcam.WebcamDriver;
import com.sun.jna.Native;


/**
* NOT STABLE, EXPERIMENTAL STUFF!!!
*
* Vlcj service discovery works only on Linux, so there is no way (at least for
* now) to list capture devices on Windows.
*
* For Windows dsj library could be used (http://www.humatic.de/htools/dsj.htm)
* listing DirectShow filters for all capture devices in system.
*
* There is service discovery for Linux, but in any case this one could be used
* (http://code.google.com/p/v4l4j/) to access the Video4Linux devices.
*
* MAC OS X can reuse Rococoa (http://code.google.com/p/rococoa/), a Java
* binding to the Mac Objective-C object system, could read device details via
* the Mac's QTKit library.
* This is capture driver which uses <code>vlcj</code> library to gain access to
* the camera device.
*
* @author Bartosz Firyn (SarXos)
* @see http://www.capricasoftware.co.uk/projects/vlcj/index.html
*/
public class VlcjDriver implements WebcamDriver {
public class VlcjDriver implements WebcamDriver, WebcamDiscoverySupport {

static {
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
Expand Down Expand Up @@ -75,4 +65,14 @@ public boolean isThreadSafe() {
public String toString() {
return getClass().getSimpleName();
}

@Override
public long getScanInterval() {
return 3000;
}

@Override
public boolean isScanPossible() {
return true;
}
}

0 comments on commit dc33350

Please sign in to comment.