Trypetide
24th January 2016, 17:43
After lurking in here from time to time these last years, first post!! \o/
Please be gentle with me as I'm REALLY not into scripting and encoding from the get go, and not being a native English speaker can be challenging with all the technical stuff.
But I'll do my best to be concise.
-------------------------------
I thought it was time for me to "try" using filters and do some science. Newbie science of course, I'm using MeGui after all.
I still have difficulties to understand exactly what is what and why, in terms of all the settings available for x264, but by cross-checking others' encoded videos with MediaInfo (embedded into MPC-HC) and testing their settings, I still have found some good things.
But my actual problem is that -as a "detail" lover- keeping a maximum of grain when needed let me experience various situation where I didn't met a solution.
For once, what should be called... "Flickering"?
HERE (http://www.mirari.fr/ldnQ) is an example to illustrate my point.
In this case the problem is already present in the source material but really not as jarring, due to a largely bigger amount of bitrate of course. And obviously in the aim of downscaling, it could only become worse.
So in my search for a solution, I found a little script and was curious to try it and see if it was effective, as I saw it referenced many times as a used filter.
It's called GrainStabilize, you can find it HERE (http://www.mirari.fr/CdVH) or below:
###################################################
### ###
### GrainStabilize.avsi ###
### ###
### By 06_taro ( astrataro @ gmail.com ) ###
### ###
### v0.3 - 20 Feb 2012 ###
### ###
###################################################
###
###
### Temporal-only on-top grain stabilizer
### Only stabilize the difference ( on-top grain ) between source clip and spatial-degrained clip
###
### Support YV12 input only
###
###
### +-------------+
### | CHANGELOG |
### +-------------+
###
### v0.3 - 21 February 2012:
### - Use repair to remove temporal artifacts
###
### v0.2 - 20 February 2012:
### - Add "radius"
###
### v0.1 - 19 February 2012:
### - First script
###
###
### +----------------+
### | REQUIREMENTS |
### +----------------+
###
### -> RemoveGrain (v1.0)
### -> Masktools2 (v2a48)
###
###
### +-------+
### | USAGE |
### +-------+
###
### GrainStabilize(int temp, int radius, int adapt, bool luma, bool chroma, clip p)
###
###
### +-----------+
### | GENERAL |
### +-----------+
###
### temp [int, default: 50]
### ------------------
### Strength for temporal stabilization of on-top grain
### 0 = nervous
### ..
### 100 = calm
###
### radius [int, default: 1]
### ------------------
### Radius for temporal stabilization of on-top grain
###
### adapt [int, default: 64]
### -------------------
### Threshold for luma-adaptative grain
### -1 = off
### 0 = source
### ..
### 255 = invert
###
### rep [int, default: 3]
### ------------------
### Mode of repair, used to remove artifacts introduced by temporal soften
###
### luma, chroma
### ----------------------
### Whether to process luma/chroma plane or not
###
### p [clip, default = not set]
### ----------------------
### Define your own on-top grain removed clip instead of using internal RemoveGrain
### e.g., GrainStabilize( p=PNLM2(strength=32, wSpan=2, tSpan=0) )
###
###
Function GrainStabilize(clip input, int "temp", int "radius", int "adapt", int "rep", bool "luma", bool "chroma", clip "p"){
temp = Default(temp, 50)
radius = Default(radius, 1)
adapt = Default(adapt, 64)
rep = Default(rep, 3)
luma = Default(luma, true)
chroma = Default(chroma, true)
Assert( input.IsYV12, "GrainStabilize: only support YV12 colorspace!" )
Assert( temp>=0 && temp<=100, "GrainStabilize: invalid value for temp(0~100)!" )
Assert( adapt>=-1 && adapt<=255, "GrainStabilize: invalid value for adapt(-1~255)!" )
Y = luma ? 3 : 2
U = chroma ? 3 : 2
V = chroma ? 3 : 2
pre_nr = Defined(p) ? p : input.RemoveGrain(luma?20:0, chroma?20:0)
diff_nr = mt_makediff(input, pre_nr, Y=Y, U=U, V=V)
diff_sb = (luma&&chroma) ? diff_nr.TemporalSoften(radius, 255, 255, scenechange=255, mode=2)
\ : luma ? diff_nr.TemporalSoften(radius, 255, 0, scenechange=255, mode=2)
\ : chroma ? diff_nr.TemporalSoften(radius, 0, 255, scenechange=255, mode=2)
\ : diff_nr
diff_mg = (temp == 0) ? diff_nr
\ : (temp == 100) ? diff_sb
\ : (luma&&chroma) ? Merge(diff_nr, diff_sb, temp/100.)
\ : luma ? MergeLuma(diff_nr, diff_sb, temp/100.)
\ : chroma ? MergeChroma(diff_nr, diff_sb, temp/100.)
\ : diff_nr
stabled = rep==0 ? mt_adddiff(pre_nr, diff_mg, Y=Y, U=U, V=V)
\ : mt_adddiff(pre_nr, diff_mg, Y=Y, U=U, V=V).Repair(input, mode=rep)
Lmask = adapt==0 ? input.RemoveGrain(19, -1)
\ : adapt==255 ? input.mt_invert(U=1, V=1).RemoveGrain(19, -1)
\ : input.mt_lut("x "+string(adapt)+" - abs 255 * "+string(adapt)+" 128 - abs 128 + /", U=1, V=1).RemoveGrain(19, -1)
return adapt==-1 ? stabled
\ : mt_merge(input, stabled, Lmask, luma=chroma, Y=Y, U=U, V=V)
}
It's an .avsi file, and needs apparently "masktools2" and "RemoveGrain" to works properly.
In the process of learning about these things, I understood that an .avsi file can be placed into the "MeGUI\tools\avisynth_plugin" folder, and SHOULD be loaded automatically by MeGui. It wasn't the case for me so in the end, I preferred to load manually the stuff and after many tries checking the logs for every lines of error concerning the script, I did arrive to this:
Import("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\GrainStabilize.avsi")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\masktools2-25.dll")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\RemoveGrainSSE2.dll")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\RepairSSE2.dll")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\RSharpenSSE2.dll")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\lsmash\LSMASHSource.dll")
LWLibavVideoSource("G:\TEST.mkv")
GrainStabilize(temp=50, radius=1, adapt=64, rep=3, luma=true, chroma=true)
BUT with or without this filter command line, the video stay the same at the end: same size, same grain. Something is wrong somewhere but I'm at a loss in this case... I see it written into the logs at the "Avisynth input script" section but still, nothing is happening apparently. So what did I do wrong?
So.
(1) Can you help me make this filter works so that I can see what it does and if I can be contented with it?
(2) If GrainStabilize isn't worthy to be used as a filter, have you then any recommendation for this "keep as much grain as possible and stabilize it without destroying details" problem? Any filter(s) that can be useful in the same spirit as the one tried above?
(3) Did I need something extra if I want to use all that and do a downscale in the process? Other filters or changes in x264' settings?
Thanks in advance !!
[B]/!\Here are the settings I've used to encode the excerpt above:
Format profile : High 10@L5.1
Format settings, CABAC : Yes
Format settings, ReFrames : 16 frames
Bit rate : 7 400 Kbps
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 10 bits
Scan type : Progressive
Writing library : x264 core 148 r2638 7599210
Encoding settings :
cabac=1
ref=16
deblock=1:-1:-1
analyse=0x3:0x133
me=umh
subme=11
psy=1
psy_rd=1.00:0.00
mixed_ref=1
me_range=48
chroma_me=1
trellis=2
8x8dct=1
cqm=0
deadzone=21,11
fast_pskip=0
chroma_qp_offset=-4
threads=4
lookahead_threads=1
sliced_threads=0
nr=0
decimate=1
interlaced=0
bluray_compat=0
constrained_intra=0
bframes=16
b_pyramid=2
b_adapt=2
b_bias=0
direct=3
weightb=1
open_gop=0
weightp=2
keyint=250
keyint_min=23
scenecut=40
intra_refresh=0
rc_lookahead=60
rc=2pass
mbtree=1
bitrate=7400
ratetol=1.0
qcomp=0.60
qpmin=10
qpmax=81
qpstep=4
cplxblur=20.0
qblur=0.5
vbv_maxrate=240000
vbv_bufsize=240000
nal_hrd=none
filler=0
ip_ratio=1.40
aq=1:1.10
Please be gentle with me as I'm REALLY not into scripting and encoding from the get go, and not being a native English speaker can be challenging with all the technical stuff.
But I'll do my best to be concise.
-------------------------------
I thought it was time for me to "try" using filters and do some science. Newbie science of course, I'm using MeGui after all.
I still have difficulties to understand exactly what is what and why, in terms of all the settings available for x264, but by cross-checking others' encoded videos with MediaInfo (embedded into MPC-HC) and testing their settings, I still have found some good things.
But my actual problem is that -as a "detail" lover- keeping a maximum of grain when needed let me experience various situation where I didn't met a solution.
For once, what should be called... "Flickering"?
HERE (http://www.mirari.fr/ldnQ) is an example to illustrate my point.
In this case the problem is already present in the source material but really not as jarring, due to a largely bigger amount of bitrate of course. And obviously in the aim of downscaling, it could only become worse.
So in my search for a solution, I found a little script and was curious to try it and see if it was effective, as I saw it referenced many times as a used filter.
It's called GrainStabilize, you can find it HERE (http://www.mirari.fr/CdVH) or below:
###################################################
### ###
### GrainStabilize.avsi ###
### ###
### By 06_taro ( astrataro @ gmail.com ) ###
### ###
### v0.3 - 20 Feb 2012 ###
### ###
###################################################
###
###
### Temporal-only on-top grain stabilizer
### Only stabilize the difference ( on-top grain ) between source clip and spatial-degrained clip
###
### Support YV12 input only
###
###
### +-------------+
### | CHANGELOG |
### +-------------+
###
### v0.3 - 21 February 2012:
### - Use repair to remove temporal artifacts
###
### v0.2 - 20 February 2012:
### - Add "radius"
###
### v0.1 - 19 February 2012:
### - First script
###
###
### +----------------+
### | REQUIREMENTS |
### +----------------+
###
### -> RemoveGrain (v1.0)
### -> Masktools2 (v2a48)
###
###
### +-------+
### | USAGE |
### +-------+
###
### GrainStabilize(int temp, int radius, int adapt, bool luma, bool chroma, clip p)
###
###
### +-----------+
### | GENERAL |
### +-----------+
###
### temp [int, default: 50]
### ------------------
### Strength for temporal stabilization of on-top grain
### 0 = nervous
### ..
### 100 = calm
###
### radius [int, default: 1]
### ------------------
### Radius for temporal stabilization of on-top grain
###
### adapt [int, default: 64]
### -------------------
### Threshold for luma-adaptative grain
### -1 = off
### 0 = source
### ..
### 255 = invert
###
### rep [int, default: 3]
### ------------------
### Mode of repair, used to remove artifacts introduced by temporal soften
###
### luma, chroma
### ----------------------
### Whether to process luma/chroma plane or not
###
### p [clip, default = not set]
### ----------------------
### Define your own on-top grain removed clip instead of using internal RemoveGrain
### e.g., GrainStabilize( p=PNLM2(strength=32, wSpan=2, tSpan=0) )
###
###
Function GrainStabilize(clip input, int "temp", int "radius", int "adapt", int "rep", bool "luma", bool "chroma", clip "p"){
temp = Default(temp, 50)
radius = Default(radius, 1)
adapt = Default(adapt, 64)
rep = Default(rep, 3)
luma = Default(luma, true)
chroma = Default(chroma, true)
Assert( input.IsYV12, "GrainStabilize: only support YV12 colorspace!" )
Assert( temp>=0 && temp<=100, "GrainStabilize: invalid value for temp(0~100)!" )
Assert( adapt>=-1 && adapt<=255, "GrainStabilize: invalid value for adapt(-1~255)!" )
Y = luma ? 3 : 2
U = chroma ? 3 : 2
V = chroma ? 3 : 2
pre_nr = Defined(p) ? p : input.RemoveGrain(luma?20:0, chroma?20:0)
diff_nr = mt_makediff(input, pre_nr, Y=Y, U=U, V=V)
diff_sb = (luma&&chroma) ? diff_nr.TemporalSoften(radius, 255, 255, scenechange=255, mode=2)
\ : luma ? diff_nr.TemporalSoften(radius, 255, 0, scenechange=255, mode=2)
\ : chroma ? diff_nr.TemporalSoften(radius, 0, 255, scenechange=255, mode=2)
\ : diff_nr
diff_mg = (temp == 0) ? diff_nr
\ : (temp == 100) ? diff_sb
\ : (luma&&chroma) ? Merge(diff_nr, diff_sb, temp/100.)
\ : luma ? MergeLuma(diff_nr, diff_sb, temp/100.)
\ : chroma ? MergeChroma(diff_nr, diff_sb, temp/100.)
\ : diff_nr
stabled = rep==0 ? mt_adddiff(pre_nr, diff_mg, Y=Y, U=U, V=V)
\ : mt_adddiff(pre_nr, diff_mg, Y=Y, U=U, V=V).Repair(input, mode=rep)
Lmask = adapt==0 ? input.RemoveGrain(19, -1)
\ : adapt==255 ? input.mt_invert(U=1, V=1).RemoveGrain(19, -1)
\ : input.mt_lut("x "+string(adapt)+" - abs 255 * "+string(adapt)+" 128 - abs 128 + /", U=1, V=1).RemoveGrain(19, -1)
return adapt==-1 ? stabled
\ : mt_merge(input, stabled, Lmask, luma=chroma, Y=Y, U=U, V=V)
}
It's an .avsi file, and needs apparently "masktools2" and "RemoveGrain" to works properly.
In the process of learning about these things, I understood that an .avsi file can be placed into the "MeGUI\tools\avisynth_plugin" folder, and SHOULD be loaded automatically by MeGui. It wasn't the case for me so in the end, I preferred to load manually the stuff and after many tries checking the logs for every lines of error concerning the script, I did arrive to this:
Import("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\GrainStabilize.avsi")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\masktools2-25.dll")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\RemoveGrainSSE2.dll")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\RepairSSE2.dll")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\avisynth_plugin\GRAINSTABILIZE\RSharpenSSE2.dll")
LoadPlugin("D:\#\#VIDEO ET ENCO\MeGUI_2418_x86\tools\lsmash\LSMASHSource.dll")
LWLibavVideoSource("G:\TEST.mkv")
GrainStabilize(temp=50, radius=1, adapt=64, rep=3, luma=true, chroma=true)
BUT with or without this filter command line, the video stay the same at the end: same size, same grain. Something is wrong somewhere but I'm at a loss in this case... I see it written into the logs at the "Avisynth input script" section but still, nothing is happening apparently. So what did I do wrong?
So.
(1) Can you help me make this filter works so that I can see what it does and if I can be contented with it?
(2) If GrainStabilize isn't worthy to be used as a filter, have you then any recommendation for this "keep as much grain as possible and stabilize it without destroying details" problem? Any filter(s) that can be useful in the same spirit as the one tried above?
(3) Did I need something extra if I want to use all that and do a downscale in the process? Other filters or changes in x264' settings?
Thanks in advance !!
[B]/!\Here are the settings I've used to encode the excerpt above:
Format profile : High 10@L5.1
Format settings, CABAC : Yes
Format settings, ReFrames : 16 frames
Bit rate : 7 400 Kbps
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 10 bits
Scan type : Progressive
Writing library : x264 core 148 r2638 7599210
Encoding settings :
cabac=1
ref=16
deblock=1:-1:-1
analyse=0x3:0x133
me=umh
subme=11
psy=1
psy_rd=1.00:0.00
mixed_ref=1
me_range=48
chroma_me=1
trellis=2
8x8dct=1
cqm=0
deadzone=21,11
fast_pskip=0
chroma_qp_offset=-4
threads=4
lookahead_threads=1
sliced_threads=0
nr=0
decimate=1
interlaced=0
bluray_compat=0
constrained_intra=0
bframes=16
b_pyramid=2
b_adapt=2
b_bias=0
direct=3
weightb=1
open_gop=0
weightp=2
keyint=250
keyint_min=23
scenecut=40
intra_refresh=0
rc_lookahead=60
rc=2pass
mbtree=1
bitrate=7400
ratetol=1.0
qcomp=0.60
qpmin=10
qpmax=81
qpstep=4
cplxblur=20.0
qblur=0.5
vbv_maxrate=240000
vbv_bufsize=240000
nal_hrd=none
filler=0
ip_ratio=1.40
aq=1:1.10