Log in

View Full Version : SD to HD, BT.601 to BT.709 Conversion in AVS+


Aktan
2nd February 2018, 05:53
Hello all! I have captured some old VHS tapes in YUY2 and I want to upscale it to HD using nnedi3. I've read a lot of information on converting BT.601 to BT.709 and I know the transfer between them is the same but the primaries and matrix are different. I was wondering if the following method is correct way in AVS+. I have seen a way in Dither tools, but I rather just use what's there in AVS+. Since I'm going to encode to 10-bit x264, my finally output will be 4:2:2 10-bit.

#AVI Source in YUY2 720x480 res
ConvertToYV16()
ConvertBits(bits=16)
ConvertBits(bits=32)
ConvertToYUV444(chromaresample="point")
ConvertToRGB48(matrix="Rec601")
ConvertToYUV444(matrix="Rec709")
ConvertToYV16(chromaresample="point")
ConvertBits(bits=16)
ConvertToStacked()
top = last.crop(0, 0, -0, -480).nnedi3_rpow2(rfactor=4, cshift="lanczosresize", fwidth=1440, fheight=1080, ep0=2, nsize=0, nns=4, qual=2, pscrn=4, opt=4)
bottom = last.crop(0, 480, -0, -0).nnedi3_rpow2(rfactor=4, cshift="lanczosresize", fwidth=1440, fheight=1080, ep0=2, nsize=0, nns=4, qual=2, pscrn=4, opt=4)
#return bottom
last = stackvertical(top, bottom)
ConvertFromStacked()
ConvertBits(bits=10, dither=0)


I am unsure if the primaries were change, but I get the feeling they were not. If they were not, is there a way to change it?

FranceBB
2nd February 2018, 07:48
Not sure how Avisynth+ works (I use standard Avisynth 2.6.1).



#assuming it's 720x480 anamorphic flagged 4:3
#crop 8 pixel to get rid of the safe area garbage
#crop 60 top and bottom to get 16:9

crop(8, 60, -8, -60)

#bring everything to 16bit

Dither_convert_8_to_16()

#upscale using NNEDI3 to HD with 16bit precision

nnedi3_resize16(target_width=1280, target_height=720, mixed=true, thr=1.0, elast=1.5, nns=4, qual=2, etype=0, pscrn=4, threads=0, tv_range=true, kernel_d="Spline", kernel_u="Spline", taps=6, f_d=1.0, f_u=2.0, sharp=0, lsb_in=true, lsb=true)

#convert from BT601 to BT709 with 16bit precision

Dither_convert_yuv_to_rgb(matrix="601", output="rgb48y", lsb_in=true)
r = SelectEvery(3, 0)
g = SelectEvery(3, 1)
b = SelectEvery(3, 2)
Dither_convert_rgb_to_yuv(r, g, b, matrix="709", lsb=true)

#Dithering down to real 10bit

Dither_quantize(bitdepth=10, reducerange=true)
Dither_out()


Remember to set --input-depth 10 in x264.
This assuming it's a progressive capture, 'cause if it's interlaced, you should deinterlace it first.

Aktan
2nd February 2018, 15:10
Thanks for the help! I was trying to avoid using dither tools and use pure AVS+ (if possible) but I appreciate your help. I have a few comments/question:

- My source is really 4:3 so cropping top/bottom 60 for 16:9 doesn't apply, but how much should I crop for just 4:3? Is it 8 pixels?
- nnedi3_resize16 also uses dither tools, is it possible to just use nnedi3_resize16?
- I thought standard AVS only supports 8-bit, so does that mean the output is in Stack16 format? If so, how do you output that to x264?
- Yep, I'm setting --input-depth 10 with AVS+ and yep, I have deinterlaced it with QTGMC.
- Does this method change the color primaries between BT.601 and BT.709?

FranceBB
2nd February 2018, 16:18
- My source is really 4:3 so cropping top/bottom 60 for 16:9 doesn't apply, but how much should I crop for just 4:3? Is it 8 pixels?


Use avspmod, you'll figure out how much to crop according to your source.



- nnedi3_resize16 also uses dither tools, is it possible to just use nnedi3_resize16?



Sure, you can avoid to call Dither_convert_8_to_16() and just use nnedi3_resize16 with lsb_in=true, lsb=true.
It's gonna take an 8bit input and upscale it at 16bit.



- I have deinterlaced it with QTGMC.
- Does this method change the color primaries between BT.601 and BT.709?



QTGMC is a very good deinterlacer, but it doesn't change the colour matrix.



- I thought standard AVS only supports 8-bit, so does that mean the output is in Stack16 format? If so, how do you output that to x264?



Avisynth supports 8bit, 10bit, 16bit stacked (dither tool) and 16bit interleave (HDR Core).
You can output 16bit stacked with just Dither_Out() or you can dither it down to 10bit using

Dither_quantize(bitdepth=10, reducerange=true)
Dither_out()

This way you'll send 10bit video to x264 and all you need is to add --input-depth 10.

Aktan
2nd February 2018, 16:25
Use avspmod, you'll figure out how much to crop according to your source.

Sure, you can avoid to call Dither_convert_8_to_16() and just use nnedi3_resize16 with lsb_in=true, lsb=true.
It's gonna take an 8bit input and upscale it at 16bit.

Thanks for the info!

QTGMC is a very good deinterlacer, but it doesn't change the colour matrix.

You misunderstood me. I'm asking if your above script changes the color primaries. Not the matrix, the primaries.

Avisynth supports 8bit, 10bit, 16bit stacked (dither tool) and 16bit interleave (HDR Core).
You can output 16bit stacked with just Dither_Out() or you can dither it down to 10bit using

Dither_quantize(bitdepth=10, reducerange=true)
Dither_out()

This way you'll send 10bit video to x264 and all you need is to add --input-depth 10.

Ah, I see. I always thought regular AVS only outputs 8-bit.