Results 1 to 3 of 3
  1. #1
    rhexis is offline Member
    Join Date
    Nov 2011
    Posts
    56
    Rep Power
    0

    Default Problems with JMF and capturing image with webcam.

    Before getting too in-depth, I would like to say that my laptop is using an inbuilt webcam.

    the following code is being used. I got them off the internet.

    Java Code:
    import java.awt.BorderLayout;
    import javax.media.*;
    import javax.media.protocol.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import javax.media.control.FormatControl;
    import javax.media.format.VideoFormat;
    
    public class test {
    
    	public static void main(String[] args) {
    		test t = new test();
    		t.getCam();
    	}
    
    	public void getCam() {
    		try {
    
    			Vector deviceList = CaptureDeviceManager.getDeviceList(null);
    			System.out.println(deviceList.size());
    			/* Grab the default web cam */
    			MediaLocator ml = new MediaLocator(
    					"vfw:Microsoft WDM Image Capture (Win32):0");
    
    			/* Create my data source */
    			DataSource ds = Manager.createDataSource(ml);
    
    			requestFormatResolution(ds);
    
    			/* Create & start my player */
    			Player p = Manager.createRealizedPlayer(ds);
    
    			p.start();
    
    			Thread.currentThread().sleep(1000);
    
    			/* code for creating a JFrame and adding the visual component to it */
    			JFrame jfrm = new JFrame("Testing Webcam");
    			jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    			if (p.getVisualComponent() != null)
    				jfrm.getContentPane().add(p.getVisualComponent());
    			if (p.getControlPanelComponent() != null)
    				jfrm.getContentPane().add(p.getControlPanelComponent(),
    						BorderLayout.SOUTH);
    			jfrm.pack();
    			jfrm.setLocationRelativeTo(null);
    			jfrm.setVisible(true);
    			jfrm.setSize(320, 240);
    
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public boolean requestFormatResolution(DataSource ds) {
    
    		if (ds instanceof CaptureDevice) {
    			FormatControl[] fcs = ((CaptureDevice) ds).getFormatControls();
    			for (FormatControl fc : fcs) {
    				Format[] formats = ((FormatControl) fc).getSupportedFormats();
    				for (Format format : formats) {
    					if ((format instanceof VideoFormat)
    							&& (((VideoFormat) format).getSize().getHeight() <= 240)
    							&& (((VideoFormat) format).getSize().getWidth() <= 320)) {
    						((FormatControl) fc).setFormat(format);
    						return true;
    					}
    				}
    			}
    		}
    		return false;
    	}
    
    }
    upon running, I encountered this error.

    Java Code:
    javax.media.NoDataSourceException: Cannot find a DataSource for: vfw:Microsoft WDM Image Capture (Win32):0
    	at javax.media.Manager.createDataSource(Manager.java:1037)
    	at test.getCam(test.java:27)
    	at test.main(test.java:14)
    I did some extensive google search, and tried several different solutions. I added in the lines

    Java Code:
    	Vector deviceList = CaptureDeviceManager.getDeviceList(null);
    			System.out.println(deviceList.size());
    and the return is 0, meaning that there are no device detected.

    However, I have JMFStudio installed, and upon running the application and detecting capture devices, I am able to detect this

    Java Code:
    Name = vfw:Microsoft WDM Image Capture (Win32):0
    
    Locator = vfw://0
    
    Output Formats---->
    
    0. javax.media.format.YUVFormat
      YUV Video Format: Size = java.awt.Dimension[width=640,height=480] MaxDataLength = 614400 DataType = class [B yuvType = 32 StrideY = 1280 StrideUV = 1280 OffsetY = 0 OffsetU = 1 OffsetV = 3
    
    1. javax.media.format.YUVFormat
      YUV Video Format: Size = java.awt.Dimension[width=160,height=120] MaxDataLength = 38400 DataType = class [B yuvType = 32 StrideY = 320 StrideUV = 320 OffsetY = 0 OffsetU = 1 OffsetV = 3
    
    2. javax.media.format.YUVFormat
      YUV Video Format: Size = java.awt.Dimension[width=176,height=144] MaxDataLength = 50688 DataType = class [B yuvType = 32 StrideY = 352 StrideUV = 352 OffsetY = 0 OffsetU = 1 OffsetV = 3
    
    3. javax.media.format.YUVFormat
      YUV Video Format: Size = java.awt.Dimension[width=320,height=240] MaxDataLength = 153600 DataType = class [B yuvType = 32 StrideY = 640 StrideUV = 640 OffsetY = 0 OffsetU = 1 OffsetV = 3
    
    4. javax.media.format.YUVFormat
      YUV Video Format: Size = java.awt.Dimension[width=352,height=288] MaxDataLength = 202752 DataType = class [B yuvType = 32 StrideY = 704 StrideUV = 704 OffsetY = 0 OffsetU = 1 OffsetV = 3
    And I am even able to select Capture from JMFStudio, and it runs my webcam perfectly fine.

    I have all the libraries (jmf.jar, mediaplayer.jar, customizer.jar, etc) from jmf-2_1_1 installed to my class path.

    This seems to be quite a difficult question, but I'm hoping I'll be able to get some answers because I've been cracking my brain at it for hours. Thank you

    EDIT:

    I finally managed to solve my problem. However, I encountered something else.

    The follow error shows.

    Java Code:
    1
      Unable to handle format: YUV Video Format: Size = java.awt.Dimension[width=160,height=120] MaxDataLength = 38400 DataType = class [B yuvType = 32 StrideY = 320 StrideUV = 320 OffsetY = 0 OffsetU = 1 OffsetV = 3
    
    Failed to realize: com.sun.media.PlaybackEngine@1a7bf11
    Error: Unable to realize com.sun.media.PlaybackEngine@1a7bf11
    javax.media.CannotRealizeException
    	at javax.media.Manager.blockingCall(Manager.java:2005)
    	at javax.media.Manager.createRealizedPlayer(Manager.java:580)
    	at test.getCam(test.java:32)
    	at test.main(test.java:14)
    May I ask what does it mean?
    Last edited by rhexis; 04-07-2013 at 10:22 PM.

  2. #2
    rhexis is offline Member
    Join Date
    Nov 2011
    Posts
    56
    Rep Power
    0

    Default Re: Problems with JMF and capturing image with webcam.

    Bump. I'm still stuck after 1 week. would appreciate any kind of help.

  3. #3
    rhexis is offline Member
    Join Date
    Nov 2011
    Posts
    56
    Rep Power
    0

    Default Re: Problems with JMF and capturing image with webcam.

    I'm happy to say that I have managed to solve the problem by myself already. Thank you.

Similar Threads

  1. Capturing video from webcam with JMF
    By Shurukan in forum New To Java
    Replies: 2
    Last Post: 11-18-2011, 12:01 PM
  2. How do I capture webcam image into data array
    By Cleeve in forum AWT / Swing
    Replies: 2
    Last Post: 06-12-2011, 12:06 AM
  3. capturing image
    By java_bond in forum Advanced Java
    Replies: 5
    Last Post: 03-04-2010, 08:45 AM
  4. Java+taking image from webcam+3d
    By Test4 in forum New To Java
    Replies: 0
    Last Post: 02-28-2010, 12:38 PM
  5. JMF: capturing built in webcam
    By Perre in forum Advanced Java
    Replies: 0
    Last Post: 02-20-2010, 11:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •