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

SCDetect v0.3 - 检测scene change并输出为文件的脚本

SCDetect:
检测scene change,并且输出scene change frames到外部文件。
需要YV12输入,以及MVTools2。
用法:SCDetect(scFile, thSCD1, thSCD2, mDiff, pel, search, searchparam, preblur, info)
一般来说一个SCDetect()就行了
然后avs2avi之类的工具空跑一遍就能出list了

参数说明:
scFile [string, Default="scFile.log"]:指定输出scene change frames list的文件名,为"nul"时为不输出
thSCD1 [int, Default=360]:指定对于单个block的scene change检测阈值,越高则被判定为scene change的block越少
thSCD2 [int(0-255), Default=120]:指定单帧被判定为scene change帧的阈值,实际上是指有一帧内多少的scene change block时将该帧判定为scene change frame,255时为100%,130时为51%,依次类推
mDiff [float, Default=2.5]:指定means difference的阈值,越高则判定为scene change的frame越少
pel [int(1,2,4), Default=2]
search [int(0-7), Default=4]
searchparam [int, Default=2]:这三个详见脚本内文档或者MVTools2的文档,反正就是Motion estimation的各种参数,其实对scene change判定结果本身的影响并不算大,而且列出来的话太多了,所以懒得写了……
preblur [bool, Default=true]:是否在检测前先blur以降低grain的影响
info [bool, Default=false]:是否在画面上显示检测信息"Scene change: true/false"

---------------------------------------------------------------------------------

FFTypeList:
只能和FFVideoSource/FFmpegSource2的源滤镜配合使用,输出源文件的frame type list
格式同x264的qpfile,不过没有qp,只有frame number和frame type
例如
233 I
304 I
用法:FFTypeList(tlFile, full)
tlFile [string, Default="FFTypeList.log"]:指定输出的文件名,默认为"FFTypeList.log"
full [bool, Default=false]:输出的帧类别,默认只输出I/i帧,当full=true的时候输出包含B/P等全部帧,例如
0 I
1 P
2 B
3 P
4 P
5 B
6 B
7 I
因为有FFInfo的存在所以就不加info参数了

---------------------------------------------------------------------------------

下载:SCDetect_v0.3.rar
或者保存下面脚本为avsi[syntax lang="avisynth" lines="f" filename="SCDetect.avsi"]###################################################
### ###
### Scene change detect script ###
### ###
### by 06_taro - astrataro@gmail.com ###
### ###
### v0.3 - 12 February 2012 ###
### ###
###################################################
###
### SCDetect - Detect scene change and output scene change frames to a file.
###
### FFTypeList - Output frame type list to a new file.
### The list has exactly the same format as x264's qpfile, except for no qp value is given.
###
### +-----------+
### | CHANGELOG |
### +-----------+
###
### v0.3 - 12 February 2012:
### - Add means difference calculation, more accurate on flicking.
###
### v0.2 - 28 December 2011:
### - Crop before calculate whether the scene change mask is a scene change frame or not,
### and replace LumaDifference(BlankClip) with YPlaneMax, might be faster.
### - Tweak parameters of thSCD1 and thSCD2 back to MVTools2's default. The parameters in v0.1 is too weak to detect non-grain clips.
### - Add FFTypeList to output frame types of source clip. Can be used only with FFVideoSource or FFmpegSource2.
###
### v0.1 - 28 December 2011:
### - First release.
###
### +----------------+
### | REQUIREMENTS |
### +----------------+
###
### SCDetect:
### YV12 input
### -> RemoveGrain
### -> MVTools2
###
### FFTypeList:
### FFVideoSource or FFmpegSource2 as source filter
###
### +-------+
### | USAGE |
### +-------+
###
### SCDetect(scFile, thSCD1, thSCD2, mDiff, pel, search, searchparam, info)
### ----------------------
###
### scFile [string, Default="scFile.log"]
### -- The log file of scene change frames, do not output log file when scFile is set to "nul"
###
### thSCD1 [int, Default=360]
### -- Threshold which decides whether a block has changed between the previous frame and the current one.
### -- Raising it will lower the number of blocks detected as changed. It may be useful for noisy or flickered video.
### -- Read MVTools2 documents for more details.
###
### thSCD2 [int(0-255), Default=120]
### -- Threshold which sets how many blocks have to change for the frame to be considered as a scene change.
### -- 0 meaning 0 %, 255 meaning 100 %.
###
### mDiff [float, Default=2.5]
### -- Means difference threshold.
###
### pel [int(1,2,4), Default=1]
### -- It is the accuracy of the motion estimation. Value can only be 1, 2 or 4.
### -- 1 means a precision to the pixel.
### -- 2 means a precision to half a pixel.
### -- 4 means a precision to quarter a pixel.
### -- Larger value is more accurate but slower, and not always better due to big level scale step.
###
### search [int(0-7), Default=4]
### searchparam [int, Default=2]
### -- Search decides the type of search at every level, and searchparam is an additional parameter (step, radius) for this search:
### -- search = 0 : 'OneTimeSearch'.
### searchparam is the step between each vectors tried ( if searchparam is superior to 1, step will be progressively refined ).
### -- search = 1 : 'NStepSearch'.
### N is set by searchparam. It's the most well known of the MV search algorithm.
### -- search = 2 : Logarithmic search, also named Diamond Search.
### searchparam is the initial step search, there again, it is refined progressively.
### -- search = 3 : Exhaustive search.
### searchparam is the radius (square side is 2*radius+1). It is slow, but it gives the best results, SAD-wise.
### -- search = 4 : Hexagon search.
### searchparam is the range. (similar to x264).
### -- search = 5 : Uneven Multi Hexagon (UMH) search.
### searchparam is the range. (similar to x264).
### -- search = 6 : pure Horizontal exhaustive search.
### searchparam is the radius (width is 2*radius+1).
### -- search = 7 : pure Vertical exhaustive search.
### searchparam is the radius (height is 2*radius+1).
###
### preblur [bool, Default=true]
### -- Blurring before scene change detection on the clip to avoid affected by grain or not.
###
### info [bool, Default=false]
### -- Overlay the result of scene change detection on the clip or not.
###
###
###
### FFTypeList(tlFile, full)
### ----------------------
###
### tlFile [string, Default="FFTypeList.log"]
### -- The log file of frame type list.
###
### full [bool, Default=false]
### -- Generates list of only I frames or all frames.
###

Function SCDetect(clip c, string "scFile", int "thSCD1", int "thSCD2", float "mDiff", int "pel", int "search", int "searchparam", bool "preblur", bool "info"){

scFile = Default(scFile, "scFile.log")
thSCD1 = Default(thSCD1, 360)
thSCD2 = Default(thSCD2, 120)
mDiff = Default(mDiff, 2.5)
pel = Default(pel, 1)
search = Default(search, 4)
searchparam = Default(searchparam, 2)
preblur = Default(preblur, true)
info = Default(info, false)

last = preblur ? c.RemoveGrain(20, 0) : c

Assert( IsYV12 , "SCDetect needs YV12 input!" )

super = MSuper(pel=pel, chroma=false)
vector = super.MAnalyse(pelsearch=pel, search=search, searchparam=searchparam, chroma=false)
global scMask = MSCDetection(vector, thSCD1=thSCD1, thSCD2=thSCD2).Crop(0,0,16,16)

global SC_mD = mDiff
global mean = Histogram(mode="Color").Crop(width+64, 64, 128, 128)

SCTrue = c.Subtitle("Scene change: true" )
SCFalse = c.Subtitle("Scene change: false")

info ? ConditionalFilter( last, SCTrue, SCFalse, "boolSC", "==", "true" )
\ : nop
FrameEvaluate( """global boolSC =
\ (
\ ( scMask.YPlaneMax == 255 ) &&
\ (
\ (mean.YDifferenceFromPrevious > SC_mD*3) ||
\ (
\ (mean.YDifferenceFromPrevious > SC_mD) &&
\ (mean.YDifferenceFromPrevious > (mean.YDifferenceToNext+mean.loop(0, 0, -1).YDifferenceToNext+mean.loop(0, 0, 1).YDifferenceToNext)/1.2)
\ )
\ )
\ )""" )

( scFile != "nul" ) ? WriteFileStart( scFile, """ "# Scene change frame list" """ ).WriteFileIf( scFile, "boolSC==true", "current_frame" ) : nop

return last
}

Function FFTypeList(clip c, string "tlFile", bool "full"){

tlFile = Default(tlFile, "FFTypeList.log")
full = Default(full, false)
last = c

full ? WriteFileIf(tlFile, "true", "current_frame", "chr(32)+chr(FFPICT_TYPE)", append=false)
\ : WriteFileIf(tlFile, """ chr(FFPICT_TYPE)=="I" """, "current_frame", "chr(32)+chr(FFPICT_TYPE)", append=false)
}
[/syntax]
上次由 06_taro 在 2017-08-25 11:59,总共编辑 9 次。
つまんねー事聞くなよ!

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日。
头像
-o-o-304-o-o-
超级版主
帖子: 640
注册时间: 2010-10-10 20:00
来自: US
联系: 网站

Re: SCDetect v0.1 - 检测scene change并输出为文件的脚本

\拜谢taro大/
► 显示剧情透露 En Taro 06!Taro Pie NC Fanclub project始动!聊天用Q群开放中
► 显示剧情透露 胸中有万言,退敌无一策,是谓书生误国"
► 显示剧情透露 前辈们的信念
► 显示剧情透露 妇联招新广告,走过路过可以看看撒
► 显示剧情透露 香芋派,后期菊苣们的一致选择
► 显示剧情透露 众菊苣喜评香芋派
► 显示剧情透露 聊天用工具
cunhan
核心会员
核心会员
帖子: 214
注册时间: 2010-09-20 22:09

Re: SCDetect v0.1 - 检测scene change并输出为文件的脚本

哦哦,领走用来辅助修正BD Chapters MOD的qpfile输出。
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

Re: SCDetect v0.2 - 检测scene change并输出为文件的脚本

0.2增加了FFTypeList,当输入的源滤镜为FFVideoSource/FFmpegSource2时可以输出frame type list,HD视频用mvtools2也许比解码速度慢,村汉可以试试拿这个来做BD chapters MOD的修正(其实直接Aegisub/VFRHelper出keyframes list应该是最快的……)

顺便SCDetect修改了一下scene change mask的处理方式,也许会快些。
つまんねー事聞くなよ!

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日。
cunhan
核心会员
核心会员
帖子: 214
注册时间: 2010-09-20 22:09

Re: SCDetect v0.2 - 检测scene change并输出为文件的脚本

aegisub/vfrhelper只能出压好的成品的keyframes list吧,但是qpfile的修正对象是经过avs处理后帧数变化了的clip。所以,SCDetect这个一遍分析的过程是少不了的。

让脚本吃scfile来修正的功能是做好了,然后突然想到chapter项的时间戳也要对应修正,好麻烦 OTL
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

Re: SCDetect v0.2 - 检测scene change并输出为文件的脚本

经过avs之后帧数变化导致timestamp都变化的话就没办法了……不过那样的话其实需要有scfile+framerate(cfr)/tcfile(vfr)才能搞定了,requirement好多……
つまんねー事聞くなよ!

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日。
histamine
帖子: 85
注册时间: 2010-09-23 20:07

Re: SCDetect v0.2 - 检测scene change并输出为文件的脚本

scenecut检测用x264就行了

比如
x264 --preset ultrafast --scenecut 40 --log-level debug --output NUL xxx.avs 2>x264-debug.txt
(调整scenecut参数来得到合适的结果)

然后把x264-debug.txt中所有"scene cut at %d Icost:%d Pcost:%d ratio:%.4f bias:%.4f gop:%d (imb:%d pmb:%d)" 字符串中的帧号提取出来

perl -lne 'print $1 if /scene cut at (\d+)/' >scFile.txt <x264-debug.txt
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

Re: SCDetect v0.2 - 检测scene change并输出为文件的脚本

本来就是x264的准确度更高……
其实如果已经x264 1pass跑了一遍的话我一般是拿这个shell脚本批处理的……

代码: 全选

#!/bin/sh

for arg in $*; do
  grep "scene cut at" < "$arg" | awk '{print $6}' > "$arg.scFile.log"
done
つまんねー事聞くなよ!

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日。
histamine
帖子: 85
注册时间: 2010-09-23 20:07

Re: SCDetect v0.2 - 检测scene change并输出为文件的脚本

x264 ultrafast速度飞快(动画如果用scenecut=40,可能会漏掉一些scenecut,一般要调高一些)
建议SCDetect脚本中Mvtools2只计算Y平面就够了(chroma=false)

其实也可以借鉴下下yatta的SCXvid,写一个SCX264 {:cat_16}
利用scenecut帧号可以将整部片子按照场景分段,方便分段处理
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

Re: SCDetect v0.3 - 检测scene change并输出为文件的脚本

v0.3

aki菊苣提到用means和variance来计算scene change,而完全抛弃计算量大而且繁琐的motion estimate的想法
前者很容易实现,现在就用在ScDetect.avsi里面辅助ME,对于闪烁画面的误检有很大降低,因此原来ME的几个参数略有放宽。
后者因为暂时目前还没有直接或者间接返回DCT后DC分量的现成滤镜,所以暂时不搞(死……
つまんねー事聞くなよ!

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”