简体   繁体   English

如何在Azure媒体服务中获取上载视频的尺寸(PHP SDK / Django项目)

[英]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. 我有一个Django应用,其中包含视频点播功能。 It's powered by Azure Media Services (AMS). 它由Azure媒体服务(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). 当用户上传视频时,我首先将视频保存在Azure存储Blob中,然后使用PHP脚本(利用AMS php sdk)对该视频进行编码,并准备一个流URL(托管在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. 我需要知道高度和宽度,以便可以在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). 我无法从python获取尺寸,因为我没有先将视频文件上传到本地服务器(运行Web服务器的本地服务器)。 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. 当您使用用于PHP的AMS SDK创建AMS任务时,该任务需要视频资产文件。 You can leverage the PHP module http://getid3.sourceforge.net/ to get the info of video asset during the PHP process with a ease. 您可以轻松地利用PHP模块http://getid3.sourceforge.net/在PHP流程中获取视频资产的信息。

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: 您可以下载PHP模块http://getid3.sourceforge.net/并将其解压缩到php应用程序的文件夹中,并且可以使用以下代码段获取视频资产的尺寸:

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 在Azure存储上使用remotefile更新

Here is a code sample, leveraging which, you can use the SAS url of blobs on Azure Storage. 这是一个代码示例,利用它,您可以在Azure存储上使用Blob的SAS URL。 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);
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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