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 13th January 2021, 12:49   #1  |  Link
PatchWorKs
Registered User
 
PatchWorKs's Avatar
 
Join Date: Aug 2002
Location: Italy
Posts: 228
[HELP REQ] How to implement MPEG-2 (576i) to HEVC (2160p) clean, upscale and encode

I do really need to upscale my old 576i/MPEG2 clips to 2160p/265.

Need to:
- autocrop
- deinterlace
- quality denoise/deblock
- upscale
- 2 pass reencode

Can anyone help me to choose best scripts/filters to use ?

Thanks in advance !
PatchWorKs is offline   Reply With Quote
Old 13th January 2021, 12:53   #2  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 263
Deinterlace use Animeivtc
Denoise use Temporaldegrain2
kedautinh12 is offline   Reply With Quote
Old 13th January 2021, 19:14   #3  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 1,286
It really depends on what your source is.
I know that it's 720x576 25i but is it truly interlaced?
PAL Sources can be either 25i truly interlaced which can be bobbed up to 50p or progressive flagged as interlaced which shouldn't really be deinterlaced.
So, assuming that your source is truly interlaced, I'm gonna address your points in order:

- Autocrop: you shouldn't really crop BEFORE deinterlacing, otherwise you're gonna screw up fields. Besides, what do you mean by AutoCrop?
720x576 is anamorphic, which means that it has to have a flag, either 4:3 or 16:9.
If it's 16:9, for instance, the player automatically resizes it to 1024x576, otherwise if it's 4:3 the player automatically resizes to fit the 4:3 resolution.
If it's 4:3, I really encourage you not to crop to get 16:9 but rather to add black borders with AddBorders() as you might be cutting important parts of the scene if you crop.

- Deinterlace: there are several different deinterlacers, like TDeint, Yadif, BWDif, but the best one out there is QTGMC, which is slow, but worth it.
Generally, when you bob-deinterlace, you'll end up with fields jumping up-down-up-down when brought to 50p, but QTGMC not only takes care of that, but it also reduces aliasing and it performs some heavy filtering by itself to take care of the most annoying issues.

- Denoise: Dfttest is my favorite denoiser and it's a very good one which uses the Discrete Fourier Transform, so you'll need FTTW in System32 or SysWOW64 depending on which system you have (x86? x64?). I would add MDegrain for temporal degrain if the source is particularly old.

- Deblocking: do you really need it? If the source is an official one from, let's say, a DVD, so a .vob at about 5 Mbit/s, it shouldn't really need deblocking. There are deblocking filters like Deblock_QED and Unblock, but I rarely use 'em. You can also rely on the built-in deblock filter of x265 which is also good enough for most scenarios.

- Upscale: well, NNEDI3 is what you're looking for as it will achieve a better result compared to normal kernel alone. If you don't wanna use it, you can go for Spline64 or Spline36, but again, I strongly suggest using NNEDI.

- 2 pass re-encode: ok, what's your target bitrate?


Since we don't have a sample or any other information, I'll assume a few things:
A) That your sample is an MPEG-2 .vob file truly interlaced
B) That your target bitrate for the 2 pass encode is 25 Mbit/s
C) That you wanna go to BT2020 SDR from BT601 SDR
D) That you're gonna use x265 to encode in H.265 HEVC
E) That you're using the latest version of Avisynth+
F) That you're on Windows

If that's the case, then...


Code:
#Indexing
video=DGDecode_MPEG2Source("video.d2v")
audio=WAVSource("audio.wav")
AudioDub(video, audio)

#Bob-deinterlacing
QTGMC(Preset="placebo")

#Matrix Conversion from BT601 to BT709 SDR with 16bit interleaved precision
ConvertBits(16)
ConvertToDoubleWidth()
Matrix(from=601, to=709, rg=1.0, gg=1.0, bg=1.0, a=16, b=235, ao=16, bo=235, bitdepth=16)
ConvertFromDoubleWidth()

#Matrix Conversion from BT709 SDR to BT2020 SDR with 16bit planar precision
ConvertYUVtoXYZ()
ConvertXYZtoYUV(Color=1, pColor=2)

#Spatial denoise with 16bit planar precision
dfttest(sigma=64, tbsize=1, lsb_in=false, lsb=false, Y=true, U=true, V=true, opt=0, dither=0)

#Optional degrain with 16bit planar precision
super = MSuper(pel=2, sharp=1)
bv1 = MAnalyse(super, isb = true, delta = 1, overlap=4)
fv1 = MAnalyse(super, isb = false, delta = 1, overlap=4)
bv2 = MAnalyse(super, isb = true, delta = 2, overlap=4)
fv2 = MAnalyse(super, isb = false, delta = 2, overlap=4)
MDegrain2(super,bv1,fv1,bv2,fv2,thSADC=800, thSAD=800)

#Adding Borders to get from 4:3 to 16:9 (skip if it's anamorphic flagged 16:9) with 16bit planar precision
AddBorders(152, 0, 152, 0)

#Upscale with 16bit planar precision
nnedi3_rpow2(cshift="Spline64ResizeMT", rfactor=2, fwidth=3840, fheight=2160, nsize=4, nns=4, qual=1, etype=0, pscrn=2, threads=0, csresize=true, mpeg2=true)

#Clipping with 16bit precision
Limiter(min_luma=4096, max_luma=60160, min_chroma=4096, max_chroma=61440)

#Loudness Correction to -24LUFS
ResampleAudio(48000)
Normalize(0.22, show=false)

As to x265 2-pass 25Mbit/s UHD 4:2:0 Type 2 10bit planar with AC3 Audio first track and MP2 Audio second track in .ts, then:

Code:
ffmpeg.exe -i "AVS Script.avs" -vf scale=out_color_matrix=bt2020nc:out_h_chr_pos=0:out_v_chr_pos=0 -pix_fmt yuv420p16le -strict -1 -an -f yuv4mpegpipe - | x265.exe --y4m - --dither --preset medium --level 5.0 --tune fastdecode --no-high-tier --ref 4 --profile main10 --bitrate 25000 --deblock -4:-4 --min-luma 64 --max-luma 940 --chromaloc 2 --range limited --videoformat component --colorprim bt2020 --transfer bt2020-10 --colormatrix bt2020nc --overscan show --no-open-gop --min-keyint 1 --keyint 50 --repeat-headers --rd 3 --vbv-maxrate 25000 --vbv-bufsize 25000  --wpp --pass 1 -o NUL 

ffmpeg.exe -i "AVS Script.avs" -vf scale=out_color_matrix=bt2020nc:out_h_chr_pos=0:out_v_chr_pos=0 -pix_fmt yuv420p16le -strict -1 -an -f yuv4mpegpipe - | x265.exe --y4m - --dither --preset medium --level 5.0 --tune fastdecode --no-high-tier --ref 4 --profile main10 --bitrate 25000 --deblock -4:-4 --min-luma 64 --max-luma 940 --chromaloc 2 --range limited --videoformat component --colorprim bt2020 --transfer bt2020-10 --colormatrix bt2020nc --overscan show --no-open-gop --min-keyint 1 --keyint 50 --repeat-headers --rd 3 --vbv-maxrate 25000 --vbv-bufsize 25000 --wpp --pass 2 -o "\\VBOXSVR\Share_Windows_Linux\temp\raw_video.hevc"



C:/Programmi/MKVToolNix\mkvmerge.exe --output "\\VBOXSVR\Share_Windows_Linux\temp\raw_video.mkv" --language 0:und ^"^(^" \\VBOXSVR\Share_Windows_Linux\temp\raw_video.hevc ^"^)^"

ffmpeg.exe -i "AVS Script.avs" -map 0:1 -af loudnorm=I=-24:LRA=14:tp=-2 -c:a ac3 -b:a 384k -ar 48000 "\\VBOXSVR\Share_Windows_Linux\temp\audio.ac3"

ffmpeg.exe -i "AVS Script.avs" -map 0:1 -af loudnorm=I=-24:LRA=14:tp=-2 -c:a libtwolame -b:a 192k -ar 48000 "\\VBOXSVR\Share_Windows_Linux\temp\audio.mp2"

ffmpeg.exe  -i "\\VBOXSVR\Share_Windows_Linux\temp\raw_video.mkv" -i "\\VBOXSVR\Share_Windows_Linux\temp\audio.ac3" -i "\\VBOXSVR\Share_Windows_Linux\temp\audio.mp2" -map 0:0 -map 1:0 -map 2:0 -c:v copy -c:a copy -c:a copy  -f mpegts -mpegts_original_network_id 0x1122 -mpegts_transport_stream_id 0x3344 -mpegts_service_id 0x5566 -mpegts_pmt_start_pid 0x1500 -mpegts_start_pid 0x150 -mpegts_service_type "digital_tv" -mpegts_flags "resend_headers" "\\VBOXSVR\Share_Windows_Linux\temp\final.ts"

pause


Couple of things:

1) If you don't have to air it, you can easily choose AAC as audio and mkv as container, you don't have to use AC3, MP2 and .ts

2) If you don't have to air it, you can encode with way different specs in x265, like without setting the keyint equal to the framerate etc


That's pretty much it from me and since you're Italian, I'm gonna say: tič, servito e riverito hahahaha

Last edited by FranceBB; 13th January 2021 at 19:21.
FranceBB is offline   Reply With Quote
Old 13th January 2021, 22:40   #4  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,395
Sounds like a lot of work to end up with almost the same thing. Up-scaling doesn't improve anything. The other steps won't do much either.

And, of course, re-encoding will reduce quality.

Try it on one of your most-watched videos and see if you think the end result is worth all the effort. My guess? No.
johnmeyer is offline   Reply With Quote
Old 14th January 2021, 01:29   #5  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 1,286
Quote:
Originally Posted by johnmeyer View Post
Sounds like a lot of work to end up with almost the same thing. Up-scaling doesn't improve anything. The other steps won't do much either.

And, of course, re-encoding will reduce quality.
Yep, John is right.
@PatchWorKs, I blindly addressed your questions, but if you're a home user, you shouldn't upscale.
Not only it won't improve anything, but it will also make you waste more space than the original SD file.
As to re-encoding the file in SD with x265, you might be able to save some space like going from 5Mbit/s to 2Mbit/s but it's still gonna be lossy and it won't be playable on most devices, so is it really worth it?
Make your own conclusions, but your best option, if you're a home user, is to leave the file as it is.
FranceBB is offline   Reply With Quote
Old 14th January 2021, 07:14   #6  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,424
I think this is a good time to try AI upscale when you're upscaling by 7.5x
lansing is offline   Reply With Quote
Old 14th January 2021, 12:40   #7  |  Link
takla
Registered User
 
Join Date: May 2018
Posts: 13
You're insane for wanting 576i to 2160p. Most funny thing I've read in a while.
takla is offline   Reply With Quote
Old 16th February 2021, 15:07   #8  |  Link
DTL
Registered User
 
Join Date: Jul 2018
Posts: 89
Quote:
Originally Posted by johnmeyer View Post
Sounds like a lot of work to end up with almost the same thing. Up-scaling doesn't improve anything.
Actually here is much ways of improvement of MPEG2 contend produced by old hardware:

1. Many frames blending for increasing signal to noise ratio. Old hardware can not even think of something like todays almost realtime processing like about 1 second (25 frames) blending in realtime with motion compensation.

2. Best deinterlacing in compare with simple deinterlacing in the tv of poor people.

3. Best scaler in compare with simple scaler in the tv of poor people.

4. MPEG2 decoding post-processing with decoder-guided de-blocking and de-ringing.

In theory there may be also some playback device to do 1 to 4 in realtime. But I not sure if such processing is already built-in in typical consumer grade playback devices.

HEVC actually do not required for encoding - the older h.264 is enough and with proper metadata defining in the stream no need to convert colorspace to 2020. The good enough playback devices must run 4K and 8K displaying with rec.601 system content just correctly marked in medatata.
Most of processing will be visible also at 1080-lines system. But for extreme perfectionists upscaling to 2160 gives a bit better results. It also greatly depends on source quality.

Last edited by DTL; 16th February 2021 at 15:09.
DTL 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 02:12.


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