简体   繁体   中英

How to get dimensions of an uploaded Video in Azure Media Services (PHP SDK/Django project)

I have a Django app that contains a Video-on-Demand feature. It's powered by Azure Media Services (AMS). When a user uploads a video, I first save the video in an Azure storage blob, and then I use a PHP script (which utilizes the AMS php sdk) to encode the said video and prep a streaming URL (hosted on AMS).

My problem is this: how do I get the dimensions of the video? I need to know the height and width so that I can encode the video to lower res formats on AMS. I can't get the dimensions from python since I'm not uploading the video file onto a local server first (where my web server is running). What are my options? Please advise.

As you are using AMS SDK for PHP to create AMS task, and which requires the video asset file. You can leverage the PHP module http://getid3.sourceforge.net/ to get the info of video asset during the PHP process with a ease.

You can download the PHP module http://getid3.sourceforge.net/ and extract to your php application's folder, and you can use the following code snippet to get the dimensions of video asset:

require_once('./getid3/getid3.php');
$filename="<video_path>"; 
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
var_dump($ThisFileInfo['asf']['video_media']);

Any further concern, please feel free to let me know.

update using remotefile on Azure Storage

Here is a code sample, leveraging which, you can use the SAS url of blobs on Azure Storage. It will download the file to server folder, and detect the info, and then delete the template file.

$remotefilename = '<SAS Url>';
if ($fp_remote = fopen($remotefilename, 'rb')) {
    $localtempfilename = tempnam('/tmp', 'getID3');
    if ($fp_local = fopen($localtempfilename, 'wb')) {
        while ($buffer = fread($fp_remote, 8192)) {
            fwrite($fp_local, $buffer);
        }
        fclose($fp_local);
        // Initialize getID3 engine
        $getID3 = new getID3;
        $ThisFileInfo = $getID3->analyze($localtempfilename);
        // Delete temporary file
        unlink($localtempfilename);
    }
    fclose($fp_remote);
    var_dump($ThisFileInfo);
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM