When you use ApsaraVideo Media Processing (MPS) to transcode videos, you can specify a resolution for output videos by using a transcoding template. If the images of an output video are stretched, it is generally because the aspect ratio of the input video does not match the specified resolution. This topic describes how to specify a resolution for an output video.
Enable auto-rotate screen
You need to transcode videos in both landscape and portrait modes. For example, the resolutions of input videos are 1920 × 1080 pixels and 1080 × 1920 pixels. In this case, you can define the output resolution by specifying the pixel value of the longer or shorter side.
Configuration methods
When you create a transcoding template in the MPS console, set the Resolution parameter to Set by Long and Short Sides.
When you call the SubmitJobs or AddTemplate operation, set the LongShortMode parameter to true, the Width parameter to the long side of the output video, and the Height parameter to the short side of the output video.
Enable proportional scaling
The input videos use different aspect ratios, such as aspect ratios of 16:9 and 4:3, and you want to retain the original aspect ratios after transcoding. In this case, you can enable proportional scaling.
When you configure a transcoding template, specify either the output width or height and leave the other dimension empty. Alternatively, specify either the longer side or shorter side, and leave the other dimension empty. The unspecified dimension is proportionally scaled to match the aspect ratio of each input video.
If you transcode videos in both landscape and portrait modes, we recommend that you enable auto-rotate screen and define the output resolution by specifying the pixel value of the longer or shorter side. This prevents excessively large or small frame sizes.
NoteIf you specify either the output width or height, you may be charged for a higher tier than the one that you specify. For example, if you set the output height to 720 pixels and the aspect ratio of an input video exceeds 16:9, the output width exceeds 720 pixels. In this case, you are charged additional fees.
Configuration methods
When you create a transcoding template in the MPS console, set the Resolution parameter to Set by Long and Short Sides or Set by Width and Height and specify only one of the longer side and shorter side or one of the output width and output height.
When you call the SubmitJobs or AddTemplate operation, specify only one of the Width and Height parameters and set the LongShortMode parameter to true.
Specify an aspect ratio conversion method
If you specify both the output width and height or both the longer and shorter sides and the aspect ratio of an input video does not match the specified resolution, you can perform aspect ratio conversion. You can adjust the display aspect ratio (DAR) of the output video by stretching the images, adding black bars to the images, or cropping the images. You can also choose to retain the original DAR of the input video.
The sample aspect ratio (SAR) is the width-to-height ratio of a video frame and essentially represents the resolution of a video. The DAR is the width-to-height ratio at which a video is displayed. When you play a video, the video is displayed at the DAR. If the DAR is inappropriate, the video images may be distorted. Generally, the DAR and SAR of a video represent the same proportional relationship between the width and height. However, the DAR and SAR may differ in some cases.
Configuration methods
When you create a transcoding template in the MPS console, specify an aspect ratio conversion method.
When you call the SubmitJobs or AddTemplate operation, configure the AdjDarMethod parameter. For more information, see the TransConfig section of the "Parameter details" topic.