JxCapture osx camera issue

245 Views Asked by At

background:

I've am doing an Artificial intelligence project on activity recognition that requires me to use a camera and it has to be in Java. It has to be the built camera as well in because I don't own a webcam. When trying to use the Camera in Java using JxCapture I keep getting the same (thankfully not so cryptic) error listed below near the bottom. The error seems to be suggesting that Java, or at-least this library and some others cannot pick up my built in camera feed. I noted this as JMF also had a similar issue where it couldn't detect the camera.

import com.teamdev.jxcapture.Codec;
import com.teamdev.jxcapture.EncodingParameters;
import com.teamdev.jxcapture.VideoCapture;
import com.teamdev.jxcapture.video.VideoFormat;
import com.teamdev.jxcapture.video.VideoSource;

import java.io.File;
import java.util.List;

/*
 * This example demonstrates the video capture from web camera.
 * <pre>
 * Platforms:           
 * Image source:        WebCamera
 * Output video format: 
 * Output file:         
 *
 * @author Serge Piletsky
 */
public class TemplateRun 
{
    public static void main(String[] args) throws Exception 
    {
        VideoCapture videoCapture = VideoCapture.create(VideoFormat.WMV); 
        // This is where things go south. 
        Thread.sleep(1000);
        ....
    }
}

Research:

I've done my fair share of research on the issue. Some have suggested work arounds like using one of the Windows operating systems, screen recording photo-booth or facetime running, ect.., but none really actually answered the question itself. I haven't yet attempted OpenCV/JavaCV because I didn't want to waste another entrenching amount time to get the same issue. The code also compiles and runs (except for the error), and even is able to get to the variables, so the libraries are working per se. Is it an issue with some framework in Java/OSX? are there ways to fix this? is there a nice modern work around?

482 [main] ERROR com.teamdev.jxcapture.VideoCapture - No compatible video capture modules found for running operating system.
availableVideoSources = [LionVideoDevice[Name='FaceTime HD Camera (Built-in)'; Enabled=false]]
webCamera = LionVideoDevice[Name='FaceTime HD Camera (Built-in)'; Enabled=false]
Exception in thread "main" java.lang.NullPointerException
at TemplateRun.main(TemplateRun.java:34)

HardWare:

Camera: V5.16 FaceTime HD Camera (Built-in).

Computer: Macbook pro 2012 Mid-year

OS: MAC OS Sierra 10.12.3

Java Version: Java 8 update, 121

Tested, and it seems not even OpenCV/JavaCV can get the camera feed from the built in camera.

1

There are 1 best solutions below

4
Vitaly Eremenko On

You are trying to initialize instance of VideoCapture class with VideoFormat.WMV video format.

JxCapture doesn't support this format on MacOS. You have to use VideoFormat.MP4 instead:

VideoCapture videoCapture = VideoCapture.create(VideoFormat.MP4); 

or create instance of VideoCapture using default constructor:

VideoCapture videoCapture = VideoCapture.create();