Mostly automatic encoding/preparing for posting process

Kevin_san

Member
Nov 24, 2015
55
14
Ok I wasn't here for weeks,
at first I'd like to share 3 more kernels:
C40i ="3 -9 25 -25 130 0 0 2 -4 -25 0 0 -5 5 25 0 0 0 -1 -7 0 0 0 0 3"
C40k ="3 -10 23 -28 123 0 0 2 -4 -25 0 0 -5 5 25 0 0 0 -1 -7 0 0 0 0 3"
C40k1="3 -10 25 -28 132 0 0 2 -4 -27 0 0 -5 5 23 0 0 0 -1 -7 0 0 0 0 3"

There are diagonal coefficients now that make the pixel "rounder" and everything looks more natural and smooth.
Especially the last turns out very versatile, probably good for a default setting.
It sharpens a bit, reduces halo a bit, and makes many yadif'd videos quite nice looking, more like classic TV with only minimal bobbing. But it needs the postprocessing with the upsampling to reach full quality.
Many encodes look better than the original MPEG2, at least in the VLC player.

About the QTGMC, I agree it should be recommended, but also I think a tuned process that integrates the convolution in place of one of the complex sharpeners inside QTGMC, might improve the quality of the result a lot, also in that it does not "equalize" sharpness over the whole area. What I saw is that videos end up almost as sharp in every corner, when the original deliberately (by the camera artist) kept only the center or focus sharp, like the face of a girl. What the complex sharpeners do though, is improve the artifact situation with those poorly encoded (overloaded) originals.

I think yadif does some pseudo-interpolate, in that it can detect _some_ edges and smooth them out over the doubled lines.
 

iConsume

Active Member
Apr 2, 2011
129
76
SK,

i'm on a mac so most of these tips i don't believe would apply. i don't think many, if any, of the gui apps available on this platform offer the kind of customization you recommend.

but i do have a question: if you had only a standard DVD as source material, what would your recommendation be as far as expectations of the highest possible resolution? anything beyond regular DVD dimensions? reason i ask is because some of your old Rui Saotome rips, I don't think they were available in HD or FHD at the time you encoded them (I might be wrong) but your shares were super clear and with beautiful resolution. maybe even high resolution.
 

Kevin_san

Member
Nov 24, 2015
55
14
I switched to the new AviDemux 2.6.18 BTW, it is faster (good multithreading) and has a few new options, e.g. x265. The x264 parameter set has changed, when we load an old script file, not everything is right.
 

Kevin_san

Member
Nov 24, 2015
55
14
if avisynth works on a mac, then any customization is possible. QTGMC is just a script, that manages a number of object files that hold the actual filter code.
QTGMC does so much of search, interpolation, and AI pattern replacement, that the outcome is practically a different product with increased resolution and smoothness that looks very sharp at the same time.
but you can't beat shannon. just that the original often is practically worse than 720x480. so within that frame the process can restore quite a lot but it cannot generate data to fill a physically higher resolution with something meaningful.
what we see is that many players just perform better, when the input is upsampled. the point is the filtering and resizing from 480 lines to the actual screen of the user. the slow filtering in the upsampling is such that the pixel absolutely disappears, while most players will show still some "stairs" at sharp edges or letter fonts, when fed with that format.
 

SamKook

Grand Wizard
Staff member
Super Moderator
Uploader
May 10, 2009
3,737
5,131
I personally prefer to leave the resolution unchanged so all my mkv encodes are at DVD resolution(720x480, unless I crop a few pixels to remove black bars) which I use as a source instead of the digital versions most people use nowadays and I just fix the aspect ratio inside the stream(has better compatibility than if you do it in the container) to make it 853x480 if 16:9 or 640x480 if 4:3.

I use a video renderer(madvr) with my player that allows me to do complex resizing and filtering in real time so that gives the best result for me since I have a decently powerful PC to play them.


If you play them on a slow pc, you may want to look into upsampling(making the resolution higher when encoding) like kevin_san suggests, but that's not something I've done in any of my encodes.

QTGMC and slow encoding settings are what help making the picture clear.

My scripts are windows only(and what's posted is an outdated version) but I'm pretty sure there's a way to make avisynth works with wine so you could use it for encoding on a mac, but you'd have to do a bit of research to make that work.
 

SamKook

Grand Wizard
Staff member
Super Moderator
Uploader
May 10, 2009
3,737
5,131
I've been meaning to take a look at a recent version of x265 since I've seen a few nice looking encodes with pretty small sizes, but I've barely done anything encoding or akiba related lately.
 

Kevin_san

Member
Nov 24, 2015
55
14
for those who encode on their own..
another example that (somewhat) corrects a black halo above a bright horizontal object.
some older videos are notorious for this. improvement is great though.
it takes some sensitive tuning else the result would look blurred in one direction.


Code:
#LoadPlugin("F:\programs\AviSynth+\plugins+\dgdecode58.dll")
MPEG2Source ("E:\fun\wrk\1\MyDVD.d2v",cpu=0,info=2)

#------ these are kernels for the "bad after-interlace sharpening" fault:
C60 =  "0 -0   0  0 112    0  0 -0 -0 -5   0  0  -0  -0  30    0  0  0 0 -3   0  0  0  0  8" #C
C61 =  "0 -0   0  0 112    0  0 -0 -0 -6   0  0  -0  -0  10    0  0  0 0 -3   0  0  0  0  0" #C
C62 =  "0 -0   0  0   0    0  0  0 -0  0   0  0 112   0   0    0  0 25 0 -0   0  0  0  0  0" #C
C63 =  "0 -0   0  0   0    0  0  0 -0  0   0  0 113   0   0    0  0 19 0 -0   0  0  0  0  0" #C
C64 =  "0 -0   3  0   0    0  0  8  0  0   0  0 140   0   0    0  0 15 0 -0   0  0  3  0  0" #C
C65 =  "0 -0  15  0   0    0  0 27  0  0   0  0 141   0   0    0  0 37 0 -0   0  0 27  0  0" #C

#-- basically we undo the vertical sharpen on the fields, and redo it after deinterlacing
#   coefficient #18 is the intensity, for the simple, asymmetric case
#   it deals with the black halo at the upper edge of a bright rectangular object on dark background
CC=last
ConvertToRGB32(matrix="PC.709",interlaced=true,chromaresample="lanczos4")
SeparateFields
GeneralConvolution(0, C63) ### select kernel to use, specify its variable name here
Weave
ConvertToYV12(matrix="PC.709",interlaced=true,chromaresample="lanczos4")
MergeChroma(CC) # we assume that chroma is not concerned so we put back the original
#---------


#-- Deinterlace Yadif -- delete this, when source is not actually interlaced i.e. shows combing without
#Load_Stdcall_plugin("F:\programs\AviSynth+\plugins\yadif.dll")
Yadif(mode=1,order=1)

AssumeFPS(60000,1001)

# -----
global rff=60000./1001. # for resulting 60fps

#--- show some still pictures: (correct the audio intro length for this!)
tpos=0.0*60.+0.000    # pics start time = minutes*60 + ss.ddd #(seconds)
fpos=int(tpos*rff)    # if we do it by frame number
tsl=int(1.0*rff/2.)+1 # duration of one pic
n=fpos+0 #sometimes add 1

/*
#--- the following is a particular example to cut together DVD intro, slide show, and movie in a controlled manner
vv=last
intro = cut(vv,0,0., 1,06.548-6.5+26./rff) # -13 pics * 0.5s + 26 fields
pics  = cut(vv,1,06.565, 1,06.999) 
movie = cut(vv,1,06.999, 98,21.819)

pics = Loop(pics,tsl,n+26,n+27)
pics = Loop(pics,tsl,n+24,n+25)
pics = Loop(pics,tsl,n+22,n+23)
pics = Loop(pics,tsl,n+20,n+21)
pics = Loop(pics,tsl,n+18,n+19)
pics = Loop(pics,tsl,n+16,n+17)
pics = Loop(pics,tsl,n+14,n+15)
pics = Loop(pics,tsl,n+12,n+13)
pics = Loop(pics,tsl,n+10,n+11)
pics = Loop(pics,tsl,n+8,n+9)
pics = Loop(pics,tsl,n+6,n+7)
pics = Loop(pics,tsl,n+4,n+5)
pics = Loop(pics,tsl,n+2,n+3)
pics = Loop(pics,tsl,n+0,n+1)
#
last = intro + pics + movie
*/


AddBorders(4,4,4,8,$7F7F7F)
ConvertToRGB32(matrix="PC.709",interlaced=false,chromaresample="lanczos4")

C40  = "3 -5 17 -21 112  0  0 -0 -4 -13   0  0 -6 -0  15   0  0  0  0 -4   0  0  0  0  0" #
C40a1= "3 -9 21 -17 112  0  0  0 -4 -12   0  0 -8 -0  14   0  0  0  0 -4   0  0  0  0  0" #
C40a2= "3 -5 21 -17 112  0  0  2 -4 -12   0  0 -8  4  10   0  0  0 -1 -4   0  0  0  0  2" #
C40b ="-2 -3 19 -21 112  0  0 -0 -4 -13   0  0 -6 -0  15   0  0  0  0 -4   0  0  0  0  0" #
C40c = "3 -3 23 -23 112  0  0 -0 -4 -10   0  0 -7 -0  15   0  0  0  0 -5   0  0  0  0  0" #
C40d = "3 -5 23 -25 112  0  0 -0 -4 -10   0  0 -7 -0  15   0  0  0  0 -4   0  0  0  0  0" #
C40e = "3 -5 23 -25 140  0  0 -0 -4 -10   0  0 -6 -0  15   0  0  0  0 -4   0  0  0  0  0" #
C40f = "5 -5 29 -25 130  0  0 -0 -3 -12   0  0 -5 -0  15   0  0  0  0 -4   0  0  0  0  2" #
C40g ="5 -11 29 -25 130  0  0 -0 -3 -10   0  0 -5 -0  20   0  0  0  0 -6   0  0  0  0  2" #
C40h ="5 -11 29 -25 130  0  0 -0 -3 -30   0  0 -5 -0  40   0  0  0  0 -8   0  0  0  0  3" #
C40i ="3  -9 25 -25 130  0  0  2 -4 -25   0  0 -5  5  25   0  0  0 -1 -7   0  0  0  0  3" #
C40k ="3 -10 23 -28 123  0  0  2 -4 -25   0  0 -5  5  25   0  0  0 -1 -7   0  0  0  0  3" #
C40k1="3 -10 25 -28 132  0  0  2 -4 -27   0  0 -5  5  23   0  0  0 -1 -7   0  0  0  0  3" #that's a good general one
C41  = "3 -8  7 -11 112  0  0 -0 -6 -12   0  0 -3  2  14   0  0  0  0 -4   0  0  0  0  2" #C4.1 naturalsharp

GeneralConvolution(0, C40a2) # select kernel to use, specify its variable name here

ConvertToYV12(matrix="PC.709",interlaced=false,chromaresample="lanczos4")

CShft(last,-0.3,-1.5)  # adjust per video for rainbow artifacts / chroma position

Crop(0,6,-2,-2)



#--------------------------- helper funcs ---------------------------------------
function CShft(clip In, float X, float Y) {
w = In.Width()
h = In.Height()
Tmp = In.BlackmanResize(w, h, -X, -Y, w-X, h-Y, 5)
In = MergeChroma(In, Tmp)
return In}

function cut(clip In, int Mins, float secs, int Mins2, float secs2) {
tpos = 60.*Mins + secs
te =   60.*Mins2 + secs2
Outclp=Trim(In,int(rff*tpos)+1,-int(rff*(te-tpos))-1)
return Outclp}
it is only for interlaced videos and you need to use a simple deinterlacer.
it is the line with "yadif" and it needs to load its DLL correctly. (remove the # sign and enter correct path)

however, it also could be merged with the complex deinterlacer scripts by a skilled coder.
 
Last edited:

Lonsdaleite

New Member
May 15, 2018
24
8
Any chance you might re-up the batch files? I'd like to use them as a reference for my encode workflow.
 

SamKook

Grand Wizard
Staff member
Super Moderator
Uploader
May 10, 2009
3,737
5,131
Done, looks like one of the previous forum update decided that an imouto picture was better than my script, lol.

You may also be interested in this(a much simpler script for simply re-encoding a video): https://www.akiba-online.com/threads/wmv-to-mkv-re-encoding-help.1082131/#post-2090539

You don't need anything remotely as complicated as this script to do things manually, you basically only have to make an avisynth script with the video processing you want and then use a few separate tools(mostly command line stuff) to process or encode your stuff. This is only to automate some of the process to save me some time. I really need to finish v 1.3 one of these days.
 

Kevin_san

Member
Nov 24, 2015
55
14
I can contribute an update. My technique is useful for very "difficult" ISOs, which means those where you find only crappy re-encodes, but easily the ISO itself.
So obviously, some contributors upload the ISO because one-click-encoding did not produce a nice result. QTGMC may still be better, but not always, and much slower.
This one tackles particular issues in typical idol NTSC videos.

I have an example, tuned for a particular video. I found some kernels that can do a better job than before.

Save the following as "MyProject.avs":
Code:
######################################################################
# First, you need DGIndex to prepare the d2v index file from the ISO.
# Then, here in the script, you need to correct the DLL paths for DGDecode and Yadif, and for the d2v path and video name.
# Occasionally, you will need a different DGIdex + DGDecode version.
# With avsproxy, you feed this into Avidemux 2.7.0 (caveat - connect, before opening the py project file).
# In the py or settings, set video length (A-B buttons), select quality (19-22), output format NTSC 16/9 (or 3/4),
#   and adjust color correction and border cutting in the plugins.
# For a different Avidemux version the py file is probably invalid, and you need to re-enter all my parameters manually.


#LoadPlugin("F:\programs\AviSynth+\plugins+\DGDecode154.dll")
#LoadPlugin("F:\programs\AviSynth+\plugins+\dgdecode58.dll")
LoadPlugin("D:\Programs\AVISynthPlus\plugins\DGDecode.dll")

MPEG2Source ("E:\_wrk\RinaTSDS\RinaNagai_TSDS-42048.d2v",cpu=5,moderate_h=45,moderate_v=55,info=2)
# if there are not MPEG2 artifacts and no ringing, set cpu=0

global rff=30000./1001. 
vv=last
pics   = cut(vv,1,06.598, 1,07.533)

global rff=60000./1001. # factor *2 for 60fps

tsl=int(2.0*rff/2.)+1 # duration of one pic
n=0

# noob hack for repeating each picture for half a second:
pics = Loop(pics,tsl,n+27,n+27)
pics = Loop(pics,tsl,n+26,n+26)
pics = Loop(pics,tsl,n+25,n+25)
pics = Loop(pics,tsl,n+24,n+24)
pics = Loop(pics,tsl,n+23,n+23)
pics = Loop(pics,tsl,n+22,n+22)
pics = Loop(pics,tsl,n+21,n+21)
pics = Loop(pics,tsl,n+20,n+20)
pics = Loop(pics,tsl,n+19,n+19)
pics = Loop(pics,tsl,n+18,n+18)
pics = Loop(pics,tsl,n+17,n+17)
pics = Loop(pics,tsl,n+16,n+16)
pics = Loop(pics,tsl,n+15,n+15)
pics = Loop(pics,tsl,n+14,n+14)
pics = Loop(pics,tsl,n+13,n+13)
pics = Loop(pics,tsl,n+12,n+12)
pics = Loop(pics,tsl,n+11,n+11)
pics = Loop(pics,tsl,n+10,n+10)
pics = Loop(pics,tsl,n+9,n+9)
pics = Loop(pics,tsl,n+8,n+8)
pics = Loop(pics,tsl,n+7,n+7)
pics = Loop(pics,tsl,n+6,n+6)
pics = Loop(pics,tsl,n+5,n+5)
pics = Loop(pics,tsl,n+4,n+4)
pics = Loop(pics,tsl,n+3,n+3)
pics = Loop(pics,tsl,n+2,n+2)
pics = Loop(pics,tsl,n+1,n+1)
pics = Loop(pics,tsl,n+0,n+0)



# -------- pre-blend kernels -------
C50d=  "5 -3  13 -9 121    0  0 -0 -3 -25   0  0  -4  -0  27    0  0   0  0 -4   0  0  0  0  2" #C
C60 =  "0 -0   0  0 112    0  0 -0 -0  -5   0  0  -0  -0  30    0  0   0  0 -3   0  0  0  0  8" #C
C61 =  "0 -0   0  0 112    0  0 -0  0  -6   0  0  -0  -0  10    0  0   0  0 -3   0  0  0  0  0" #C
C62 =  "0 -0   0  0   0    0  0  0  0   0   0  0 112   0   0    0  0  25  0 -0   0  0 -7  0  0" #C 
C62a=  "0 -0   0  0   0    0  0  0  0   0   0  0 112   0   0    0  0  17  0 -0   0  0 -4  0  0" #C
C62b=  "0 -0  -7  0   0    0  0 25  0   0   0  0 112   0   0    0  0   0  0 -0   0  0  0  0  0" #C
C62c=  "0 -0  -7  0   0    0  0 25  0   0   0  0  87   0   0    0  0   0  0 -0   0  0  0  0  0" #C
C62d=  "0 -0  -2  0   0    0  0  9  0   0   0  0 140   0   0    0  0  17  0 -0   0  0 -3  0  0" #C
C63 =  "0 -0   3  0   0    0  0  6  0   0   0  0 150   0   0    0  0  12  0 -0   0  0  3  0  0" #C 
C64 =  "0 -0   3  0   0    0  0  8  0   0   0  0 140   0   0    0  0  15  0 -0   0  0  3  0  0" #C
C64a=  "0 -0   2  0   0    0  0  4  0   0   0  0 140   0   0    0  0  11  0 -0   0  0  3  0  0" #C
C65 =  "0 -0  15  0   0    0  0 27  0   0   0  0 141   0   0    0  0  37  0 -0   0  0 27  0  0" #C

# C62a..d are examples that shift the pre-blending within the interlaced fields a bit up, or down, or both
# the purpose is to end up with less shimmering after yadif. also, it attempts to reduce the problem when
# interlaced program was sharpened field by field.
# C62b works quite often.
# The other kernels are less general and kind of worked with particular videos.


## ---------------------------------- do the pre-blend -----------------------------------
# --- switch on or off the following convolution and occasionally tweak kernel, according to results of deinterlacing.
# --- omit, if there is no interlacing.
CC=last
SeparateFields
ConvertToRGB32(matrix="PC.709",interlaced=false,chromaresample="lanczos4")

GeneralConvolution(0, C62d) # select kernel to use, specify its variable name here

ConvertToYV12(matrix="PC.709",interlaced=false,chromaresample="lanczos4")
Weave
MergeChroma(CC)
## ----------------------------- end of pre-blend convolution -------------


#-- Deinterlace Yadif -- delete this, when source is not actually interlaced i.e. shows combing without
Load_Stdcall_plugin("D:\Programs\AVISynthPlus\plugins\yadif.dll")
Yadif(mode=1,order=1)
AssumeFPS(60000,1001)


# -- after pre-blending and deinterlacing, we put together intro and still pictures.
vintro=cut(last,0,00.000, 1,06.582)
vmain=cut(last,1,08.000, 160,00.000)

#vintro = Yadif(vintro, mode=0,order=1)
#vintro = ChangeFPS(vintro,60000,1001)
#vmenu = ChangeFPS(vmenu,60000,1001)

pics=AssumeFPS(pics,60000,1001)
#last = pics + vintro + vmenu + vmain
last = vintro + pics + vmain  # you need to edit the audio according to this


# -----
global rff=60000./1001. # factor *2 for 60fps
o=0

 
#------------------------------------------- end cutting -------------------------------


AddBorders(4,4,4,8,$7F7F7F)
#AddBorders( clip clip, int left, int top, int right, int bottom [, int color ] )
ConvertToRGB32(matrix="PC.709",interlaced=false,chromaresample="lanczos4")
# default for this type of work: PC.709 = HDTV
# though most DVD = Rec601 !
# Rec.709 should be used when your source is HDTV (but fits some DVDs also)
# "Rec601" : Use 601 coefficients, scaled to TV range [16,235].
# "PC.601" : Use 601 coefficients, keep full range [0,255].


# -- symmetric kernels
C20 = "-2 0 3 0 -2   0 -1 -3 -1 0   2 -6 56 -6 2   0 -1 -3 -1 0   -1 0 3 0 -1" 
C21 = "-1 0 3 0 -1   0 -1 -3 -1 0   3 -5 56 -5 3   0 -1 -3 -1 0   -1 0 3 0 -1" 
C22 = "-1 0 3 0 -1   0 -1 -3 -1 0   3 -6 48 -6 3   0 -1 -3 -1 0   -1 0 3 0 -1" 
C23 = "-1 0 3 0 -1   0 -1 -3 -1 0   3 -5 48 -5 3   0 -1 -3 -1 0   -1 0 3 0 -1" 
C24 = " 0 0 3 0 -0   0 -1 -3 -1 0   4 -4 44 -4 4   0 -1 -3 -1 0    0 0 3 0  0" 

# -- asymmetric kernels
# -- select one of these kernels, ordered by increasing radius and impact:
#    C3.1 will do for most good quality DVDs with sufficient sharpness
C000 = "0 0 0 0 100   0 0 0 0 0   0 0 0 0 0  0 0 0 0 0   0 0 0 0 0" #dummy for asymmetric (to keep the shifting)

C31  = "3 -4  8 -10 112 0  0 -0 -4 -15   0  0 -6 -0  15   0  0  0  0 -5   0  0  0  0  0" #C3.1
C32  = "3 -3  9 -13 112 0  0 -0 -4 -15   0  0 -6 -0  15   0  0  0  0 -5   0  0  0  0  0" #C3.2 
C32a = "3 -3  9 -13 140 0  0 -0 -4 -15   0  0 -6 -0  15   0  0  0  0 -5   0  0  0  0  0" #C3.2a
C32c = "3 -3 11 -13 173 0  0 -0 -4 -10   0  0 -6 -0  15   0  0  0  0 -5   0  0  0  0  0" #C3.2c
C33  = "3 -3 10 -15 112 0  0 -0 -4 -12   0  0 -6 -0  14   0  0  0  0 -4   0  0  0  0  0" #C3.3 
C331 = "4 -5 14 -15 112 0  0 -0 -4 -12   0  0 -6 -0  14   0  0  0  0 -4   0  0  0  0  0" #C3.31 
C333 = "3 -5 17 -21 112 0  0 -0 -4 -13   0  0 -6 -0  14   0  0  0  0 -4   0  0  0  0  0" #C3.33
C335 = "3 -5 15 -21 112 0  0  1 -4 -13   0  0 -6  3  14   0  0  0  0 -4   0  0  0  0  0" #C3.33
C34  = "2 -5 12 -20 112 0  0 -0 -4 -10   0  0 -6 -0  12   0  0  0 -1 -3   0  0  0  0  1" #C3.4

C40  = "3 -5 17 -21 112  0  0 -0 -4 -13   0  0 -6 -0  15   0  0  0  0 -4   0  0  0  0  0" #C4.0
C40a = "3 -5 21 -23 112  0  0 -0 -4 -12   0  0 -8 -0  14   0  0  0  0 -4   0  0  0  0  0" #C4.0a
C40a1= "3 -9 21 -17 112  0  0  0 -4 -12   0  0 -8 -0  14   0  0  0  0 -4   0  0  0  0  0" #
C40a2= "3 -5 21 -17 112  0  0  2 -4 -12   0  0 -8  4  10   0  0  0 -1 -4   0  0  0  0  2" #
C40g ="5 -11 29 -25 130  0  0 -0 -3 -10   0  0 -5 -0  20   0  0  0  0 -6   0  0  0  0  2" #C4.0g
C40h ="5 -11 29 -25 130  0  0 -0 -3 -30   0  0 -5 -0  40   0  0  0  0 -8   0  0  0  0  3" #C4.0h
C40i ="3  -9 25 -25 130  0  0  2 -4 -25   0  0 -5  5  25   0  0  0 -1 -7   0  0  0  0  3" #C4.0i #######
C40i1="3  -9 25 -25 130  0  0  2 -4 -25   0  0 -5  5  15   0  0  0 -1 -7   0  0  0  0  3"
C40i2="3  -9 25 -25 130  0  0  2 -4 -41   0  0 -5  5  13   0  0  0 -1 -7   0  0  0  0  3" #
C40k ="3 -10 23 -28 123  0  0  2 -4 -25   0  0 -5  5  25   0  0  0 -1 -7   0  0  0  0  3" #C4.0k
C40k1="3 -10 25 -28 132  0  0  2 -4 -27   0  0 -5  5  23   0  0  0 -1 -7   0  0  0  0  3" #C4.0k1  #########
C40k2="3 -10 23 -31 119  0  0  2 -4 -25   0  0 -5  5  15   0  0  0 -1 -7   0  0  0  0  3" #C4.0k2
C40k3="3  -9 25 -31 131  0  0  2 -4 -27   0  0 -5  5  23   0  0  0 -1 -11  0  0  0  0  3" #C4.0k3
C40k4="3 -13 13 -31 123  0  0  2 -4 -31   0  0 -5  5  23   0  0  0 -1 -11  0  0  0  0  3" #C4.0k4
C40k5="3 -11 10 -31 123  0  0  2 -4 -31   0  0 -5  5  23   0  0  0 -1 -13  0  0  0  0  3" #C4.0k5
C40k6 ="4 -17 17 -27 137  0  0  2 -4 -31   0  0 -5  5  23   0  0  0 -1 -11  0  0  0  0  3" #C4.0k6
C40k7b="2 -5  17 -27 137  0  0  2 -5 -31   0  0 -4  4  27   0  0  0 -1  -9  0  0  0  0  3" #C4.0k7b ################
C40k7a="4 -7  17 -27 113  0  0  2 -4 -37   0  0 -5  5  27   0  0  0 -1 -11  0  0  0  0  3" #C4.0k7a ########
C40k8 ="3 -11 19 -37  89  0  0  2 -4 -13   0  0 -5  5   9   0  0  0 -1 -11  0  0  0  0  1" #C4.0k8  ##### if super blurred
C40k8a="3  -7 19 -37  89  0  0  2 -4 -13   0  0 -5  5   9   0  0  0 -1  -7  0  0  0  0  1" #C4.0k8a
C40k9 ="1  -7 11 -29  89  0  0  2 -4 -21   0  0 -5  5  21   0  0  0 -1  -7  0  0  0  0  3" #C4.0k9  ########
# C40 group has strong halo softening and anti-ringing compensation, but only for DVDs that have correct bandwidth limiting.
# on pixel-sharp and high-contrast vertical lines it will still show a ringing pattern.
# Use C40 for sources that would look awkwardly blurred after the reencoding, when they won't allow
# the stronger sharpening by the other kernels because of noise, grainy lines, and sharp halos/outlines.


C50  = "4 -4  6  -3 121  0  0 -0 -2 -25   0  0 -4 -0  30   0  0  0  0 -7   0  0  0  0  5" #C5.0 strong dehalo
C50b = "3 -5  3  -4 121  0  0 -0 -3 -15   0  0 -4 -0  15   0  0  0  0 -4   0  0  0  0  0" #C5.0b
C50d=  "5 -3  13 -9 121  0  0 -0 -3 -25   0  0 -4 -0  27   0  0  0  0 -4   0  0  0  0  2" #
C50g = "2 -8  14 -7 121  0  0 -0 -3 -10   0  0 -4 -0   1   0  0  0  0 -1   0  0  0  0  7" #
C50g1= "2 -8  14 -7 121  0  0  2 -4 -15   0  0 -4  4  11   0  0  0 -1 -5   0  0  0  0  2" #C5.0g1
C50g1a="2 -8  14 -7 121  0  0  2 -4 -21   0  0 -4  4  17   0  0  0 -1 -5   0  0  0  0  2" #C
C50g2= "2 -5  14 -7 121  0  0  2 -4 -15   0  0 -4  4  17   0  0  0 -1 -5   0  0  0  0  2" #C
C50g3= "2 -7  17 -3 121  0  0  2 -4 -15   0  0 -4  4  19   0  0  0 -1 -5   0  0  0  0  5" #C
C50g4= "2 -7  17 -3 121  0  0  2 -4 -12   0  0 -4  4  25   0  0  0 -1 -7   0  0  0  0  7" #C
C50g4a="2 -7  17 -3 121  0  0  2 -4 -17   0  0 -4  4  23   0  0  0 -1 -7   0  0  0  0  5" #C5.0g4a RinaH_TSDS-40277
C50g5= "3 -15 19 -1 121  0  0  2 -4  -1   0  0 -4  4  23   0  0  0 -1 -19  0  0  0  0  1" #C5.0g5
C50g5a="3 -15 19 -1 121  0  0  2 -4 -12   0  0 -4  4  23   0  0  0 -1 -7   0  0  0  0  1" #C5.0g5a
C50g5b="2 -15 23 -3 121  0  0  2 -5 -31   0  0 -4  4  37   0  0  0 -0 -3   0  0  0  0  6" #C5.0g5b ## strong dehalo
C50g5c="1 -11 19 -9 113  0  0  2 -5 -21   0  0 -4  4  11   0  0 -0 -1 -7   0  0  0  0  3" #C5.0g5c ########
C50g5d="1 -11 19 -9 113  0  0  2 -5 -31   0  0 -4  4  23   0  0 -0 -1 -9   0  0  0  0  5" #C5.0g5d ########
C50g5e="1 -11 19 -9 113  0  0  2 -5 -17   0  0 -4  4   3   0  0 -0 -1 -3   0  0  0  0  1" #C5.0g5e
C50g5f="1 -11 19 -9 113  0  0  2 -5 -17   0  0 -4  3  17   0  0 -0 -1 -5   0  0  0  0  5" #C5.0g5f
# Use C50 kernels if there is strong ringing plus outlining.




GeneralConvolution(0, C50g5f) # select kernel to use, specify its variable name here

ConvertToYV12(matrix="PC.709",interlaced=false,chromaresample="lanczos4")

#AssumeFPS(60000,1001)


CShft(last,-0.3,-0.66)  # correct chroma shift


Crop(0,6,-2,-2)
#Crop(clip clip, int left, int top, int -right, int -bottom [, bool align ] )

### ---- we are ready for output to Avidemux or some other encoder.
#   ---- (should denoise, upsize, and sharpen strongly on upsized format).



#--------------------------- helper funcs ---------------------------------------
function CShft(clip In, float X, float Y) {
w = In.Width()
h = In.Height()
Tmp = In.BlackmanResize(w, h, -X, -Y, w-X, h-Y, 5)
In = MergeChroma(In, Tmp)
return In}

function cut(clip In, int Mins, float secs, int Mins2, float secs2) {
tpos = 60.*Mins + secs
te =   60.*Mins2 + secs2
Outclp=Trim(In,int(rff*tpos)+1,-int(rff*(te-tpos))-1)
return Outclp}


save the following as "MyProject.py":
Code:
#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.loadVideo("::ADM_AVS_PROXY::")
adm.clearSegments()
adm.addSegment(0, 0, 8800000000)
adm.markerA = 0
adm.markerB = 7299561472
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=AQ=19", "general.threads=0", "general.preset=ultrafast", "general.tuning=film", "general.profile=baseline", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=True", "general.fake_interlaced=False", "level=-1", "vui.sar_height=27", "vui.sar_width=32", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250"
, "i_scenecut_threshold=40", "intra_refresh=False", "MaxBFrame=5", "i_bframe_adaptive=1", "i_bframe_bias=0", "i_bframe_pyramid=2", "b_deblocking_filter=True", "i_deblocking_filter_alphac0=1", "i_deblocking_filter_beta=0"
, "cabac=True", "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=True", "analyze.b_i4x4=True", "analyze.b_i8x8=True", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=True", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=3", "analyze.chroma_offset=0", "analyze.me_method=2", "analyze.me_range=20", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=8", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.100000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=13", "analyze.psy=True", "analyze.intra_luma=0", "analyze.inter_luma=0", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=8"
, "ratecontrol.qp_max=59", "ratecontrol.qp_step=8", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1"
, "ratecontrol.ip_factor=1.400000", "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.200000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
adm.addVideoFilter("fluxsmooth", "temporal_threshold=13", "spatial_threshold=0")
adm.addVideoFilter("addBorder", "left=0", "right=0", "top=0", "bottom=2")
adm.addVideoFilter("swscale", "width=1600", "height=968", "algo=2", "sourceAR=2", "targetAR=2")
adm.addVideoFilter("Sharpen", "luma=True", "chroma=True")
adm.addVideoFilter("Sharpen", "luma=True", "chroma=True")
adm.addVideoFilter("Sharpen", "luma=True", "chroma=True")
adm.addVideoFilter("colorYuv", "y_gain=0.000000", "y_bright=0.000000", "y_gamma=3.000000", "y_contrast=10.200000", "u_gain=0.000000", "u_bright=0.000000", "u_gamma=0.000000", "u_contrast=12.000000", "v_gain=0.000000", "v_bright=0.000000"
, "v_gamma=0.000000", "v_contrast=12.000000", "matrix=0", "levels=0", "opt=False", "colorbars=0", "analyze=1", "autowhite=False", "autogain=False")
adm.addVideoFilter("contrast", "coef=0.790000", "offset=40", "doLuma=False", "doChromaU=False", "doChromaV=True")
adm.addVideoFilter("swscale", "width=972", "height=652", "algo=2", "sourceAR=1", "targetAR=1")
adm.addVideoFilter("crop", "top=4", "bottom=8", "left=4", "right=8")
adm.audioClearTracks()
adm.setContainer("AVI", "odmlType=1")


For some encode, you will end up with 3/4 of the original file size, but you get 60fps that look extremely smooth, while eyes and skin will be brilliant, as far there is some detail at all to discover for the algorithm.
 
Last edited:

Kevin_san

Member
Nov 24, 2015
55
14
thx for taking a look, but the message is somewhat different.
convolution is extremely powerful, and with the pre-blending the yadif performs much better than it is known for, and results are definitely in a higher class than the average DVD transcode in the gravure blogs, except a well-tuned QTGMC,
but the very point here is to be fast and avoid QTGMC and still get away with something that looks natural and also a bit like classic CRT TV. (take a B&O).
the other thing is the preset is entirely irrelevant, the settings are in the details, I changed many, and they override the meta-preset, just the script is a very lazy copy. I care for a parameter only when it makes the output look bad.
analyze.noise_reduction and fluxsmooth play together quite well at moderate settings, the example video (which is a worst-case, overcompressed already at MPEG2) has excessive noise and ringing BTW, and after, that's almost gone.
the quality comes from empirical tuning, in that a number of components harmonize much better than expected. there are about 4 aspects that mitigate the yadif thing, and the cost is 1 or 2 convolutions (5x5) and two resizes. the purpose of the convolution though is fine-structure of lines, and the right way of sharpening that fits the particular video, therefor the library with the many kernels. with a better deinterlacer, the convo still improves detail and smoothness, and it will be required to make up for the wrong field-sharpening.
I was too lazy to put together the multithreading, but this should be trivial, then it should be done in 20 minutes.
 

Porni

Well-Known Member
Feb 29, 2012
349
324
@Kevin_san if you are interested in encoding speed, it's better to replace yadif with bwdif, the speed is the same, but the result will be better.
 
Last edited:

Kevin_san

Member
Nov 24, 2015
55
14
@Porni thx, I will look into this also.
so far, I have seen DVD sources react totally different on yadif.
e.g. if they have these horizontal extra black edges above white edges, then they allow pre-blending and will look better.
the issue is about how the digital camera creates a fake interlace, as for a real one it takes a CRT cam.
also, a lot of old stuff was recorded on tape initially, and from there comes a similar source of wrong sharpening within interlaced formats.
furthermore, QTGMC rarely removes such outlining artifacts. convolution does, with skillfully tuned kernels.
so what I'm suggesting is to play with the different kernels, no matter what interlacer is in use.

----
additionally, to the one example in my recent code posting, I might add hints for settings like the following.
these are legends, and it seems there are no decent renderings, and the DVDs don't play that well on cheap players. results are rewarding, becomes really a different animal.
FOEN-031 : C62b (pre-blending luma) + C50g5c; chroma shift (0.0 X, -1.3 Y)
->> py: quality=19, denoise=9, deblocking=1, LumaV=85, y_gamma=4.0, y_contrast=10.5, chroma contrast=10.5
MMA-050 : C62c + C40k6 (but for the making-of part, use C50g5c); chroma (-0.3 X, -0.66 Y);
->> py: quality=19, denoise=11, deblocking=1, LumaV=85, y_gamma=4.0, y_contrast=10.5, chroma contrast=10.5
LCDV-40540 : C40k7b; chroma (-0.3,-0.66)
->> py: quality=20, denoise=9

 
Last edited: