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

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd February 2018, 05:53   #1  |  Link
Aktan
Registered User
 
Join Date: Feb 2002
Posts: 303
SD to HD, BT.601 to BT.709 Conversion in AVS+

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.

Code:
#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?

Last edited by Aktan; 2nd February 2018 at 15:45. Reason: Found that 32 float is less lossy when converting to RGB
Aktan is offline   Reply With Quote
Old 2nd February 2018, 07:48   #2  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,883
Not sure how Avisynth+ works (I use standard Avisynth 2.6.1).

Code:
#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.

Last edited by FranceBB; 2nd February 2018 at 07:53.
FranceBB is offline   Reply With Quote
Old 2nd February 2018, 15:10   #3  |  Link
Aktan
Registered User
 
Join Date: Feb 2002
Posts: 303
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?

Last edited by Aktan; 2nd February 2018 at 15:17.
Aktan is offline   Reply With Quote
Old 2nd February 2018, 16:18   #4  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,883
Quote:
Originally Posted by Aktan View Post
- 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.

Quote:
Originally Posted by Aktan View Post

- 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.

Quote:
Originally Posted by Aktan View Post

- 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.

Quote:
Originally Posted by Aktan View Post

- 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.
FranceBB is offline   Reply With Quote
Old 2nd February 2018, 16:25   #5  |  Link
Aktan
Registered User
 
Join Date: Feb 2002
Posts: 303
Quote:
Originally Posted by FranceBB View Post
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!

Quote:
Originally Posted by FranceBB View Post
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.

Quote:
Originally Posted by FranceBB View Post
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.
Aktan is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 00:57.


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