【问题标题】:use flash capture webcam image?使用闪存捕获网络摄像头图像?
【发布时间】:2010-11-23 22:47:17
【问题描述】:

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

【问题讨论】:

    标签: flash servlets red5


    【解决方案1】:

    这听起来很适合Thibault Imbert's AS3 GIF Animation Encoding Class。 大约 2 年前,我在大学的一个项目中使用过它。您可以查看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方法发送是个好主意吗?!!我认为这是耗费时间和资源的。不是吗?我知道这个问题的答案是完整的。但是我想知道这是否是一个好的解决方案?
    • @Morteza M. 我认为将 flv 转换为 GIF 并使用 POST 发送不是一个好主意。这不是我的回答所说的。我要说的是:对于“短时间剪辑并“发布”到我的服务器 servlet”,您可以使用动画 GIF……没有 FLV。否则,如果没有声音,并且很短的持续时间不适合需要,请尝试使用 SimpleFLVWriter 或其他东西来绕过“不需要 red5 或 flash 服务器”。一般来说,Red5 将是一个更强大/更灵活的解决方案。 GIF 选项是,嗯……一个选项。
    猜你喜欢
    • 1970-01-01
    • 2011-03-21
    • 2013-02-09
    • 2013-03-17
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多