0

我们有以下代码,它捕获了视频,但没有捕获网络摄像头中显示的实际视频。它只捕获了 x 100 和 y 40 的图像的三分之一

有人可以帮助如何捕获网络摄像头中显示的整个图像,例如 320*250

下面是代码

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();
4

1 回答 1

0

看起来您正在将相机设置为小于您需要捕获的尺寸:

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

那是 160 x 120 但你需要

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

有关此调用的参数的详细说明,请参阅 api 文档。

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

于 2010-07-28T16:08:49.070 回答