使用flash捕获网络摄像头图像?

时间:2009-08-29 05:56:25

标签: flash servlets red5

是否有任何开源Flash实用程序可以嵌入网页并使用它来捕获用户网络摄像头图像或短时间剪辑并对我的服务器servlet执行“POST”操作?我不寻找流视频,因此我不需要red5或flash服务器。你们可以详细说明......?

1 个答案:

答案 0 :(得分:3)

这听起来像Thibault Imbert's AS3 GIF Animation Encoding Class的好候选人。 我大约两年前在大学的一个项目中使用它。你可以查看here。 在我看来,你将有3个步骤:

//1.Create a Camera object

//this code comes from the LiveDocs
var camera:Camera = Camera.getCamera();
var video:Video;            
if (camera != null) {
    video = new Video(camera.width * 2, camera.height * 2);
    video.attachCamera(camera);
    addChild(video);
} else {
    trace("You need a camera.");
}

//2. Take one or more 'screenshots' using BitmapData

    var screenshot:BitmapData = new BitmapData(video.width,video.height,false,0x009900);
    screenshot.draw(video);
    //you would probably save more of these in an array called screenshots maybe

//3. Create a GIFEncoder and send it to the server:



//assuming screenshots is an array of BitmapData objects previously saved
var animationEncoder:GIFEncoder = new GIFEncoder();
animationEncoder.setRepeat(0);
animationEncoder.setDelay (150);
animationEncoder.start();
for(var i:int = 1 ; i < screenshots.length ; i++){
    animationEncoder.addFrame(screenshots[i]);
}
animationEncoder.finish();
//save it on the server
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");//binary header
var gifRequest:URLRequest = new URLRequest ('http://yourServer/writeGIF.php?name=myFile.gif&method=download');
gifRequest.requestHeaders.push (header);
gifRequest.method = URLRequestMethod.POST;
gifRequest.data = animationEncoder.stream;
sendToURL(gifRequest);



//Obviously you would have listeners to check if everything was ok, and when the operation //is complete.

//The PHP code would be something simple as this

    <?php

    $method = $_GET['method'];
    $name = $_GET['name'];

    if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {

        // get bytearray
        $gif = $GLOBALS["HTTP_RAW_POST_DATA"];

        // add headers for download dialog-box
        header('Content-Type: image/gif');
        header('Content-Length: '.strlen($gif ));
        header('Content-disposition:'.$method.'; filename="'.$name.'".gif');

        echo $gif ;

    }  else echo 'An error occured.';

    ?>

应该是它。

请务必查看Thibault Imbert's AS3 GIF Animation Encoding Class和此Web-Cam-Stop-Motion有趣的应用:) Lee Felarca's SimpleFlvWriter也值得关注,具体取决于您的需求。

相关问题