Reputation: 9286
I wanna achieve the same exact CSS behavior of: background-size: contain
.
But all I am able to choose from is either letterboxing or stretching:
How do we maintain aspect ratio when we provide both width and height as constraints?
Upvotes: 4
Views: 1998
Reputation: 153
There are a couple of options that may work for you. It's unfortunate that Elemental MediaConvert doesn't support a number of commonly-needed resizing options. However there is another service that does: Elastic Transcoder. It's an older service and AWS is pushing people to move to the newer one, but it may be exactly what you need. It doesn't support the same feature set as MediaConvert, but probably does everything a lot of people will need. Compare features for yourself. In particular be sure ET will support the highest resolution videos you expect to have to process. The pricing models are different, so one or the other may be cheaper depending on the type of files you expect to process typically.
If you have to make it work with MediaConvert one way you could do this is to do the resizing calculations and set the output video dimensions yourself to maintain the input aspect ratio. The only problem is how do you get the input video dimensions? I'm presuming here that you're doing this work in a lambda. Otherwise your workflow may have to be quite different. To get the input video dimensions there are a couple of options.
First you could use MediaInfo to extract it. The linked blog walks you through compiling MediaInfo so you can package it up with your lambda and use a pre-signed S3 URL to allow MediaInfo to extract the video metadata for you.
Another option would be to first run a MediaConvert job to create a video one frame long. Leave the dimensions unspecified so the output dimensions match those if the input video. To limit the video length for your input configure an input clip and set the end timecode to 00:00:00:01. When the job finishes the output will include the video dimensions.
From there you can calculate the output video dimensions in such a way that the input aspect ratio is maintained.
Upvotes: 3