doujiu1447
doujiu1447
2016-08-11 13:01
浏览 53
已采纳

如何在Azure Media Services中获取已上载视频的尺寸(PHP SDK / Django项目)

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjuduo4573
    duanjuduo4573 2016-08-15 02:20
    已采纳

    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);
    } 
    
    点赞 评论

相关推荐