Search code examples
flashactionscriptwebcam

Webcam resolution detection


I just can't believe I've found NOTHING on google, I'm starting to think that may be a DUMB question, but I have to ask.

I WANT to get the MAXIMUM RESOLUTION supported by a webcam, how can I do that?

This is my actual code:

 // Maximum amount of bandwidth that the current 
 // outgoing video feed can use, in bytes per second.
 var bandwidth:int = 0; 
 var quality:int = 100; // This value is 0-100 with 1 being the lowest quality. 


 var cam:Camera = Camera.getCamera();
 if(cam==null)
  writeErrorPopup(NOCAMERA_ERR);
 else
 {
  cam.addEventListener(StatusEvent.STATUS,statusHandler);
  function statusHandler(evt:StatusEvent):void
  {
   if(cam.muted)
   {   
    writeErrorPopup(CAMPERMISSION_ERR);
   }
   else
   {   
    trace(cam.width);
   }
  }    

 cam.setQuality(bandwidth, quality);
 //cam.setMode(640,480,30,false); 
 // setMode(videoWidth, videoHeight, video fps, favor area)

What I have understood is:

  • default setMode of any webcam sets its resolution to 160x120, and infact the trace returns me the 160x120 value.

  • if I uncomment the 640x480 setmode the trace returns me the 640x480 value, which is OK, but this is a static value, I want to understand WHICH is the webcam resolution..

any hint?


Solution

  • There's one way to find out:

    Camera.setMode sets the height and width of the camera to the nearest possible value matching your requested resolution. So if you pick a 4:3 aspect ratio and set the size to, say, 8192x6144, you should be able to get the highest possible resolution of the camera. Just to make sure, you could also try a 16:9 or 16:10 ratio and see which returns the best result.