Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 14th April 2012, 10:15   #1  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
About resizing and cropping

Hi everybody,

I have some technical questions : as from I read around, when encoding with x264 my resolution should be at least mod 4. In the past, I cropped the video then resized it with Lanczos resize but I read it would blur and provoke ringing (especially Lanczos4) so I decided not to use it anymore. Here are the questions :

1) Should I just crop with the crop(x,x,x,x) function and that's all ? Will that maybe result in blurring anyway ? Is there another way to crop ?

2) What if, for some reason, I have a potential source that has black bars ; after cropping, let's say one of width or height is divisible by 2. Should I keep it like that or intentionally cut more pixels in order to have a weft divisible by 4 ?

3) I'm still not sure of what mod4 is : does that just mean 4 is the largest divisor of width or height ? How to be sure to systematically do mod4 at the cost of cutting some extra pixels ?
sirt is offline   Reply With Quote
Old 14th April 2012, 12:22   #2  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
1.) Just crop (and then resize if desired)
2.) keep it like that
3.) mod4 resolution means that both the width and the height are divisible by 4 without any remainder.
Example:
width: 1920 / 4 = 480, remainder 0
height: 1080 / 4 = 270, remainder 0
=> 1920x1080 is mod4

mod16:
width: 1920 / 16 = 120, remainder 0
height: 1080 / 16 = 67, remainder 8 (67.5)
=> 1920x1080 is not mod16
sneaker_ger is offline   Reply With Quote
Old 14th April 2012, 21:45   #3  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Thanks sneaker_ger, it is much clear now.

EDIT : I only resize when encoding and HD Full source an Heavy one (1280x720), I use spline16resize(1280,720) before cropping in fact ; otherwize, cropping then resizing seems to distord the video because it forces it to come back at 1280x720 again. Did you perhaps made a lapsus ? Anyway do you think that spline16resize is enough rafinate or would you suggest another resizer ? As you probably know I want to avoid blurring and ringing and I know some resizers can cause that.

Last edited by sirt; 14th April 2012 at 21:55.
sirt is offline   Reply With Quote
Old 14th April 2012, 22:13   #4  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by sirt View Post
I use spline16resize(1280,720) before cropping in fact ; otherwize, cropping then resizing seems to distord the video
Obviously you have to resize properly after cropping.

For example:
- Crop 1920x1080 to 1920x816
- Resize to 1280x544

Now figure out the mindblowing math I used there.


Quote:
Originally Posted by sirt View Post
Anyway do you think that spline16resize is enough rafinate or would you suggest another resizer ? As you probably know I want to avoid blurring and ringing and I know some resizers can cause that.
I like Spline36 for downscaling, Spline16 is also nice. A matter of taste.
Groucho2004 is offline   Reply With Quote
Old 14th April 2012, 22:25   #5  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Yes thanks, I was dumb sorry. But there the divising factor is 1.5 (1920/1280=816/544=1.5) but let's say I crop from 1920x1080 to 1916x816, then - according to your method - I will need to use that 1.5 factor ; let's call x the width and y the lenght, so 1916/x=1.5 and 816/y=1.5 which gives you x=1277,333333 and y=544 ; all that may imply spline16resize(1277,544) but it seems weird in so far 1277 is not mod 4, I may be appealed to try 1276 instead, so something like that :

crop(2,132,-2,-132)
Spline16Resize(1276,544)

What do you think ?
sirt is offline   Reply With Quote
Old 14th April 2012, 22:38   #6  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by sirt View Post
Yes thanks, I was dumb sorry. But there the divising factor is 1.5 (1920/1280=816/544=1.5) but let's say I crop from 1920x1080 to 1916x816, then - according to your method - I will need to use that 1.5 factor ; let's call x the width and y the lenght, so 1916/x=1.5 and 816/y=1.5 which gives you x=1277,333333 and y=544 ; all that may imply spline16resize(1277,544) but it seems weird in so far 1277 is not mod 4, I may be appealed to try 1276 instead, so something like that :

crop(2,132,-2,-132)
Spline16Resize(1276,544)

What do you think ?
Why would you not stick with a width of 1280 and simply adjust the height accordingly (and round to mod4 if you want)? I only gave you an example.
Groucho2004 is offline   Reply With Quote
Old 14th April 2012, 22:52   #7  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
In my example there are annoying vertical black bars, that's why I cropped from 1280 to 1276.
sirt is offline   Reply With Quote
Old 14th April 2012, 22:55   #8  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by sirt View Post
In my example there are annoying vertical black bars, that's why I cropped from 1280 to 1276.
I thought your source is 1920x1080.
Groucho2004 is offline   Reply With Quote
Old 14th April 2012, 23:03   #9  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Well sorry my brain is completly down...I was meaning 1920x1080 --->1916x816 with the cropping line (in order to remove the black bars) then I wanted to resize by keeping the 1.5 factor correctly that's why I said I should do spline(1277,544) but it looks incorrect to me so I choose spline(1276,544) (i just followed your method below)
sirt is offline   Reply With Quote
Old 14th April 2012, 23:07   #10  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Why are you still sticking to mod4? I told you that mod2 is sufficient (for progressive 4:2:0).

To pick up your example:
Source: 1920x1080
1.) crop(2,132,-2,-132) #result: 1916x816
2.) resize to a width of 1280, while keeping the aspect ratio (using simple math):

816 / 1916 = x / 1280

=>

x = (816 * 1280)/1916 ~= 545.1

Round to nearest mod2 resolution:
Spline16Resize(1280, 546)
sneaker_ger is offline   Reply With Quote
Old 14th April 2012, 23:12   #11  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by sirt View Post
Well sorry my brain is completly down...I was meaning 1920x1080 --->1916x816 with the cropping line (in order to remove the black bars) then I wanted to resize by keeping the 1.5 factor correctly that's why I said I should do spline(1277,544) but it looks incorrect to me so I choose spline(1276,544) (i just followed your method below)
How about this:

- Crop to 1916x816

- The scaling factor for a target width of 1280 is 1916/1280 = 1.496875

- Your target height would then be 816/1.496875 = 545.13569937369519832985386221294

- Round to mod4: 544


Of course you can use a target width of 1276. It's up to you.
Groucho2004 is offline   Reply With Quote
Old 14th April 2012, 23:17   #12  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Quote:
Originally Posted by sneaker_ger View Post
Why are you still sticking to mod4? I told you that mod2 is sufficient (for progressive 4:2:0).
Thanks for your advise and method. So the 1.5 factor is not absolutely needed, is it ? 1920/1280=1.5 but 1080/546=1.9, I think - perhaps undeservedly - that I should have the same dividing factor between both (such as 1920/1280=1.5 and 1080/720=1.5) that's why I wanted to use spline(1276,544) ; I know I am finical but resizing to 1280 the 1920 weft whereas I cropped it to 1916 should result in theorical blurring, shouldn't it ?

About mod2 : in spite of the fact I've read last builds implemented in the x264 should offer the possibility to use mod2, I've also read it may be problematic with some decoders, especially when you play the video trough a blu ray player. Am I wrong ? That's why I'm after mod4.
sirt is offline   Reply With Quote
Old 14th April 2012, 23:23   #13  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by sirt View Post
1920/1280=1.5 but 1080/546=1.9, I think - perhaps undeservedly - that I should have the same dividing factor between both (such as 1920/1280=1.5 and 1080/720=1.5) that's why I wanted to use spline(1276,544) ; I know I am finical but resizing to 1280 the 1920 weft whereas I cropped it to 1916 should result in theorical blurring, shouldn't it ?
I give up, sorry.
Groucho2004 is offline   Reply With Quote
Old 14th April 2012, 23:28   #14  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
lol Why ? You should never give up...I am punctilious that's a fact but I don't want any blur, either ringing, nothing that is NOT from the source. Then resizing to 1280 even thought I have cropped 4 pixels from the source is iqual to a distorsion in my mind and in your second approach above you are respecting the 1.5 scaling factor too.
sirt is offline   Reply With Quote
Old 14th April 2012, 23:36   #15  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Quote:
Originally Posted by sirt View Post
Thanks for your advise and method. So the 1.5 factor is not absolutely needed, is it ? 1920/1280=1.5 but 1080/546=1.9, I think - perhaps undeservedly - that I should have the same dividing factor between both (such as 1920/1280=1.5 and 1080/720=1.5) that's why I wanted to use spline(1276,544)
Of course keeping the AR means a constant factor, and it will check out if you follow the simple math posted above:
1916 / 816 ~= 2.348
1280 / 546 ~= 2.344

(Error ~= 0.16 %)

Quote:
Originally Posted by sirt View Post
I know I am finical but resizing to 1280 the 1920 weft whereas I cropped it to 1916 should result in theorical blurring, shouldn't it ?
I'm no expert on the spline function, but seeing that you can't do cross-multiplying: no, not really.

Quote:
Originally Posted by sirt View Post
About mod2 : in spite of the fact I've read last builds implemented in the x264 should offer the possibility to use mod2, I've also read it may be problematic with some decoders, especially when you play the video trough a blu ray player. Am I wrong ? That's why I'm after mod4.
I don't know where you've read that, but I've never came across any such issues. (Also, internally H.264 works with mod16, so mod4 is just as "bad" as mod2.)
sneaker_ger is offline   Reply With Quote
Old 14th April 2012, 23:47   #16  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Just wanted to add:
The factor you can choose is arbitrary, so 1280x546 is just as wrong or right as your 1276x544. I just pick 1280 as I'm used to that and since it resembles the common 720p resolution, but you don't have to stick to that.
sneaker_ger is offline   Reply With Quote
Old 14th April 2012, 23:59   #17  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Okay thanks for those precious precisions. Now, you can certainly guess what I wonder about...what will be the theorical difference between the 1280x546 and the 1276x544 encode one ? It sound like we won't be able to see any difference between each one but I am curious as you know...

I was referring to that thread http://forum.doom9.org/showthread.php?t=101195 ; but I have another reason to avoid mod2 ; sometimes I experience deinterlacers (you can especially check my thread with the "test.mkv" file) and a large amount of deinterlacers don't support mod2, mostly when you have to crop and cut the frame in separate segments to deinterlace (such as Tdeint to name one) and I don't even tell you about the bob based ones.
sirt is offline   Reply With Quote
Old 15th April 2012, 00:21   #18  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Quote:
Originally Posted by sirt View Post
Okay thanks for those precious precisions. Now, you can certainly guess what I wonder about...what will be the theorical difference between the 1280x546 and the 1276x544 encode one ? It sound like we won't be able to see any difference between each one but I am curious as you know...

The difference is the resolution.

Quote:
Originally Posted by sirt View Post
I was referring to that thread http://forum.doom9.org/showthread.php?t=101195

Nowhere in that thread does it say that mod4 is more compatible with decoders than mod2. And even if x264 did not support mod2 and mod4 encoding many many years ago, this does not have anything to do with decoder compatibility.

Quote:
Originally Posted by sirt View Post
but I have another reason to avoid mod2 ; sometimes I experience deinterlacers (you can especially check my thread with the "test.mkv" file) and a large amount of deinterlacers don't support mod2, mostly when you have to crop and cut the frame in separate segments to deinterlace (such as Tdeint to name one) and I don't even tell you about the bob based ones.
Interlaced YV12 must indeed be at least mod4. mod2 is not allowed in that case.
sneaker_ger is offline   Reply With Quote
Old 15th April 2012, 00:33   #19  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Quote:
Originally Posted by sneaker_ger View Post

The difference is the resolution.
Sure but I was thinking of which one would be the most accurate i.e. the less blurry ; I foretell my 1276x544 would be clear-cut but I think it is just splitting hairs...

I was playing around with a 1080i source, that's why I was reluctant with mod2, but it's all clear now.
sirt is offline   Reply With Quote
Old 15th April 2012, 00:45   #20  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Quote:
Originally Posted by sirt View Post
Sure but I was thinking of which one would be the most accurate i.e. the less blurry ; I foretell my 1276x544 would be clear-cut but I think it is just splitting hairs...
What makes you assume that? (rhetorical question)
The differences between those two will be negligible. 1276x544 will not be "less blurry" than 1280x546.
sneaker_ger is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:31.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.