问题描述
是否有任何开源的Flash工具,我可以嵌入在网页上,并用它来捕捉用户的摄像头图像或短期的剪辑,并做POST到我的服务器servlet?我不寻找流媒体视频,所以我不需要red5或闪存服务器。你可以详细说一下...?这听起来像是一个很好的候选人。
大约两年前我在大学使用了一个项目。你可以查看。
在我看来,你会有3个步骤:
$ $ $ $ code $ //创建一个Camera对象
//这段代码来自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(你需要一个摄像头);
}
// 2。采取一个或多个截图使用BitmapData
var截图:BitmapData =新的BitmapData(video.width,video.height,false,0x009900);
screenshot.draw(video);
//你可能会把更多的这些保存在一个名为screenshots的数组中,比如
// 3。创建一个GIFEncoder并将其发送到服务器:
//假设屏幕截图是以前保存的BitmapData对象的数组$ b $ var动画编码器:GIF编码器=新GIF编码器);
animationEncoder.setRepeat(0);
animationEncoder.setDelay(150);
animationEncoder.start();
for(var i:int = 1; i< screenshots.length; i ++){
animationEncoder.addFrame(screenshots [i]);
}
animationEncoder.finish();
//将其保存在服务器上
var header:URLRequestHeader = new URLRequestHeader(Content-type,application / octet-stream); //二进制头文件
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);
//很显然你会让侦听器检查一切是否正常,以及何时该操作完成。
// PHP代码将会是这样简单的
$ method = $ _GET ['method'];
$ name = $ _GET ['name'];
if(isset($ GLOBALS [HTTP_RAW_POST_DATA])){
// get bytearray
$ gif = $ GLOBALS [HTTP_RAW_POST_DATA];
//添加下载对话框标题
header('Content-Type:image / gif');
header('Content-Length:'.strlen($ gif));
header('Content-disposition:'。$ method。'; filename =''。$ name。'。gif');
echo $ gif;
} else echo'发生错误。
?>
应该是这样。
制作请确保您查看和好玩的应用:)
也值得一看。
Is there any open source flash utility that i can embed on a webpage and use it to capture user webcam image or short duration clips and do "POST" to my server servlet ? i do not looking for streaming video and so i do not need red5 or flash server. can you folks elaborate ...?
This sounds like a good candidate for Thibault Imbert's AS3 GIF Animation Encoding Class.I've used it about 2 years ago for a project at University. You can check it out here.In my opinion you would have 3 steps:
//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.';
?>
That should be it.
Make sure you check out Thibault Imbert's AS3 GIF Animation Encoding Class and this Web-Cam-Stop-Motion fun app :)Lee Felarca's SimpleFlvWriter is worth looking at as well, depending on your needs.
这篇关于使用闪光灯捕捉摄像头图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!