[英]use flash capture webcam image?
是否有任何開源Flash實用程序,我可以嵌入網頁,並使用它來捕獲用戶網絡攝像頭圖像或短持續時間剪輯,並“POST”到我的服務器servlet? 我不尋找流視頻,因此我不需要red5或flash服務器。 你能詳細說說......?
這聽起來像是Thibault Imbert的AS3 GIF動畫編碼類的一個很好的候選者。 我大約兩年前在大學的一個項目中使用它。 你可以在這里查看 。 在我看來,你將有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的AS3 GIF動畫編碼類和這個Web-Cam-Stop-Motion有趣的應用程序:) Lee Felarca的SimpleFlvWriter也值得一看,具體取決於您的需求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.