I want to scale a video stream on devices with different screen sizes. The sender's video size can be different also.
The code what I have till now:
public func videoView(_ videoView: RTCEAGLVideoView, didChangeVideoSize size: CGSize) {
// scale by height
let w = renderer.bounds.height * size.width / size.height
let h = renderer.bounds.height
let x = (w - renderer.bounds.width) / 2
renderer.frame = CGRect(x: -x, y: 0, width: w, height: h)
}
The renderer is a view where the video is rendered in. This scales, but not in the right way. Some part of the video is lost, the height is fine. But the width is cropped what I understand.
Is it possible to achieve a solution that displays the video full screen (on the receiver side) without losing its aspect ratio?
1920 x 1080 is a 16:9 aspect ratio. By default, smartphones, DSLRs, and most modern camcorders record video at 1920 x 1080.
What Is the Best Aspect Ratio for Video? 16:9 is the best aspect ratio for video due to its acceptance as the international standard and because a majority of the world uses devices with screens matching the 16:9 ratio. Even popular video streaming platforms like Netflix and YouTube use 16:9 for videos.
Try using AVMakeRect(aspectRatio:insideRect)
. This method finds the minimum rect that preserves the aspectRatio inside the specified rect.
You can read more about it here
In general you will specify your UIScreen
bounds as an insideRect:
parameter and the size of your media in aspectRatio
. There might be a case where the rect would be slightly smaller than your UIScreen
size. In that case i suggest using technique called letter boxing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With