2009-08-29 97 views
4

是否有任何開源的Flash工具,我可以嵌入在網頁上,並使用它來捕獲用戶的網絡攝像頭圖像或短期的剪輯,並做「POST」到我的服務器servlet?我不尋找流媒體視頻,所以我不需要red5或閃存服務器。你可以詳細說明......嗎?使用閃光燈捕捉攝像頭圖像?

回答

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 ClassWeb-Cam-Stop-Motion有趣的應用程序:) Lee Felarca's SimpleFlvWriter是值得期待的還有,根據您的需要。

+0

你認爲將flv轉換成GIF然後用POST方法發送它是個好主意嗎?我認爲這是時間和資源消耗。不是嗎?我知道這個問題的答案是完整的。但我想知道這是否是一個好的解決方案? – 2010-08-20 12:21:27

+0

@Morteza M.我不認爲將flv轉換爲GIF並將其與POSt一起發送是個不錯的主意。這不是我的答案所說的。我說的是這樣的:對於「短時間片段並對我的服務器servlet執行」POST「,你可以使用動畫GIF逃脫......沒有FLV。否則,如果沒有聲音,並且持續時間很短並不適合需求,請嘗試使用SimpleFLVWriter或其他方法繞過「不需要red5或flash服務器」。一般而言,Red5將是一個更強大/更靈活的解決方案。 GIF選項是...,一個選項。 – 2010-08-29 16:44:22

相關問題