版面规则
提问时请注意:尽量详细描述操作过程、AVS脚本内容等,最好能写出片名,只贴图有时无法看出问题原因。
提示:发布原创内容请尽量使用附件上传。使用网盘会出现过期失效的问题,请注意。
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

NCPP.avsi - 利用NCOP/ED与正片OP/ED对背景与credit分别处理的脚本

2012-02-09 1:55

有时候渣制作的片子有OP中背景缟缟,文字fade interlaced,而NCOP中则是与OP相同pattern的缟缟,这时我们会希望对背景做destripe,对文字做deint。但是很多时候OP的画面很难单独把字幕部分mask然后merge,于是我们可以通过取OP与NCOP的差值得到文字(credit),然后将credit单独做deint,再覆盖到单独做完destripe的NCOP上。

其他类似情况也可以类似处理,譬如背景deint,文字不动,等等。

本脚本就是用于完成这个工作的。
NCPP(clip input, clip nc, clip "pp", string "diffpp", int "repair")
需要三个clip,
一个是原始的OP,
一个是原始的NCOP,
一个是NCOP做过处理后的结果pp。
例如背景要去缟而credit可以不动的情况,用NCPP(OP, NCOP, pp),就可以将未处理的credit覆盖到处理过的NCOP上,从而得到成品。如图示(感谢四妹试验sample)

原始OP:
图片

原始NCOP:
图片

处理后的NCOP:
图片

最终merge结果:
图片

来看一个实例:
[syntax lang="avisynth" lines="f"]OP = AviSource("OP.avi")
NCOP = AviSource("NCOP.avi")
pp = NCOP.Destripe(360, 4, 3, 3).evenly720(3, 30).Spline64Resize(NCOP.width, NCOP.height)
NCPP(OP, NCOP, pp, "vinverse.Spline36Resize(1920, 1080, 0, -0.5)", 2)[/syntax]
这样就是背景destripe,而字幕部分vinverse的效果。

几个注意事项:
1. 本脚本需要OP/ED与NCOP/NCED有相同的背景画面。
2. 有些pp处理会导致画面被移动,譬如destripe。根据情况可以采用将diff进行同样的移动,或者将pp的画面移回去。前者用法可以参加上面一个例子里的diffpp参数,后者可以直接在定义pp的时候处理,譬如pp=NCOP.Destripe().Spline36Resize(width, height, 0, 0.5)这样。
3. NCOP处理前后,线条边缘常常会出现变化,譬如解缟前线条混乱,占了3pix,而解缟后变成了2pix,直接add diff的话会出现类似jerk的问题。所以本脚本默认开启repair来去除这种add diff过程导致的问题。repair参数的意义就是使用repair时的mode,0为不使用repair处理(如果同时不定义pp的话,默认pp直接取input,得到的结果应该和原始OP完全相同)。默认是和repair里mode一样为2,需要的话自己tweak参数。


下载碗柜
或者保存下面的脚本:
[syntax lang="avisynth" lines="f" filename="NCPP.avsi"]### Original by 06_taro: http://pastebin.com/L1SAjpYZ
### Script by ssnake & 06_taro
### Tested by 454790560
###
### This script is used in such cases:
### OP/NCOP (and of course EDs) are interlaced/cross-upconved in background, need pp,
### while credits (subtitles) need other pp method, or are progressive.
###
### It requires two clips ("input"/"nc") with same time-line, resolution, and other properties.
### You may use "OP" and "NCOP" for this two clips (in order).
### And a clip of "pp" should be given, which is filtered nc clip.
###
### If destripe moves the clip, say, by 0.5 pixel, move it back (in "pp"),
### or shift diff clip to adjust to pped clip using "diffpp" parameter.
###
### Sometimes pp may changed pixels of edges, resulting in artifacts after mt_adddiff.
### In that case, use "repair" ( indicates "mode" of repair, 0 to disable, 2 by default) to remove them.
###
### e.g.
### OP = AviSource("OP.avi")
### NCOP = AviSource("NCOP.avi")
### pp = NCOP.Destripe(360, 4, 3, 3).evenly720(3, 30).Spline64Resize(NCOP.width, NCOP.height)
### NCPP(OP, NCOP, pp, "vinverse.Spline36Resize(1920, 1080, 0, -0.5)", 2)
###

function NCPP(clip input, clip nc, clip "pp", string "diffpp", int "repair")
{
repair = default(repair, 2)

### get clean credit
diff = mt_makediff(input, nc, u=3, v=3) ### "x y - 128"
diff_Overflow = mt_lutxy(input, nc, "x y - 127 -", u=3, v=3) ### "x y - 128 + 255 -"
diff_Underflow = mt_lutxy(input, nc, "y x - 128 -", u=3, v=3) ### "0 x y - 128 + -"

### process diff
diff = Defined(diffpp) ? eval("diff."+diffpp) : diff
diff_Overflow = Defined(diffpp) ? eval("diff_Overflow."+diffpp) : diff_Overflow
diff_Underflow = Defined(diffpp) ? eval("diff_Underflow."+diffpp) : diff_Underflow

### process interlaced/cross-upconved background
pped = Defined(pp) ? pp : input

### add back credit
adb = pped.mt_adddiff(diff, u=3, v=3).mt_lutxyz(diff_Overflow, diff_Underflow, "x y + z -", u=3, v=3)

rep = ( repair!=0 ) ? adb.Repair(input, repair) : adb

return rep
}
[/syntax]

PS. 其实方法几个月前就写出来了,今天修掉了一个数值溢出的问题,顺便改进了一下。本来因为只用来处理特殊情况所以懒得封装成函数,反正一般ripper不会这么蛋疼吧。感谢ssnake菊苣写成avsi,于是就顺便放出来了。如果上面说的看不懂就Ctrl+W好了…… {:cat_1}
つまんねー事聞くなよ!

I, personally, for me, believe (obviously sometimes) that my OS choice is right. That's me. I'm not telling you that you should believe it. Learn the facts, and the origins behind the facts, and make up your own damn mind. That's why you have one. (source)

Follow me: @06_taro

304——
为纪念伟大的宇宙史上最强压制304先生,联合国教科文组织决定,将每年的第304天,即平年的10月31日或者闰年的10月30日,定为世界304日。

回到 “AviSynth”