# Best possible AviSynth Script

1. This is an episode from the bleach R1 DVD, I just demuxed the episode [untouched vob]
As an encoder I want to make a best encode out of this so I can forget about the crappy DVD!
I've used basic denoising plus antialiasing but I'm not happy with the result!
Thanks!
VOB: https://mega.nz/#!TlkBiTCR!4XIU6ru548UXsi4KtnMVfjUBM_fMExyPfM-Jtu0iR-4
2. The best possible script will use a plugin that will be programmed next year...
3. You might get more replies if you post a sample smaller than 915MB. Few people will take the trouble for that much download, and no one is going to install another website's downloader. If you don't know how to make a smaller sample without re-encoding, just ask. Or try MPG2Cut2.
4. Originally Posted by LMotlow
You might get more replies if you post a sample smaller than 915MB. Few people will take the trouble for that much download, and no one is going to install another website's downloader. If you don't know how to make a smaller sample without re-encoding, just ask. Or try MPG2Cut2.
Thanks mate!
Thanks!
5. The DVD looks pretty good to me. What aliasing? I don't see any. What is it that you want to do with this DVD? There's nothing wrong with it. What don't you like about it?

Can you show us the script you tried to use?
6. Request:
Originally Posted by OP
Best possible AviSynth Script
Originally Posted by jagabo
I use the FixEverythingThat'sWrongWithThisVideo() filter. Works perfectly every time.
7. Would probably be more informative if we could see Swaqdith's script.

I suspect he's probably trying to deinterlace the video. It isn't interlaced. It's telecined. During one camera pan it looks like there's some motionless gray vertical bars bars. They don't move, so it won't look like "noise" to a filter. In the same pan scene there's also some faint gray horizontal lines that look like hanover bars. The same thing shows up in the scene with the gray smoke.
8. Hmm, come to think of it those little gray lines only appear in the TV shots, so I assume they're meant to simulate TV broadcast noise/scanlines. They don't appear in any of the other segments. In some spots, looks like a missing frame or two. Inverse Telecine should avoid the aliasing that comes from deinterlacing telecined video. First, I made a d2v demuxed project file with DGIndex. This is the script for the attached mp4, which runs at 23.976 progressive.

Code:
vid=MPEG2Source("Drive:\path\to\VTS_01_1.d2v")
aud=NicAC3Source("Drive:\path\to\VTS_01_1 T80 2_0ch 224Kbps DELAY -27ms.ac3")
AudioDub(vid,aud)
AssumeTFF().TFM().Tdecimate()
return last
If you want DVD or standard def BluRay, you'll have to apply 3:2 pulldown again to get 29.97fps. I used only audio track #1 here.
9. Thanks for your thought guys!
I just don't wanna just fix the DVD!
I want to enhance the output quality as well!
so what I ask for is to make a script which will fix and enhance the issues!

I used this with basic megui automatic anime deinterlacing which downgraded the FPS!

Code:
Undot()
SetMemoryMax()
maa()
LimitedSharpenFaster(ss_x=2.0, ss_y=2.0, strength=180, overshoot=0, undershoot=0, soft=0, edgemode=0)
I just don't wanna just fix the DVD!
I want to enhance the output quality as well!
so what I ask for is to make a script which will fix and enhance the issues!

I used this with basic megui automatic anime deinterlacing which downgraded the FPS!
That's idiotic. This video is not interlaced. Or did you decide to ignore the previous warning about that? No wonder you see aliasing!

There are any number of ways to screw up a decent video with so-called "enhancements". Take your choice. You don't need outside help to screw up a video to your liking.
11. Alright I'll decide that part!
I need another help!

you did mention a way to keep the same frame-rate of the DVD!
just a question will there be any quality difference in that method other than maintaining the frame-rate?
like will there be a difference in 23.97 FPS vs 29.97 FPS versions?
12. There's no quality difference, unless your playback equipment can't handle pulldown well. All film-based NTSC SD video uses some form of pulldown, including many TV shows in SD and HD. However, 23.976 fps is not valid for DVD or standard definition BluRay. To get 29.97fps from 23.976 you apply 3:2 pulldown (aka "2:3 pulldown") in the encoding step.
13. And is AssumeTFF() needed to be used if megui picked this up automatically?
Code:
TFM(order=1).Tdecimate(mode=1,hybrid=1)
14. I can see a bit of noise on the video after the interlace fix! any help with how much denoising should I do?
15. Does this look good guys?
16. I don't use MeGUI, mainly because of all the problems it's giving new users, it doesn't help anyone learn how to process different video types, and its version of Avisynth does not have enough of the proper Avisynth plugins. What's wrong with using the TIVTC (TFM+Tdecimate) code and adding it to MeGUI's script? You will have to import the TIVTC plugin from another location; I don't think MeGUI includes it.

What bit of noise? What kind of noise? What interlace fix? The video isn't interlaced. Can you give us some details? The Read-my-mind forum psychic is on vacation at this time, man. C'mon, get with it.
Does this look good guys?
Not to me. That script is a mess, with poor logic.

Do you have some sort of problem with posting text and full-sized images in a forum thread?
18. Originally Posted by LMotlow
Does this look good guys?
Not to me. That script is a mess, with poor logic.

Do you have some sort of problem with posting text and full-sized images in a forum thread?
Well this is the output video!
Now tell me what's wrong or what should I have done better!
19. Just downloaded the mkv but it's very late here, so I should finish in the morning. You did get the TFM/TDecimate setup more correctly, though, as I notice there is a mix of telecined and duplicate frames during some scenes. So far I don't see any aliasing, but there are some problems with some fine lines that disappear, combine, develop splits with resizing.

Lanczos can cause broken lines and sawtooth edges, especially on downsizing. But you've been told this earlier, I think. Low bitrates are noisy, too, and don't render large flat solid areas cleanly. Why resize to 4:3 when the original is encoded for 4:3 DAR in the first place? You never gain quality by resizing. Resizing always has a cost.

Back tomorrow.
20. Originally Posted by LMotlow
Just downloaded the mkv but it's very late here, so I should finish in the morning. You did get the TFM/TDecimate setup more correctly, though, as I notice there is a mix of telecined and duplicate frames during some scenes. So far I don't see any aliasing, but there are some problems with some fine lines that disappear, combine, develop splits with resizing.

Lanczos can cause broken lines and sawtooth edges, especially on downsizing. But you've been told this earlier, I think. Low bitrates are noisy, too, and don't render large flat solid areas cleanly. Why resize to 4:3 when the original is encoded for 4:3 DAR in the first place? You never gain quality by resizing. Resizing always has a cost.

Back tomorrow.
Well I prefer fixing the aspect ratio at the beginning. No point in just leaving that alone. Thanks for your comments. Hope to expect much more detailed help from you. I'd like to know then which resizing plugin should I use?
21. Some parts of that clip started out as 30p, not 24p. The panning TV shot with billowing smoke in the foreground, for example. IVTC to 24p makes it very jerky. Other parts have an odd pulldown pattern of 2:2:2:4, the dolly shot at the end, for example. Those IVTC ok.
22. Originally Posted by jagabo
Some parts of that clip started out as 30p, not 24p. The panning TV shot with billowing smoke in the foreground, for example. IVTC to 24p makes it very jerky. Other parts have an odd pulldown pattern of 2:2:2:4, the dolly shot at the end, for example. Those IVTC ok.
Yep, the more you look at frames broken down into separate images the more you see different patterns. That leaves an unlucky dude with the chore of going thru that video scene by scene and deciding what kind of pulldown was used in each. Bummer. I got the smoothest motion with this:
Code:
TFM(order=1,pp=0).Tdecimate(mode=1,hybrid=1)
But that isn't perfect for every segment. You get 23.976, but if you add pulldown on encoding for 29.97fps you get jerky motion in some shots. And it looks like the code above drops a frame or two where it shouldn't. I'd have to leave that shot by shot work for someone else.

Well I prefer fixing the aspect ratio at the beginning. No point in just leaving that alone. Thanks for your comments. Hope to expect much more detailed help from you. I'd like to know then which resizing plugin should I use?
I don't know what you mean by "correcting" the aspect ratio. The anamorphic 720x480 MPG plays at a 4:3 display aspect ratio, your square-pixel 640x480 plays at 4:3, and the revised 720x480 mp4 attached below also plays at 4:3. Why do you think they play at different aspect ratios? If you want a new DVD out of 640x480, it won't work.

Lanczos resizers are notorious for several faults, which includes rough edges, broken lines, and oversharpening artifacts. Better to use BicubicResize or Spline36Resize. I used Spline36Resize in the sample attached.

Your mp4 uses long GOPs, one of them is 238 frames long. That might work for low-tier web display, but when you want clean gradients and motion, long GOPs don't get it. They're also the devil to edit, even with smart-rendering apps.

Some lines and edges in the original look kind of rough. I used QTGMC in progressive mode and Santiag() to clean lines about as smooth as they'll get without softening the video. The attached 720x480 mp4 plays at 4:3. When you resized horizontally to 640 width you brought many fine vertical lines closer together, which show up as aliased and broken verticals in some media players that don't resample so well to the player's working window size. With the 640x480 video, MPC-BE showed some aliasing, but MPC and VLC player didn't. I don't see much sense in taking the trouble of losing something through resizing to get the same 4:3 playback, but do as you wish.

The original is also too bright in some scenes, and too contrasty in others where the data stretches beyond RGB 0-255 in some shots.

New code:
Code:
TFM(order=1,pp=0).Tdecimate(mode=1,hybrid=1)
ColorYUV(off_y=-2)
SmoothLevels(16,0.95,255,16,255,chroma=200,limiter=0,tvrange=true,dither=100,protect=6)
QTGMC(preset="medium",InputType=1,sharpness=0.7)
Santiag()
LSFmod()
23. Hmm... I wonder why SmoothLevels isn't working!
I already have the required plugins and also the avsi file!
Code:
 Masktools (v2.0a35), Removegrain (v1.0PR), GradFun2db (v1.0).
24. What does "not working" mean? If you're getting an error message, you should show us the message.

You're probably using the obsolete "SmoothLevels" plugin, which is no longer supported. SmoothLevels is now part of the SmoothAdjust plugin. There are newer versions, but some Avisynth versions have problems with it. I used version 2.6.0. Attached below. Remove the old "SmoothLevels" plugin and replace with one of the SmoothAdjust dll's for your system. The newer SmoothAdjust dll is self-contained and doesn't require the other files you mentioned.
25. Thanks for the support mate!
Thanks!
I won't be troubling you for a while since the same script will suit for a few more box sets!
26. I did this:

Code:
Mpeg2Source("D:\Downloads\VTS_01_1.d2v", CPU2="ooooxx", Info=3)
Interleave(TFM(mode=2, field=1, pp=1), TFM(mode=2, field=0, pp=1))

########################################################
# Use Dedup to remove duplicate frames for better noise reduction.
# Dedup requires two passes, use this line on the first pass
#
DupMC(log="VTS_01_1.DeDupLog.txt") return(last) # no need for further processing
#
# Then this line on the second pass
#
#DeDup(threshold=1.5, maxcopies=20, maxdrops=19, log="VTS_01_1.DeDupLog.txt", times="VTS_01_1.DeDupTimes.txt")
#
# Encode or mux with the times.txt file
########################################################

Santiag()
UnDot()
TemporalDegrain(SAD1=100, SAD2=75, sigma=4) # 1/4 the default, try 1/2 too
The result is a variable frame rate video that's only as jerky as the source. If you want to upscale add this to the end of the script:

Code:
ColorMatrix(mode="rec.601->rec.709")
nnedi3_rpow2(2, cshift="Spline36Resize", fwidth=1440, fheight=1080)
MergeChroma(aWarpSharp(depth=5), aWarpSharp(depth=15))
Sharpen(0.3)
27. Originally Posted by jagabo
I did this:

Code:
Mpeg2Source("D:\Downloads\VTS_01_1.d2v", CPU2="ooooxx", Info=3)
Interleave(TFM(mode=2, field=1, pp=1), TFM(mode=2, field=0, pp=1))

########################################################
# Use Dedup to remove duplicate frames for better noise reduction.
# Dedup requires two passes, use this line on the first pass
#
DupMC(log="VTS_01_1.DeDupLog.txt") return(last) # no need for further processing
#
# Then this line on the second pass
#
#DeDup(threshold=1.5, maxcopies=20, maxdrops=19, log="VTS_01_1.DeDupLog.txt", times="VTS_01_1.DeDupTimes.txt")
#
# Encode or mux with the times.txt file
########################################################

Santiag()
UnDot()
TemporalDegrain(SAD1=100, SAD2=75, sigma=4) # 1/4 the default, try 1/2 too
The result is a variable frame rate video that's only as jerky as the source. If you want to upscale add this to the end of the script:

Code:
ColorMatrix(mode="rec.601->rec.709")
nnedi3_rpow2(2, cshift="Spline36Resize", fwidth=1440, fheight=1080)
MergeChroma(aWarpSharp(depth=5), aWarpSharp(depth=15))
Sharpen(0.3)
Thanks for the help guys!
28. Well I used this script:
Code:
LoadPlugin("B:\Suwadith Srithar\MeGUI_2525_x86\tools\avisynth_plugin\SmoothAdjust.dll")
tfm(order=1).tdecimate(mode=1,hybrid=1)
#crop
Spline64Resize(640,480) # Spline64 (Sharp)
#denoise
Santiag()
Deen("c3d",0,3,2)
LSFmod(soft=-2)
SmoothLevels(16,0.95,255,16,255,chroma=200,limiter=0,tvrange=true,dither=100,protect=6)
Please check the output file's quality!
Thanks!