This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Vapoursynth Auto Detect Width based on Input
#1
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!
Reply
#2
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/pythonref...#VideoNode) or VideoFrame (http://www.vapoursynth.com/doc/pythonref...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)
----
Dev versions are in the 'experimental'-folder of my GoogleDrive, which is linked on the download page.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)