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 to get the info of video asset during the PHP process with a ease.

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

    $getID3 = new getID3;
    $ThisFileInfo = $getID3->analyze($filename);

    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);
            // Initialize getID3 engine
            $getID3 = new getID3;
            $ThisFileInfo = $getID3->analyze($localtempfilename);
            // Delete temporary file
    点赞 评论