Created
August 10, 2011 03:22
-
-
Save oravecz/1136038 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.tracermedia.gcf1001.webcam; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import uk.co.caprica.vlcj.player.MediaPlayer; | |
| import uk.co.caprica.vlcj.player.MediaPlayerFactory; | |
| import uk.co.caprica.vlcj.player.events.VideoOutputEventListener; | |
| import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer; | |
| public class WebcamCaptureTest { | |
| private static final Logger LOG = LoggerFactory.getLogger(WebcamCaptureTest.class); | |
| public static void main(final String[] args) throws InterruptedException { | |
| if (args.length != 1) { | |
| System.out.println("Specify a capture device MRL, for example \"v4l2:///dev/video0\" or \"dshow://\""); | |
| System.exit(1); | |
| } | |
| MediaPlayerFactory factory = new MediaPlayerFactory("--no-video-title-show"); | |
| HeadlessMediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer(); | |
| mediaPlayer.addVideoOutputEventListener(new VideoOutputEventListener() { | |
| public void videoOutputAvailable(MediaPlayer mediaPlayer, boolean videoOutput) { | |
| if (videoOutput) { | |
| for (int i = 3; i >= 0; i--) { | |
| LOG.info("Taking snapshot {}", i == 0 ? "now!" : "in " + i); | |
| try { | |
| Thread.sleep(1000); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| mediaPlayer.saveSnapshot(); | |
| } else { | |
| LOG.error("Failed to achieve video frame grab."); | |
| } | |
| } | |
| }); | |
| String[] options = { | |
| "--no-video-title-show", | |
| "--no-audio" | |
| }; | |
| mediaPlayer.playMedia(args[0], options); | |
| try { | |
| Thread.currentThread().join(); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| mediaPlayer.release(); | |
| factory.release(); | |
| LOG.info("Cleaned up"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment