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. |
14th April 2012, 10:15 | #1 | Link |
x264 fan
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 ? |
14th April 2012, 12:22 | #2 | Link |
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 |
14th April 2012, 21:45 | #3 | Link |
x264 fan
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. |
14th April 2012, 22:13 | #4 | Link | |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
Quote:
For example: - Crop 1920x1080 to 1920x816 - Resize to 1280x544 Now figure out the mindblowing math I used there. I like Spline36 for downscaling, Spline16 is also nice. A matter of taste. |
|
14th April 2012, 22:25 | #5 | Link |
x264 fan
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 ? |
14th April 2012, 22:38 | #6 | Link | |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
Quote:
|
|
14th April 2012, 23:03 | #9 | Link |
x264 fan
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)
|
14th April 2012, 23:07 | #10 | Link |
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) |
14th April 2012, 23:12 | #11 | Link | |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
Quote:
- 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. |
|
14th April 2012, 23:17 | #12 | Link | |
x264 fan
Join Date: Feb 2011
Location: In the trap
Posts: 458
|
Quote:
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. |
|
14th April 2012, 23:23 | #13 | Link | |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
Quote:
|
|
14th April 2012, 23:28 | #14 | Link |
x264 fan
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.
|
14th April 2012, 23:36 | #15 | Link | |||
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
1916 / 816 ~= 2.348 1280 / 546 ~= 2.344 (Error ~= 0.16 %) Quote:
Quote:
|
|||
14th April 2012, 23:47 | #16 | Link |
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. |
14th April 2012, 23:59 | #17 | Link |
x264 fan
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. |
15th April 2012, 00:21 | #18 | Link | |||
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
The difference is the resolution. Quote:
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:
|
|||
15th April 2012, 00:33 | #19 | Link |
x264 fan
Join Date: Feb 2011
Location: In the trap
Posts: 458
|
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. |
15th April 2012, 00:45 | #20 | Link | |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
The differences between those two will be negligible. 1276x544 will not be "less blurry" than 1280x546. |
|
|
|