お前らのショボイAvisynthスクリプト貼ってください

このエントリーをはてなブックマークに追加
230名無しさん@編集中
需要は不明ですがアスペクト比を狂わせずにクロップする関数です。

function AspectCrop(clip "clip", int "left", int "top", int "right", int "bottom",
\int "minwidth", int "minheight", int "aspectx", int "aspecty",
\string "clrfmt", bool "interlaced", bool "cutOff", bool "debug")
{
left = default(left, 0)
top = default(top, 0)
right = Abs(default(right, 0))
bottom = Abs(default(bottom, 0))
minWidth = default(minWidth, 0)
minHeight = default(minHeight, 0)
aspectx = default(aspectx, 711)
aspecty = default(aspecty, 485)
clrfmt = default(clrfmt, "")
interlaced = default(interlaced, true)
cutOff = default(cutOff, true)
debug = default(debug, false)

unitx = (clip.IsYV12 || clip.IsYUY2 || clrfmt == "YV12" || clrfmt == "YUY2") ? 2 : 1
unity = (interlaced || clip.IsYV12 || clrfmt == "YV12") ? 2 : 1
rleft = Floor((left + (cutOff ? unitx - 1 : 0)) / unitx) * unitx
rtop = Floor((top + (cutOff ? unity - 1 : 0)) / unity) * unity
rright = Floor((right + (cutOff ? unitx - 1 : 0)) / unitx) * unitx
rbottom = Floor((bottom + (cutOff ? unity - 1 : 0)) / unity) * unity
w = clip.Width - rleft - rright
h = clip.Height - rtop - rbottom
wy = w * aspecty
hx = h * aspectx
amul = cutOff ? (wy < hx ? wy : hx) : (wy < hx ? hx : wy)
231名無しさん@編集中:03/12/03 19:46
rw = amul / aspecty
rh = amul / aspectx
rw = Floor((rw + (cutOff ? 0 : 3)) / 4) * 4
rh = Floor((rh + (cutOff ? 0 : 1)) / 2) * 2
offset = (w - rw) / 2
rleft = Floor((left + offset) / unitx) * unitx
rright = clip.Width - rw - rleft
offset = (h - rh) / 2
rtop = Floor((top + offset) / unity) * unity
rbottom = clip.Height - rh - rtop

clip = clip.Crop(rleft, rtop, -rright, -rbottom)
clip = debug ? clip.SubTitle("unitx : " + String(unitx), 10, 20) : clip
clip = debug ? clip.SubTitle("unity : " + String(unity), 10, 40) : clip
clip = debug ? clip.SubTitle("left : " + String(rleft), 10, 60) : clip
clip = debug ? clip.SubTitle("top : " + String(rtop), 10, 80) : clip
clip = debug ? clip.SubTitle("right : " + String(rright), 10, 100) : clip
clip = debug ? clip.SubTitle("bottom : " + String(rbottom), 10, 120) : clip
clip = debug ? clip.SubTitle("width : " + String(clip.Width), 10, 140) : clip
clip = debug ? clip.SubTitle("height : " + String(clip.Height), 10, 160) : clip
return clip
}
232名無しさん@編集中:03/12/03 19:48
一部抜けてました、申し訳ありません。
>>230>>231の間に以下の文を挿入してください。

wy = minwidth * aspecty
hx = minheight * aspectx
amul = amul < wy ? wy : (amul < hx ? hx : amul)
wy = clip.Width * aspecty
hx = clip.Height * aspectx
amul = amul > wy ? wy : (amul > hx ? hx : amul)
233名無しさん@編集中:03/12/03 19:59
使い方について。
Crop(left, top, -right, -bottom)はそのままAspectCrop(left, top, -right, -bottom)で使えます。
left : 切り抜く左端の長さ。デフォルトは0です
top : 切り抜く上端の長さ。デフォルトは0です
right : 切り抜く右端の長さ。デフォルトは0です
bottom : 切り抜く下端の長さ。デフォルトは0です
minwidth : 最低限保持する幅。デフォルトは0です
minheight : 最低限保持する高さ。デフォルトは0です
aspectx, aspecty : アスペクト比の指定。縦横比がaspectx:aspectyになるように調整します。デフォルトは711:485です
clrfmt : クロップする際、現在の色空間の制限以外にこの色空間の制限を加えます。デフォルトでは特に指定されません
interlaced : trueだと縦の切り抜き開始終了位置を偶数にします。YV12だと意味無しです。デフォルトはtrueです
cutOff : trueだと黒淵がなくなるまで切り抜き、falseだと黒淵をギリギリまで削ります。デフォルトはtrueです
debug : trueだとクロップする際に使った引数などを表示します。デフォルトはfalseです
234名無しさん@編集中:03/12/03 20:06
分かっている人には分かってるとは思うんですが、内部の一部の解説。

((n + m) / unitx) * unitx
てのはここで使っているのは本来C系言語だと
(n + 1) & (unitx >> 1)
と書くことが薦められている文で、特定の数値の倍数に丸めてます。

アスペクト比の計算や調整には初等数学の比の法則、
n:m==x:yならm*x==n*y
を使ってます。