views:

31

answers:

1

Hi

we have the below code and it captured the video but not the actual video which displayed in the webcam . It only captured one third of the image like from x 100 and y 40 something like not

Could some one help to how to capture the whole image displayed in the webcam like 320*250

below is the code

import flash.geom.*; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.net.URLRequest; import flash.display.LoaderInfo; import flash.display.Bitmap; import flash.display.BitmapData;

import com.adobe.images.JPGEncoder;

var nc:NetConnection = null; var camera:Camera; var microphone:Microphone; var nsPublish:NetStream = null;
var nsPlay:NetStream = null;

function startCamera() { // get the default Flash camera and microphone camera = Camera.getCamera(); microphone = Microphone.getMicrophone();

// here are all the quality and performance settings that we suggest camera.setMode(160, 120, 12, false); camera.setQuality(0, 88); camera.setKeyFrameInterval(24); microphone.rate = 11; microphone.setSilenceLevel(0);

// subscribeName.text = "testing"; publishName.text = "testing"; // publishName.text = root.loaderInfo.parameters.streamname ;

connect.connectButton.addEventListener(MouseEvent.CLICK, doConnect); doPublish.addEventListener(MouseEvent.CLICK, publish); doSubscribe.addEventListener(MouseEvent.CLICK, subscribe); enablePlayControls(false); }

function ncOnStatus(infoObject:NetStatusEvent) { trace("nc: "+infoObject.info.code+" ("+infoObject.info.description+")"); if (infoObject.info.code == "NetConnection.Connect.Failed") prompt.text = "Connection failed: Try rtmp://[server-ip-address]/videochat"; else if (infoObject.info.code == "NetConnection.Connect.Rejected") prompt.text = infoObject.info.description; }

function doConnect(event:MouseEvent) { // connect to the Wowza Media Server if (nc == null) { // create a connection to the wowza media server nc = new NetConnection(); nc.connect(connect.connectStr.text);

// get status information from the NetConnection object nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);

connect.connectButton.label = "Stop";

// uncomment this to monitor frame rate and buffer length //setInterval(updateStreamValues, 500);

videoCamera.clear(); videoCamera.attachCamera(camera);

enablePlayControls(true); } else { nsPublish = null; nsPlay = null;

videoCamera.attachCamera(null); videoCamera.clear();

//videoRemote.attachNetStream(null); //videoRemote.clear();

nc.close(); nc = null;

enablePlayControls(false);

doSubscribe.label = 'Play'; doPublish.label = 'Go Live';

connect.connectButton.label = "Connect"; prompt.text = ""; } }

function doConnect12() { // connect to the Wowza Media Server if (nc == null) { // create a connection to the wowza media server nc = new NetConnection(); nc.connect(connect.connectStr.text);

// get status information from the NetConnection object nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);

connect.connectButton.label = "Stop";

// uncomment this to monitor frame rate and buffer length //setInterval(updateStreamValues, 500);

videoCamera.clear(); videoCamera.attachCamera(camera);

enablePlayControls(true); } else { nsPublish = null; nsPlay = null;

videoCamera.attachCamera(null); videoCamera.clear();

//videoRemote.attachNetStream(null); //videoRemote.clear();

nc.close(); nc = null;

enablePlayControls(false);

doSubscribe.label = 'Play'; doPublish.label = 'Go Live';

connect.connectButton.label = "Connect"; prompt.text = ""; } }

function enablePlayControls(isEnable:Boolean) { doPublish.enabled = isEnable; doSubscribe.enabled = isEnable; publishName.enabled = isEnable; subscribeName.enabled = isEnable; }

// function to monitor the frame rate and buffer length function updateStreamValues() { if (nsPlay != null) { fpsText.text = (Math.round(nsPlay.currentFPS*1000)/1000)+" fps"; bufferLenText.text = (Math.round(nsPlay.bufferLength*1000)/1000)+" secs"; } else { fpsText.text = ""; bufferLenText.text = ""; } }

function nsPlayOnStatus(infoObject:NetStatusEvent) { trace("nsPlay: "+infoObject.info.code+" ("+infoObject.info.description+")"); if (infoObject.info.code == "NetStream.Play.StreamNotFound" || infoObject.info.code == "NetStream.Play.Failed") prompt.text = infoObject.info.description; }

function subscribe(event:MouseEvent) { if (doSubscribe.label == 'Play') { // create a new NetStream object for video playback nsPlay = new NetStream(nc);

// trace the NetStream status information nsPlay.addEventListener(NetStatusEvent.NET_STATUS, nsPlayOnStatus);

var nsPlayClientObj:Object = new Object(); nsPlay.client = nsPlayClientObj; nsPlayClientObj.onMetaData = function(infoObject:Object) { trace("onMetaData");

// print debug information about the metaData for (var propName:String in infoObject) { trace(" "+propName + " = " + infoObject[propName]); } };

// set the buffer time to zero since it is chat nsPlay.bufferTime = 0;

// subscribe to the named stream nsPlay.play(subscribeName.text);

// attach to the stream //videoRemote.attachNetStream(nsPlay);

doSubscribe.label = 'Stop'; } else {
// here we are shutting down the connection to the server //videoRemote.attachNetStream(null); nsPlay.play(null); nsPlay.close();

doSubscribe.label = 'Play'; } }

function nsPublishOnStatus(infoObject:NetStatusEvent) { trace("nsPublish: "+infoObject.info.code+" ("+infoObject.info.description+")"); if (infoObject.info.code == "NetStream.Play.StreamNotFound" || infoObject.info.code == "NetStream.Play.Failed") prompt.text = infoObject.info.description; }

function publish(event:MouseEvent) { if (doPublish.label == 'Go Live') {

var jpgSource:BitmapData = new BitmapData (camera.height, camera.width);

jpgSource.draw(videoCamera); var jpgEncoder:JPGEncoder = new JPGEncoder(); var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);

var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");

//Make sure to use the correct path to jpg_encoder_download.php jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;

var jpgURLLoader:URLLoader = new URLLoader();
// navigateToURL(jpgURLRequest, "_blank"); sendToURL(jpgURLRequest); // create a new NetStream object for video publishing nsPublish = new NetStream(nc);

nsPublish.addEventListener(NetStatusEvent.NET_STATUS, nsPublishOnStatus);

// set the buffer time to zero since it is chat nsPublish.bufferTime = 0;

// publish the stream by name nsPublish.publish(publishName.text);

// add custom metadata to the stream var metaData:Object = new Object(); metaData["description"] = "Chat using VideoChat example." nsPublish.send("@setDataFrame", "onMetaData", metaData);

// attach the camera and microphone to the server nsPublish.attachCamera(camera); nsPublish.attachAudio(microphone);

doPublish.label = 'Stop'; } else { // here we are shutting down the connection to the server nsPublish.attachCamera(null); nsPublish.attachAudio(null); nsPublish.publish("null"); nsPublish.close();

doPublish.label = 'Go Live'; } }

stage.align = "TL"; stage.scaleMode = "noScale";

startCamera(); doConnect12(); stop();

A: 

Looks like you are setting the camera to a size smaller than you need to capture:

camera.setMode(160, 120, 12, false);

That is 160 x 120 but you need

camera.setMode(320, 250, 12, false);

See the api docs for a detailed explanation of the parameters of this call.

http://www.adobe.com/livedocs/flex/3/langref/flash/media/Camera.html#setMode%28%29

Neil