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. |
5th January 2014, 14:08 | #1 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,664
|
1080p 4:2:0 to 540p 4:4:4 without resizing chroma?
Hi everyone,
I'm wondering if is possible to correctly downscale 1080p 4:2:0 to 540p 4:4:4 without resizing chroma? Using the idea and example from here, this is what I have so far. Code:
# 1920x1080p Source DGSource("00042.dgi") # Processing Y = ConvertToY8(matrix="Rec709").Spline36Resize(width/2, height/2) U = UToY8() V = VToY8() YToUV(U, V, Y) ConvertToRGB24(matrix="Rec709") |
5th January 2014, 14:21 | #2 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
most yv12 clips are top left aligned so you shouldn't use a center aligned resizer to resize the luma and merge it to a top left aligned chroma
instead, using a top left aligned resizer should be correct, something like xxxresize (960,540,src_top=1,src_left=1) |
14th January 2014, 06:21 | #3 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,664
|
Okay, so I had some time and I did some test to try to figure out the correct offsets regarding chroma position. Since I want to leave the chroma untouched the alternative is to shift the luma when resizing.
I don't really know what I'm doing so I tried a handful of different offset values. Just a sample: Code:
# 1920x1080p Source DGSource("00042.dgi") # Processing Y = ConvertToY8(matrix="Rec709").Spline36Resize(width/2, height/2, src_left=0.00, src_top=0.00).Subtitle("Y") Y2 = ConvertToY8(matrix="Rec709").Spline36Resize(width/2, height/2, src_left=0.25, src_top=0.00).Subtitle("Y2") Y3 = ConvertToY8(matrix="Rec709").Spline36Resize(width/2, height/2, src_left=0.50, src_top=0.00).Subtitle("Y3") Y4 = ConvertToY8(matrix="Rec709").Spline36Resize(width/2, height/2, src_left=0.50, src_top=0.75).Subtitle("Y4") Y5 = ConvertToY8(matrix="Rec709").Spline36Resize(width/2, height/2, src_left=1.00, src_top=1.00).Subtitle("Y5") U = UToY8() V = VToY8() Y = YToUV(U, V, Y) Y2 = YToUV(U, V, Y2) Y3 = YToUV(U, V, Y3) Y4 = YToUV(U, V, Y4) Y5 = YToUV(U, V, Y5) Interleave(Y, Y2, Y3, Y4, Y5) PointResize(width*2, Height*2) # for testing only ConvertToRGB24(matrix="Rec709") Does anyone know the math involved to calculate the correct offsets? To be honest I do not see any obvious color artifacts, if anything the incorrect offsets are hardly noticeable. |
14th January 2014, 11:54 | #4 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
The correct offsets are src_left=-0.50, src_top=0.
Avisynth resizers preserve the position of the image centre (treating the pixels as point samples). For 4:2:0 with MPEG2 placement, the horizontal chroma centre is 0.5 luma pixels to the left of the luma centre. Code:
luma centre | Luma: L L L L ... L L L L ... L L L L Chroma: C C ... C C ... C C | chroma centre Since the vertical centre positions are the same for luma and chroma, src_top=0. The visual difference when using the wrong offsets (or no offsets) is very small except where you have a sharp chroma transition. Last edited by Gavino; 14th January 2014 at 11:57. |
14th January 2014, 13:26 | #5 | Link |
Registered User
Join Date: Sep 2008
Posts: 365
|
I have 2 generic questions about downscaling 1080p 4:2:0 to 540p 4:4:4 someone hopefully could answer:
- In a blind sample test would you actually be able to differentiate between a 540p 4:2:0 and a 540p 4:4:4 downscaled from a good BD source? - For a generic source, how much would the filesize increase when using x264 and crf encoding at for example crf 16 ? (A guesstimate is good enough)
__________________
(i have a tendency to drunk post) |
14th January 2014, 16:05 | #6 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,664
|
I'm not surprised that I was completely wrong (didn't even try negative values )
Thank you very much Gavino. Your illustration helps me understand the offsets a bit better...(Now I'm going to read this post multiple times ) |
14th January 2014, 17:34 | #7 | Link | |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,493
|
Quote:
In normal viewing conditions, with normal content, I'd say it's unlikely. That's 4:2:0's raison d'etre, after all. |
|
14th January 2014, 22:36 | #8 | Link |
Registered User
Join Date: Oct 2011
Posts: 204
|
I'm just trying to grasp this logically, but wouldn't a left shift mean that you should use
Code:
in = BlankClip(pixel_type="YV12")# or any other YV12 source, really Y = ConvertToY8().Spline36Resize(in.Width()/2, in.Height()/2, src_left=-0.5, src_width=-0.5) U = UToY8() V = VToY8() YToUV(U, V, Y) |
24th January 2014, 11:32 | #11 | Link |
Registered User
Join Date: Dec 2007
Posts: 16
|
May I ask another question here, would You advise me, please?
If I want to make 1280x720 4:4:4 bd-rip from 1920x1080 4:2:0 source blu-ray (Yes, I know it won't be "true" 4:4:4 color but It will be better than 4:2:0, because less source data will be lost) what code (or both) will be right (or not)? Code:
Y = ConvertToY8().Spline36Resize(1280, 720, src_left=-0.5) U = UToY8().Spline36Resize(1280, 720) V = VToY8().Spline36Resize(1280, 720) YToUV(U, V, Y) Code:
Y = ConvertToY8().Spline36Resize(1280, 720) U = UToY8().Spline36Resize(1280, 720, src_left=0.25) V = VToY8().Spline36Resize(1280, 720, src_left=0.25) YToUV(U, V, Y) Last edited by Divet; 24th January 2014 at 11:39. |
24th January 2014, 17:37 | #12 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Both are correct as far as chroma alignment is concerned.
The first one shifts the luma centre 0.5 pixels to the left so it lines up with the chroma centre. The second one shifts the chroma centre 0.25 chroma pixels (=0.5 luma pixels) to the right, again producing alignment. I prefer the second one conceptually as it seems more consistent with normal resizing to preserve the luma centre. |
24th January 2014, 19:00 | #13 | Link |
Registered User
Join Date: Dec 2007
Posts: 16
|
Thank You very much!
I got it! Now it is clear, when we have progressive blu-ray (1080p). But I am interesting in 1080i too. Is it more complex? How to resize interlaced Y, U, V independently? I am talking about true interlaced video, shooted by interlaced camera, such as documentary movies. Not about transferred cinema with pulldown, etc. First, I do this: Code:
SeparateFields() Code:
video1=SelectEven() But I am not sure about chroma placement after SeparateFields()... Are both videos (made by SelectEven and SelectOdd) normal, common 4:2:0 progressive videos? I am not planning to reconstruct interlaced video after resizing. The last lines of my avs scrypt will be: Code:
Interleave(video1, video2) AssumeFrameBased Last edited by Divet; 24th January 2014 at 21:17. |
24th January 2014, 22:21 | #14 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
You need to use src_top=+0.25 when resizing each of Y, U and V for top fields, and src_top=-0.25 similarly for bottom fields. For a TFF source, SelectEven() gives you the top fields and SelectOdd() the bottom fields. For BFF, it is the other way round. |
|
25th January 2014, 00:02 | #15 | Link | |
Registered User
Join Date: Dec 2007
Posts: 16
|
Quote:
And if src_top is the same for Y, U and V, then I can figure out that there is no vertical shift between luma and chroma (in a field). Is it correct? And what about horizontal shift between luma and chroma? I remember I need src_left=0.25 when resizing U and V! Is it correct for fields? |
|
25th January 2014, 01:44 | #16 | Link | |||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Quote:
So there is a vertical shift between luma and chroma, and that is necessary because (in a field, unlike a progressive frame) their vertical centres are in different places. Quote:
Last edited by Gavino; 25th January 2014 at 01:48. |
|||
25th January 2014, 09:08 | #17 | Link | |||
Registered User
Join Date: Dec 2007
Posts: 16
|
Quote:
Quote:
Quote:
Code:
Y = ConvertToY8().Spline36Resize(1280, 720, src_top=0.25) U = UToY8().Spline36Resize(1280, 720, src_top=0.25, src_left=0.25) V = VToY8().Spline36Resize(1280, 720, src_top=0.25, src_left=0.25) YToUV(U, V, Y) |
|||
25th January 2014, 15:18 | #18 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Yes, see the reference I gave in post #15, which shows the layout of both progressive and interlaced YV12:
http://avisynth.nl/index.php/Sampling#YV12_color_format Also the MPEG-2 section of this: http://www.mir.com/DMG/chroma.html Quote:
|
|
25th January 2014, 21:58 | #19 | Link | |
Registered User
Join Date: Dec 2007
Posts: 16
|
Quote:
And if I don't resize something horizontally I don't need src_left=0.25. For example, if I resize chroma 960x270 (one field chroma) to 960x540 or to 960x360. Correct? Last edited by Divet; 26th January 2014 at 16:03. |
|
26th January 2014, 00:25 | #20 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
If you are still downsizing the luma (to match the chroma size and produce a 4:4:4 result), then you still need src_left=0.25 on the chroma, or alternatively src_left=-0.5 on the luma. The luma downsize shifts the luma sampling positions, so the chroma must be shifted to match, even when staying at its original size. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|