Best way to keep aspect ratio?
Best way to keep aspect ratio?
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
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
Re: Best way to keep aspect ratio?
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. Note that this function is NOT official yet, nor fully tested and may change prior to the 0.8.0 release.
-steinar
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. Note that this function is NOT official yet, nor fully tested and may change prior to the 0.8.0 release.
-steinar
Re: Best way to keep aspect ratio?
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
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
Re: Best way to keep aspect ratio?
Well, you just gonna have to pull some mathmagic on that bad integer:
$roundd(%i_my_width%/2, 0)*2
-steinar
$roundd(%i_my_width%/2, 0)*2
-steinar
-
- Posts: 54
- Joined: Thu Sep 22, 2016 7:12 am
Re: Best way to keep aspect ratio?
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.
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
Re: Best way to keep aspect ratio?
Is it the same question/answer as here?
viewtopic.php?t=1610
viewtopic.php?t=1610
emcodem, wrapping since 2009 you got the rhyme?
Re: Best way to keep aspect ratio?
Thanks for quick replay!emcodem wrote: ↑Mon Dec 16, 2024 4:26 pm Is it the same question/answer as here?
viewtopic.php?t=1610
Are you able to correct this workflow please?
I don't understand why the width is 16px as a result
Re: Best way to keep aspect ratio?
sure, can you share your workflow? @buddhabas
emcodem, wrapping since 2009 you got the rhyme?
Re: Best way to keep aspect ratio?
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?