Log in

View Full Version : SAR in frame properties vs. resizer cropping


hello_hello
19th September 2023, 11:07
VapourSynth appears not to factor-in resizer cropping when calculating a SAR for frame properties.

The starting point is a non-anamorphic 1280x720 source.

clip = core.std.Crop(clip, 20,0,0,0)
clip = core.resize.Spline36(clip, 720,576)
The SAR in frame properties changes from 1:1 to 7:5. So far so good.

clip = core.resize.Spline36(clip, 720,576, src_left=20, src_top=0, src_width=1260, src_height=720)
The SAR in frame properties changes from 1:1 to 64:45.

clip = core.resize.Spline36(clip, 720,576, src_left=20, src_top=0, src_width=20, src_height=760)
Still 64:45.

Cheers.

Myrsloik
20th September 2023, 16:04
Will fix

hello_hello
21st September 2023, 11:24
Thanks. A question though....

Is the SAR in frame properties generally used automatically for encoding, or is it something that still must be specified in the command-line, and if they're different, which would be used?
An example (I haven't actually encoded much video using VapourSynth yet) would be DVD resizing that can have an ITU/MPEG4 or Generic SAR, depending on which aspect ratio the user thinks is correct, and based on that, the resulting SAR in frame properties mightn't be the desired one.

I'm asking as I've just about completed a Vapoursyth version of this function (https://forum.doom9.org/showthread.php?t=176667) (it's SAR calculations are how I discovered the problem) so I'm wondering if I should be ensuring the SAR in frame properties is always the expected one.

I'm hoping the answer is "no" but I'm fairly sure that's just wishful thinking. :)

Cheers.

Myrsloik
21st September 2023, 13:34
Is the SAR in frame properties generally used automatically for encoding, or is it something that still must be specified in the command-line, and if they're different, which would be used?

FFmpeg's vapoursynth source reads the frame properties properly. If it's passed with y4m headers you need to specify the aspect ratio manually. Not sure if anything else directly reads the frame properties.

Myrsloik
24th September 2023, 20:14
Please test the SAR fix in R64-RC2 (https://github.com/vapoursynth/vapoursynth/releases/tag/R64-RC2)

Selur
25th September 2023, 17:28
btw. any hope for an option to disable autoloading filters through some parameter/function in Vapoursynth?

hello_hello
26th September 2023, 07:46
Please test the SAR fix in R64-RC2 (https://github.com/vapoursynth/vapoursynth/releases/tag/R64-RC2)

Thanks. I'll probably have to wait for the update to find it's way to the deb-multimedia repo to test in on Linux, but I'll try to install it on Windows in VirtualBox soon to test it that way. It might be a little while before I get to it though.

Cheers.

hello_hello
26th September 2023, 14:24
Edit: I remembered there's a mod version of VapourSynth Edit, so I thought I'd give it a try.
https://github.com/YomikoR/VapourSynth-Editor
It's working normally so I'll do some testing soon, once I've worked out where to put functions so they can be imported easily. :)

I gave it a shot, but VapourSynth won. It's only torturing me.
I tried R64-RC2 and R63 with both the portable and an installed version of Python. Any idea why this is happening? The script evaluates okay but VS Edit opens the preview without any video.
I tried putting the video file in a different place (other than the root of the C drive) thinking that might be the cause, but it didn't make any difference.
It's Windows 11 in VirtualBox but I can't image why that'd matter.

I'm not sure where the version of ffms2 I had came from. I'm pretty sure it was downloaded from VSRepo a while back, and while I reverted the Win11 VirtualBox install to an older one soon after, I kept all the downloaded plugins. Just to be sure though, I replaced ffms2.dll with this version, but nothing changed. https://github.com/FFMS/ffms2

https://imgur.com/76frCln.png

By the way, I was reading the instructions for using BestSource on the VapourSynth website but I couldn't find anywhere to download it. Is it still a thing?

Selur
27th September 2023, 09:42
Does "C:\\0201.mkv", instead of "C:\\0201.mkv" try "C:/0201.mkv" or r"C:\0201.mkv"

Cu Selur

hello_hello
27th September 2023, 11:12
Does "C:\\0201.mkv", instead of "C:\\0201.mkv" try "C:/0201.mkv" or r"C:\0201.mkv"

Cu Selur

It shouldn't be, especially as the result of F6 (evaluating the script) shows it's okay. Plus if I run the script before an index file exists, it's created normally.

I did check though, and using r"C:\0201.mkv" doesn't change anything.
You may not have seen the edit of my previous post, but I discovered the mod version of VSEdit is working fine, so I'm currently using that for testing.

It's led me to discover a typo in the VapourSynth CropResize that was resulting in some SAR madness. I've fixed that, but there's still a SAR oddity in frame properties that happens now and then, so at the moment I'm trying to work out whether it's CropResize or VapourSynth doing a silly.

hello_hello
27th September 2023, 15:06
It looks like there's a math problem. I'm testing "VapourSynth-x64-R64-RC2.exe". The source is 1280x720.

The reason for the tiny amount of height cropping below is because it's what's required for a SAR of 64:45 (1.422222) when 1 pixel is also cropped from the left.

ClipW = clip.width
ClipH = clip.height

PropsNumIn = clip.get_frame(0).props.get('_SARNum', 0)
PropsDenIn = clip.get_frame(0).props.get('_SARDen', 0)

clip = core.resize.Spline36(clip, 720,576, src_left=1, src_top=0.281, src_width=1279, src_height=719.438)

PropsNumOut = clip.get_frame(0).props.get('_SARNum', 0)
PropsDenOut = clip.get_frame(0).props.get('_SARDen', 0)

clip = core.text.Text(clip, f' Source {ClipW}x{ClipH} ' + \
f'PropsIn {PropsNumIn}:{PropsDenIn} ' + \
f'PropsOut {PropsNumOut / PropsDenOut} ({PropsNumOut}:{PropsDenOut})', alignment=2)

https://imgur.com/2vQaFO8.png

PS Is there a better place to put user functions on Windows than in the "Program Files/Python311/Lib" folder?
They'll import from there with something like
import MyFunction as MF
but I'd prefer to keep user functions separate in their own folder.

And the BestSource source filter mentioned on the VapourSynth website... I couldn't find anywhere to download it. Is it still a thing?

Selur
27th September 2023, 16:12
Maybe this helps: I keep all my scripts in: 'F:/Hybrid/64bit/vsscripts' and import them through
# Import scripts folder
scriptPath = 'F:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))

note: this requires 'import sys' and 'import os'

Cu Selur

Myrsloik
27th September 2023, 17:37
It looks like there's a math problem. I'm testing "VapourSynth-x64-R64-RC2.exe". The source is 1280x720.

The reason for the tiny amount of height cropping below is because it's what's required for a SAR of 64:45 (1.422222) when 1 pixel is also cropped from the left.

ClipW = clip.width
ClipH = clip.height

PropsNumIn = clip.get_frame(0).props.get('_SARNum', 0)
PropsDenIn = clip.get_frame(0).props.get('_SARDen', 0)

clip = core.resize.Spline36(clip, 720,576, src_left=1, src_top=0.281, src_width=1279, src_height=719.438)

PropsNumOut = clip.get_frame(0).props.get('_SARNum', 0)
PropsDenOut = clip.get_frame(0).props.get('_SARDen', 0)

clip = core.text.Text(clip, f' Source {ClipW}x{ClipH} ' + \
f'PropsIn {PropsNumIn}:{PropsDenIn} ' + \
f'PropsOut {PropsNumOut / PropsDenOut} ({PropsNumOut}:{PropsDenOut})', alignment=2)

https://imgur.com/2vQaFO8.png

PS Is there a better place to put user functions on Windows than in the "Program Files/Python311/Lib" folder?
They'll import from there with something like
import MyFunction as MF
but I'd prefer to keep user functions separate in their own folder.

And the BestSource source filter mentioned on the VapourSynth website... I couldn't find anywhere to download it. Is it still a thing?

Doh, I flipped source an destination height when cropping. Maybe the next version will please you...