Selur's Little Message Board
Vapoursynth Auto Detect Width based on Input - Printable Version

+- Selur's Little Message Board (https://forum.selur.net)
+-- Forum: Talk, Talk, Talk (https://forum.selur.net/forum-5.html)
+--- Forum: A/V Talk (https://forum.selur.net/forum-6.html)
+--- Thread: Vapoursynth Auto Detect Width based on Input (/thread-3025.html)



Vapoursynth Auto Detect Width based on Input - TheLastApostle - 08.01.2023

Hi,

I have a library with hundreds of clips each with different aspect ratios ( 16:9 and 21:9 )

How could I in the param underneath tell VS to auto add/decide the height based on the inputs aspect ratio?

clip = vs.core.resize.Bicubic(clip, width = 1280, height = 720, format=vs.RGBS, matrix_in_s="709")

Thank you!


RE: Vapoursynth Auto Detect Width based on Input - Selur - 08.01.2023

In Hybrid, you could simply tell Hybrid to:
  • autocrop
  • resize to target width 1280
  • add letterbox to 1280x720
That said, since this is not Hybrid related, in Vapoursynth in general it's tricky since not all source filters set that info and neither VideoNode  (http://www.vapoursynth.com/doc/pythonreference.html#VideoNode) or VideoFrame (http://www.vapoursynth.com/doc/pythonreference.html#VideoFrame) does hold par information.

Assuming you are using lsmas.LibavSMASHSource or lsmas.LWLibavSource you are in luck.
lsmas it sets "_SARNum" and "_SARDen" as frame properties.
So you could write some python code to calculate the new height value. Smile
Untested, but I think it should work
targetWidth = 1280
sarNum = float(int(clip.get_frame(0).props["_SARNum"]))
sarDen = float(int(clip.get_frame(0).props["_SARNum"]))
mult = targetWidth/(clip.width*sarNum/sarDen)) # newWidth =  oldWidth*SARNum/SARDen*mult
newHeight = int(height * mult + 0.5); # note that this might be mod1, not all filter support this
clip = vs.core.resize.Bicubic(clip, width = targetWidth, height = newHeight, format=vs.RGBS, matrix_in_s="709")
If you later want to convert back to anything but YUV 4:4:4 you need to adjust the height for any height requirement due to the sub sampling.

Cu Selur

Ps.: this will only work if your source is properly signaling the PAR (16:9 and 21:9 are DARs)