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!
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.
Untested, but I think it should work
Code:
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)