I'm trying to capture the video using the jxcapture. I manage to do so just for once but when I'm trying to capture second time the video in the same program I got into troubles. My code is the following:
public VideoCapture videoCapture = VideoCapture.create(VideoFormat.WMV);
public CaptureVideoFromWebCamera(){}
public void start(String filename){
List<VideoSource> availableVideoSources = VideoSource.getAvailable();
System.out.println("availableVideoSources = " + availableVideoSources);
if (availableVideoSources.isEmpty()) {
throw new IllegalStateException("No external video sources available");
}
VideoSource webCamera = availableVideoSources.get(0);
System.out.println("webCamera = " + webCamera);
videoCapture.setVideoSource(webCamera);
java.util.List<Codec> videoCodecs = videoCapture.getVideoCodecs();
System.out.println("videoCodecs = " + videoCodecs);
if (videoCodecs.isEmpty()) {
throw new IllegalStateException("No video codecs available");
}
Codec videoCodec = videoCodecs.get(2);
System.out.println("videoCodec = " + videoCodec);
EncodingParameters encodingParameters = new EncodingParameters(new File("WebCamera.wmv"));
encodingParameters.setBitrate(500000);
encodingParameters.setFramerate(10);
encodingParameters.setKeyFrameInterval(1);
encodingParameters.setCodec(videoCodec);
videoCapture.setEncodingParameters(encodingParameters);
videoCapture.start();
System.out.println("Recording started. Press 'Enter' to terminate.");
}
public void stop(String filename) throws IOException{
System.in.read();
videoCapture.stop();
}
public static void main(String[] args) throws Throwable {
CaptureVideoFromWebCamera obj = new CaptureVideoFromWebCamera();
obj.start("");
obj.stop("");
CaptureVideoFromWebCamera obj1 = new CaptureVideoFromWebCamera();
obj1.start("");
obj1.stop("");
}
}
When I'm trying to do so I'm reveiving the following error (Insufficient system resources exist to complete the requested service web camera):
Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.teamdev.jxcapture.video.win.BaseDirectShowCapture.doStart(SourceFile:103) at com.teamdev.jxcapture.VideoCapture.start(SourceFile:146) at capturer.CaptureVideoFromWebCamera.start(CaptureVideoFromWebCamera.java:58) at capturer.CaptureVideoFromWebCamera.main(CaptureVideoFromWebCamera.java:76) Caused by: java.lang.reflect.InvocationTargetException at com.teamdev.jxdesktop.win32.g.doInvokeAndWait(Unknown Source) at com.teamdev.jxcapture.video.win.BaseDirectShowCapture.doStart(SourceFile:97) ... 3 more Caused by: com.teamdev.jxdesktop.win32.com.ComException: COM object method returns error code: 0x800705AA; Insufficient system resources exist to complete the requested service.
EDIT2: I tried to do add some thread sleep to the code in order to wait for the second capturing process.
CaptureVideoFromWebCamera obj = new CaptureVideoFromWebCamera();
obj.start("1.wmv");
obj.stop("");
Thread.sleep(5000);
CaptureVideoFromWebCamera obj1 = new CaptureVideoFromWebCamera();
obj1.start("2.wmv");
obj1.stop("");
I got the same error.
EDIT3: When I am trying to use the same object for the capturing I got the following message:
Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.teamdev.jxcapture.video.win.BaseDirectShowCapture.doStart(SourceFile:103) at com.teamdev.jxcapture.VideoCapture.start(SourceFile:146) at CaptureVideoFromWebCamera.start(CaptureVideoFromWebCamera.java:47) //videoCapture.start(); at CaptureVideoFromWebCamera.main(CaptureVideoFromWebCamera.java:64) /obj.start("2.wmv"); Caused by: java.lang.reflect.InvocationTargetException at com.teamdev.jxdesktop.win32.g.doInvokeAndWait(Unknown Source) at com.teamdev.jxcapture.video.win.BaseDirectShowCapture.doStart(SourceFile:97) ... 3 more
Actually, you are getting error message because your resource has been already locked by another thread and the lock is not released while you try to utilize the same resource from the another thread.
Here, you have to do two main things :
Step 1 :
In your program, your have setup Thread.Sleep(5000);
but it actually pause your thread instead and you have not setup any statement to release the resource. So, Try resetting camera socket and closing object in a finally
statement.
Step 2 :
try Synchronized
thread instead using normal one as only one process can able to use your resource at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With