Best way to keep aspect ratio?

Questions and answers on how to get the most out of FFAStrans
mberg
Posts: 16
Joined: Fri Aug 12, 2016 10:31 am

Best way to keep aspect ratio?

Post by mberg »

Hi

I have set up a workflow that transcode a clip into 3 different qualities(720p, 540p and 360p), the output is MP4.
How is the best way to keep the aspect ratio when i transcode clips? Use the 720,540 and 360 as height.

The avisynth resize and MP4 encoder seems to do it fast and use less CPU than only use custom ffmpeg with scale options.
Have tried to set a custom integer variable into "width", but i get number with decimal and the filter does not like that.
First i take the width/height, then i use this number multiple with height to get the new "width".
But then the problem could be that number is not an even number..

I am a newbie, so any information is helpful. :)

Marius
admin
Site Admin
Posts: 1687
Joined: Sat Feb 08, 2014 10:39 pm

Re: Best way to keep aspect ratio?

Post by admin »

Hi, Marius.

I'm sorry but you have encountered a bug. You reported it earlier and I was just about to give you an answer but then you removed the post. Anyway, the bug has been fixed for the next release. In the mean time you can try and use an undocumented feature which will be fully available and documented for the 0.8.0 release:

When you populate a variable you can use the function "$roundd(%i_your_variable%, 0)" to force your variable to an integer.
2016-08-29 (1).png
2016-08-29 (1).png (14.41 KiB) Viewed 10458 times
Note that this function is NOT official yet, nor fully tested and may change prior to the 0.8.0 release.

-steinar
mberg
Posts: 16
Joined: Fri Aug 12, 2016 10:31 am

Re: Best way to keep aspect ratio?

Post by mberg »

Thanks

I will try this, but i think now i will face the problem with not even number in Avisynth resize.
f.eks i got the number 1271 in width. The resize filter then return an error.

I suppose Custom Avisynth script is maybe the way to go?

Marius
admin
Site Admin
Posts: 1687
Joined: Sat Feb 08, 2014 10:39 pm

Re: Best way to keep aspect ratio?

Post by admin »

Well, you just gonna have to pull some mathmagic on that bad integer:

$roundd(%i_my_width%/2, 0)*2

-steinar
silicontrip
Posts: 54
Joined: Thu Sep 22, 2016 7:12 am

Re: Best way to keep aspect ratio?

Post by silicontrip »

I wrote a custom resizer avisynth script, that resizes to 1920x1080, shouldn't be hard to change to other resolutions. I was very surprised when I discovered that avisynth didn't handle sample aspect ratio and none of the avisynth guys considered this a problem.

It uses pre-poulated s_g_disp_aspect and i_g_interlace variable, which I set before the AV media decoder.

Maybe it might help you.

Code: Select all

# Variables:
#
# m_clip		= The last returned AviSynth media
#
# Do NOT change any of the following variables!!!
# _ffas_video 	= <original video>
# _ffas_audio	= <original audio>
# _ffas_height	= <source height>
# _ffas_width	= <source width>
# _m_clip_a_channels = <total channels>
# _ffas_work_fdr	= Working folder for the workflow
#

s_dar = "%s_g_disp_aspect%"

cpos = FindStr(s_dar,":")
lpos = cpos - 1
rpos = cpos + 1
s_num = LeftStr(s_dar,lpos)
s_den = MidStr(s_dar,rpos)

i_num = Value(s_num)
i_den = Value(s_den)

f_dar = Float(i_num) / Float(i_den) 

n_width = Round(f_dar * 1080.0)
n_height = Round(1920.0 / f_dar)

d_dar = Float (16.0 / 9.0)

i_width = f_dar > d_dar ? 1920 : n_width
i_height = f_dar > d_dar ? n_height : 1080

# rounding for even dimensions
i_width = i_width / 2 * 2
i_height = i_height / 2 * 2

i_height = "%i_g_interlace%" == "0" ? i_height: i_height/2

i_padh = "%i_g_interlace%" == "0" ? (1080 - i_height) / 2 : (540 - i_height) / 2
i_padw = (1920 - i_width) / 2


# padding must also be even
i_padht = i_padh % 2 ==1 ? i_padh-1:i_padh
i_padhb = i_padh % 2 ==1 ? i_padh+1:i_padh

i_padwl = i_padw % 2 ==1 ? i_padw-1:i_padw
i_padwr = i_padw % 2 ==1 ? i_padw+1:i_padw


# perform interlace scaling  for interlace clips
m_clip = "%i_g_interlace%" == "0" ? m_clip : SeparateFields(m_clip)
#i_height = "%i_g_interlace%" == "0" ? i_height: i_height/2

#i_padht = "%i_g_interlace%" == "0" ? i_padht: i_padht/2
#i_padhb = "%i_g_interlace%" == "0" ? i_padhb: i_padhb/2

m_clip = BicubicResize(m_clip,i_width,i_height)
m_clip = AddBorders(m_clip,i_padwl,i_padht,i_padwr,i_padhb)

m_clip =  "%i_g_interlace%" == "0" ? m_clip : Weave(m_clip)

# The following MUST be the last line of your script
Return m_clip
buddhabas
Posts: 19
Joined: Tue Oct 04, 2022 9:03 pm

Re: Best way to keep aspect ratio?

Post by buddhabas »

admin wrote: Tue Aug 30, 2016 9:27 pm Well, you just gonna have to pull some mathmagic on that bad integer:

$roundd(%i_my_width%/2, 0)*2

-steinar
Thanks for the hint :)

what's wrong on my side?

Source:

Image

Workflow:

Image

Image

Result:

Image

Info:

Image

:shock:
emcodem
Posts: 1815
Joined: Wed Sep 19, 2018 8:11 am

Re: Best way to keep aspect ratio?

Post by emcodem »

Is it the same question/answer as here?
viewtopic.php?t=1610
emcodem, wrapping since 2009 you got the rhyme?
buddhabas
Posts: 19
Joined: Tue Oct 04, 2022 9:03 pm

Re: Best way to keep aspect ratio?

Post by buddhabas »

emcodem wrote: Mon Dec 16, 2024 4:26 pm Is it the same question/answer as here?
viewtopic.php?t=1610
Thanks for quick replay!
Are you able to correct this workflow please?
I don't understand why the width is 16px as a result :(
emcodem
Posts: 1815
Joined: Wed Sep 19, 2018 8:11 am

Re: Best way to keep aspect ratio?

Post by emcodem »

sure, can you share your workflow? @buddhabas
emcodem, wrapping since 2009 you got the rhyme?
emcodem
Posts: 1815
Joined: Wed Sep 19, 2018 8:11 am

Re: Best way to keep aspect ratio?

Post by emcodem »

after reading your workflow from PM (thanks!), i sense the only problem you have is a wrong function name. You have $roundd but you need $round instead. Found a typo in documentation and notified steinar for correction of the same.
emcodem, wrapping since 2009 you got the rhyme?
Post Reply