4
是否有任何开源的Flash工具,我可以嵌入在网页上,并使用它来捕获用户的网络摄像头图像或短期的剪辑,并做“POST”到我的服务器servlet?我不寻找流媒体视频,所以我不需要red5或闪存服务器。你可以详细说明......吗?使用闪光灯捕捉摄像头图像?
是否有任何开源的Flash工具,我可以嵌入在网页上,并使用它来捕获用户的网络摄像头图像或短期的剪辑,并做“POST”到我的服务器servlet?我不寻找流媒体视频,所以我不需要red5或闪存服务器。你可以详细说明......吗?使用闪光灯捕捉摄像头图像?
这听起来很适合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是值得期待的还有,根据您的需要。
你认为将flv转换成GIF然后用POST方法发送它是个好主意吗?我认为这是时间和资源消耗。不是吗?我知道这个问题的答案是完整的。但我想知道这是否是一个好的解决方案? – 2010-08-20 12:21:27
@Morteza M.我不认为将flv转换为GIF并将其与POSt一起发送是个不错的主意。这不是我的答案所说的。我说的是这样的:对于“短时间片段并对我的服务器servlet执行”POST“,你可以使用动画GIF逃脱......没有FLV。否则,如果没有声音,并且持续时间很短并不适合需求,请尝试使用SimpleFLVWriter或其他方法绕过“不需要red5或flash服务器”。一般而言,Red5将是一个更强大/更灵活的解决方案。 GIF选项是...,一个选项。 – 2010-08-29 16:44:22