|
07-01-2024, 12:09 PM
|
|
Free Member
|
|
Join Date: Nov 2023
Posts: 53
Thanked 2 Times in 2 Posts
|
|
I digitized several VHS tapes (720x576 PAL 5:4 SAR, 4:3 DAR) and they have different edge noise positions, so crop left,right,top,bottom varies per tape.
I'm trying to do this:
1. crop left/right/top(sometimes)/bottom
2. de-interlace
3. resize to 1440x1080 HD MINUS the borders added afterwards
4. add borders in HD (values calculated from crop in SD to keep aspect ratio) left + right
What I have so far is this but the calculation is incomplete and propably totally wrong, I can't get my head around this
Code:
# crop vars
cropleft=14
cropright=12
croptop=0
cropbottom=8
clip = core.std.Crop(clip, cropleft, cropright, croptop, cropbottom)
# calculate borders/resize keeping aspect ratio
# assume input res = 720x576 PAL 5:4 SAR, 4:3 DAR
finalwidth=(720-cropleft-cropright)*2
finalwidthborder=(1440-finalwidth)/2
finalheight=round((576-croptop-cropbottom)*1,875)
clip = haf.QTGMC(clip, Preset='Slower', TFF=True)
clip = core.resize.Lanczos(clip, 1420, 1080 ,matrix_in="6",matrix="1")
clip = core.std.AddBorders(clip, 10, 10, 0, 0, color=[0, 128, 128])
The resize and addborders values are not yet variables but manually filled in with something I tested that looked OK for these crop values.
Last edited by iseevisions; 07-01-2024 at 12:28 PM.
|
|
Someday, 12:01 PM
|
|
Ads / Sponsors
|
|
Join Date: ∞
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
|
|
|
|
|
07-02-2024, 06:32 AM
|
|
Free Member
|
|
Join Date: Jul 2023
Location: Michigan, USA
Posts: 1,126
Thanked 215 Times in 193 Posts
|
|
|
This has always been a confusing topic for me anyway - If I understand correctly, (in NTSC terms, I realize you have PAL there) you'd want to crop the 720x480 to 704x480 FIRST and then resize to a 4:3 aspect ratio. With NTSC, there's an equivalent of 16 horizontal pixels in total are added (or technically displayed from the horizontal blanking area) as black bars on the sides. My understanding is that DVD's, can be encoded not to have those black bars, but then the actual DVD player will add them to the output if the encoded resolution is 704x480. These would typically have been off screen on most consumer CRTs due to overscan, so this isn't something that was usually observed at the time it was commonly used.
The issue that then leaves is having to deal with head switching noise at the bottom which technically should be masked rather than cropped as I believe that is part of the final 4:3 aspect ratio. Theoretically, for every 3 lines you take off at the bottom for head switching noise or any top line noise, I suppose you could clip something like 4 or 5 total horizontal pixels off of the sides (someone else that is better at math would need to comment about the specific ratio of lines to remove). So you'd end up with something like 696x474 or 694x474 prior to the resize (maybe) if aspect ratio preservation is the primary goal without any sort of black bars. Doing any sort of side cropping is data loss though, so purists would always recommend masking top and bottom rather than cropping. From a symmetry standpoint, I could also see splitting the lower black bar and padding the top with half of those black lines from the bottom.
Curious what others do for their cropping/masking. I take it most just crop and resize without really thinking too much about if the final aspect ratio is a little off which is most likely to be imperceptible to the average viewer.
|
|
07-02-2024, 07:43 AM
|
|
Free Member
|
|
Join Date: Nov 2023
Posts: 53
Thanked 2 Times in 2 Posts
|
|
But isn't NTSC DVD 720x480 SAR 3:2 non-square pixels that needs to be stretched to 720x540 DAR 4:3 (when not 16:9 widescreen that is) square pixels for proper viewing so cropping would only lose data?
In my PAL case it would be 720x576 SAR 5:4 non-square to 768x576 DAR 4:3 square, but instead upscaling directly to 1440x1080, also 4:3 DAR.
But that's the easy part
What I'm trying to achieve here is cropping the VHS noise left,right,bottom,top zooming in(during resize) but stop zooming else I would lose too much of the bottom, instead adding borders left+right. There is never a border needed top or bottom.
The borders to be added AFTER resizing or else the left+right border edges are oversharpened during resizing.
So it all needs to be automatically calculated to keep the aspect ratio...
|
|
07-02-2024, 01:56 PM
|
|
Free Member
|
|
Join Date: Jan 2016
Posts: 439
Thanked 89 Times in 80 Posts
|
|
Starting with the following equation:
Quote:
You can calculate that with 720x576 (actually 704x576 with 16 pixels of padding) Storage Aspect Ratio (SAR) PAL at a Display Aspect Ratio (DAR) of 4:3, the Pixel Aspect Ratio (PAR) is 12:11:
Code:
dar = 4/3
capture_x = 720
padding_x = 16
capture_y = 576
capture_sar = capture_y / (capture_x - padding_x)
par = dar / capture_sar # 1.090909...
Save that value, you're going to need it later.
Next, adding some variables to yours:
Code:
cropped_x = capture_x - (cropleft + cropright)
cropped_y = capture_y - (croptop + cropbottom)
Now we can use the top equation again to solve for the new DAR (resized_x/resized_y) and square pixels by using the old PAR:
Code:
# DAR = PAR x SAR
# (resized_x / resized_y) = par * (cropped_x / cropped_y)
# resized_x = par * (cropped_x / cropped_y) * resized_y
resized_y = 1080
resized_x = par * (cropped_x / cropped_y) * resized_y
Or solve for resized_y instead:
Code:
resized_x = 1440
resized_y = resized_x / (par * (cropped_x / cropped_y))
Then crop and/or add borders as needed.
|
|
07-03-2024, 08:34 AM
|
|
Free Member
|
|
Join Date: Nov 2023
Posts: 53
Thanked 2 Times in 2 Posts
|
|
That doesn't seem right, or I'm doing it wrong 
It resizes to 2150x1080 instead of something like 1350x1080
This is what I've used:
Code:
cropleft=14
cropright=12
croptop=0
cropbottom=8
clip = core.std.Crop(clip, cropleft, cropright, croptop, cropbottom)
dar = 4/3
capture_x = 720
padding_x = 16
capture_y = 576
capture_sar = capture_y / (capture_x - padding_x)
par = dar / capture_sar # 1.090909...
cropped_x = capture_x - (cropleft + cropright)
cropped_y = capture_y - (croptop + cropbottom)
resized_y = 1080
resized_x = par * (cropped_x / cropped_y) * resized_y
clip = haf.QTGMC(clip, Preset='Slower', TFF=True)
clip = core.resize.Lanczos(clip, resized_x, resized_y ,matrix_in="6",matrix="1")
The calculation of the dynamic border width is missing I think.
Also I'm not sure why the 16 pixels padding is necessary?
Last edited by iseevisions; 07-03-2024 at 08:53 AM.
|
|
07-03-2024, 09:48 AM
|
|
Free Member
|
|
Join Date: Jan 2016
Posts: 439
Thanked 89 Times in 80 Posts
|
|
|
I think it's doing some or all of its calculations using integers instead of floating point values. So try specifying, for example, "720." with a decimal point instead of "720".
|
|
07-03-2024, 10:44 AM
|
|
Free Member
|
|
Join Date: Nov 2023
Posts: 53
Thanked 2 Times in 2 Posts
|
|
|
If I put it in a calculator it's the same result:
# capture_sar = capture_y / (capture_x - padding_x)
576 ÷ (720 − 16) = 0.818181818
# par = dar / capture_sar
(4÷3) ÷ 0.818181818 = 1.62962963
# cropped_x = capture_x - (cropleft + cropright)
720 − (14 + 12) = 694
# cropped_y = capture_y - (croptop + cropbottom)
576 − (0 + 8) = 568
# resized_y = 1080
# resized_x = par * (cropped_x / cropped_y) * resized_y
1.62962963 × (694 ÷ 568) × 1080 = 2150.4225357
|
|
07-03-2024, 11:40 AM
|
|
Free Member
|
|
Join Date: Jan 2016
Posts: 439
Thanked 89 Times in 80 Posts
|
|
Oops, it should be:
Code:
capture_sar = (capture_x - padding_x) / capture_y
|
|
07-03-2024, 11:51 AM
|
|
Premium Member
|
|
Join Date: Feb 2023
Location: Oklahoma, Poteau
Posts: 676
Thanked 111 Times in 100 Posts
|
|
Quote:
The calculation of the dynamic border width is missing I think.
Also I'm not sure why the 16 pixels padding is necessary?
|
Keaton answers a lot of why questions pertaining to aspect ratio in this thread.
https://www.digitalfaq.com/forum/vid...-mp4-easy.html
Selurs post on aspect ratios has an interesting read at the end of it for anyone new to anamorphic pixels.
https://forum.selur.net/thread-597.html
|
|
07-03-2024, 12:41 PM
|
|
Free Member
|
|
Join Date: Nov 2023
Posts: 53
Thanked 2 Times in 2 Posts
|
|
Quote:
Originally Posted by traal
Code:
capture_sar = (capture_x - padding_x) / capture_y
|
OK that makes it 1439x1080 ... I don't believe that 1 pixel width difference has done anything to compensate for the cropped width and kept the aspect ratio correct.
And indeed when comparing, the output image is stretched too wide...
I still don't have a clue how many pixels I should subtract from this 1439 to shrink the width (and add to the borders afterwards)
|
|
07-03-2024, 02:18 PM
|
|
Free Member
|
|
Join Date: Jan 2016
Posts: 439
Thanked 89 Times in 80 Posts
|
|
|
Actually it's 1439.539 pixels across, which is then rounded to 1440.
By cropping out 14+12-16=10 pixels from the x axis that count against (and reduce) the 4:3 DAR, and 8 pixels from the bottom that then increase the DAR, you've returned the image back to nearly the same 4:3 DAR. It's a happy coincidence, as Bob Ross might say.
|
|
07-03-2024, 02:50 PM
|
|
Free Member
|
|
Join Date: Nov 2023
Posts: 53
Thanked 2 Times in 2 Posts
|
|
|
---------------------------------
|
|
07-03-2024, 03:01 PM
|
|
Free Member
|
|
Join Date: Nov 2023
Posts: 53
Thanked 2 Times in 2 Posts
|
|
Yes, nearly 4:3, but not quite.
If you compare both screenshots fullscreen, the output is a bit stretched too wide horizontally, that's what I'm trying to avoid:
(note 1: the input screenshot resolution is 768x576 because I put the player in 4:3 aspect ratio)
note 2: the leftcrop is too low for this VHS but I keep the value the same in this example here for consistency)
input: input.jpg
output: | You must be logged in to view this content; either login or register for the forum. The attached screen shots, before/after images, photos and graphics are created/posted for the benefit of site members. And you are invited to join our digital media community. |
|
All times are GMT -5. The time now is 02:46 AM
|