Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render Size question [question] #89

Open
romaHerman opened this issue Aug 28, 2022 · 4 comments
Open

Render Size question [question] #89

romaHerman opened this issue Aug 28, 2022 · 4 comments

Comments

@romaHerman
Copy link

romaHerman commented Aug 28, 2022

Hi!

Thanks for the awesome tool

I was reading a code related to the video cropping.
There is one thing I can't wrap my head around

CGSize(width: 16 * videoCropView.aspectRatio.width * 18,
                                height: 16 * videoCropView.aspectRatio.height * 18)

Could you please explain why we need to multiple aspectRatio by 16 and 18 ?

and why scale is determined by dividing width on width
let renderScale = renderSize.width / cropFrame.width

Thanks!

@HHK1
Copy link
Owner

HHK1 commented Oct 24, 2022

Hi @romaHerman

For the first question, the interesting part is the multiplication by 16. 18 here is not important, you could potentially put whatever you want. The reason is that encoding videos with width and height that are not a multiple of 16 (or 8 or 4) can lead to some issues (white or green streaks in the video some rows or column for example).
More on that here:

If you know your stuff in video encoding, you could get rid of that constraint. But for that project, I thought it was simpler just to have sensible defaults

@HHK1
Copy link
Owner

HHK1 commented Oct 24, 2022

For the renderScale you need to map the portion of the video you want to crop into your final video size. So there is a transform applied in the video composition that just does that, and the ratio here is used in the transform.

@ZUCheema
Copy link

ZUCheema commented Jul 6, 2023

@romaHerman , 16*18 = 288 which is constant factor. We can easily calculate custom aspect ratio for needed dimensions. Here's an example for aspect ratio 16/9 or 1920x1080 dimension video. and aspect ratio is 6.667:3.75. Similarly, it would be 3.75:3.75 if required render size is 1080x1080.

let factor : CGFloat = 16*18 //288.0
let ratioHeight : Double! = postSize.height/factor //1920/288=6.667
let ratioWidth : Double! = postSize.width/factor// 1080/288=3.75
        
videoCropView.setAspectRatio(CGSize(width: ratioWidth, height: ratioHeight), animated: false)

make sure you setAspectRatio in viewDidLayoutSubviews or viewDidAppear.

@ZUCheema
Copy link

ZUCheema commented Jul 6, 2023

The setAspectRatio function doesn't really seem aspect ratio here. Setting it 1.0/1.0 will generate a video with 288x288 dimension. Its dimension factor instead of aspect ratio and we manually need to calculate render size as a multiplier of 288 factor. I think this function should be modified to take aspect ratio and renderSize in input and calculate actual aspect ratio internally. Like this: videoCropView.setAspectRatio(renderSize: CGSize(width: ratioWidth, height: ratioHeight), aspectRatio: CGFloat, animated: false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants