How to send FLV format data to byteArray using the URL loader in a PHP script?

Im creates a flash game that has a function to capture / record its gameplay, which can be viewed later by the user as a replay.

So far, I can already record the game and write it to flv format in the ByteArray variable.

Now I am working on how to send this ByteArray (video file) to a php script and save it on a web server.

I ran URLLoader in flash, where it can send data, and php will get it through the POST method. Unfortunately, a ByteArray containing flv data must first be encoded to encode php to read it. I understood this from an example on the net where it does the same thing that only sends a JPEG ByteArray instead of the FLV format using JPEGENCODER.

Is there any existing class such as JpegEncoder for the FLV format or any video formats? Or any work around, like creating an encoder, myself?

Thanks in advance guys.

here is my current code to send a ByteArray

            //send byteArray to a PHP 
        var request:URLRequest = new URLRequest(url);
        request.method = URLRequestMethod.POST;

        //need to correctly encode first the ByteArray in FLV format
        //....

        request.data = fs; //FLV byteArray  
        var loader:URLLoader = new URLLoader();
        trace(request.data);
+3
source share
1 answer

Just figured it out.

Now I can successfully send flv byteArray to a php script, where then php receives it and saves it as a flv file on the local system and uploads it to youtube server using the zend framework.

here is my code in flash.

            //send byteArray to a PHP 
        var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
        var request:URLRequest = new URLRequest(url);

        request.requestHeaders.push (header);
        request.method = URLRequestMethod.POST;

        request.data = fs; //FLV byteArray  
        var loader:URLLoader = new URLLoader();
        trace(request.data);
        loader.load(request)

and scipt, which receives and saves it as a flv file:

        $im =  $GLOBALS["HTTP_RAW_POST_DATA"];
    $fp = fopen("testVid.flv", 'w');    
    fwrite($fp, $im);
    fclose($fp);

, byteArray, , JPEGEncoder. , flash php. , , . . , .

+3

Source: https://habr.com/ru/post/1780365/


All Articles