使用Amazon Elastic Transcoder获取视频文件的视频分辨率 [英] Get Video Resolution of a Video File using Amazon Elastic Transcoder

查看:161
本文介绍了使用Amazon Elastic Transcoder获取视频文件的视频分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用此配置:

  1-向访问者显示JS上传表单2-将选择的文件直接上传到Amazon S33-使用带选项的Amazon Elastic Transcoder在MP4中对视频进行转码:*分辨率:自动*缩略图:每2秒打开一次 

一切正常.但是,出于两个原因,我需要获得原始视频分辨率/比率.第一个原因是能够为缩略图生成设置良好的比率.(有时是16/9、4/3,iphone视频...)第二个原因是显示HTML5视频播放器的比例最佳,以避免播放器侧面出现空白.

由于 Amazon Elastic Transcoder 已经在自动检测视频分辨率,所以我认为他们可能有办法返回检测到的分辨率,但是……似乎并非如此!

任何人都可以考虑一种获得视频分辨率/比率的方法吗?我当前的解决方案是从服务器上的S3下载视频,并使用 FFmpeg FFprobe 检测分辨率.显然,这并不理想.

解决方案

我有一种可能对您有用的方法,但我想提一提的是,无法直接访问有关上传视频的元数据会直接限制弹性转码器服务,我强烈建议您使用 encoding.com 之类的选择(讽刺的是,他们自己的服务器是托管在AWS上).


所以我的解决方案是您可以使用预设来对通过将其设置为自动"来创建与原始上传视频的长宽比匹配的缩略图文件:

缩略图的宽高比.如果您想让Elastic Transcoder自动检测输入文件中的宽高比并使用缩略图的值,选择自动.如果要指定外观缩略图的比例,选择适用的值.

此时,您现在有两种方法可以实际访问原始视频的长宽比(两者均涉及JavaScript):

1.编写JS来下载第一个缩略图文件,并明确解析图像尺寸并通过将宽度除以高度来计算纵横比.

OR

2.指定 ThumbnailPattern 当您创建原始作业时,该作业将使用"

缩略图文件名模式

{resolution}(可选):如果您希望Elastic Transcoder包含文件名中的分辨率",在字段中包括{resolution}.

然后您就可以了,因此您只需要获取编码视频的第一个图像缩略图,然后使用JS解析分辨率的文件名并计算纵横比即可.

这两种方法都具有一定的技巧,但是无需进行任何额外的视频处理,因此可以从中受益,并且在将来,如果AWS使您可以访问元数据,那么您应该拥有一个非常简单的升级途径,从而消除了这种麻烦./p>

根据Amazon论坛中AWS开发人员的反馈,访问视频元数据可能会在不久的将来变得可用,因此我想您还有第三种选择,这个问题可能会解决.

We have this configuration working:

1- Display a JS Upload Form to the visitor
2- Upload file chosen direclty to Amazon S3
3- Transcode the Video in MP4 using Amazon Elastic Transcoder with options:
       * resolution: auto
       * thumbnails: on, every 2sec

Everything works fine. However, I need to get the original video resolution/ratio for 2 reasons. The first reason is to be able to set a good ratio for the thumbnail generations. (sometimes it's 16/9, 4/3, iphone videos...) The second reason is to display an HTML5 video player with the perfect ratio to avoid blank spaces on the sides of the player.

As Amazon Elastic Transcoder is already detecting the video resolution automatically, I was thinking that they may have a way to return the resolution detected but... it doesn't seem so!

Anyone can think about a way to get the resolution/ratio of the video? My current solution will be to download the video back from S3 on my servers and detects the resolution using FFmpeg or FFprobe. Obviously, it's not ideal.

解决方案

I have a method that might work for you, but I'd just like to mention that not having direct access to metadata about uploaded videos directly limits the usefulness of the elastic transcoder service to the point where I'd strongly recommend using an alternative like encoding.com (ironically their own servers are hosted on AWS).


So my solution is that you could use a preset for encoding jobs that creates thumbnail files that match the aspect ratio of the original uploaded video by setting it to "auto":

The aspect ratio of thumbnails. If you want Elastic Transcoder to automatically detect the aspect ratio in the input file and use that value for thumbnails, select auto. If you want to specify the aspect ratio for thumbnails, select the applicable value.

At this point, you now have two ways to actually access the original video's aspect ratio (both of which involve JavaScript):

1. Write JS that downloads the first thumbnail file, and explicitly parse the image dimensions and calculate the aspect ratio by dividing width by height.

OR

2. Specify a ThumbnailPattern when you create the original job that will generate thumbnail filenames that include the resolution of the image file by using the "{resolution}" placeholder:

Thumbnail Filename Pattern

{resolution} (Optional): If you want Elastic Transcoder to include the resolution in the file name, include {resolution} in the field.

Then you can , so you just need to get the first image thumbnail for an encoded video and use JS to parse the filename for the resolution and calculate the aspect ratio.

Both methods are kind of hacky, but benefit from not needing to do any additional video processing, and in the future when/if AWS gives you access to the metadata you should have a very easy upgrade path that eliminates this kludge.

Based on the responses from the AWS devs in Amazon's forums, accessing video metadata is probably going to become available in the near future, so I guess you also have the third option of waiting and this problem might solve itself.

这篇关于使用Amazon Elastic Transcoder获取视频文件的视频分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆