AviSynthスクリプト


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

Version 0.8 現在のsyumas_func.avs


# 週間アイドルマスターランキング AviSynth スクリプト Ver 0.85 Beta
# 
# 使用プラグイン
#  - FFmpegSource
 
global VideoDir = "flv\"
global FrameDir = "frame\"
global ImageDir = "image\"
global BgmDir   = "bgm\"
 
# ---------- クリップ読み込み関数
function LoadClip(int id, string mark, float start_sec, float length_sec, string path)
{
    # クリップ読み込み
    #clip = FFmpegSource(VideoDir + path, atrack=-1, seekmode=-1).ConvertFPS(29.97)
    clip = DirectShowSource(VideoDir + path, fps=29.97, convertfps=true)
 
    # 切り取り
    sta_frame = Int(clip.Framerate * start_sec)
    end_frame = Int(clip.Framerate * length_sec) + sta_frame
    clip = Trim(clip, sta_frame, end_frame)
 
    # リサイズ
    clip = (clip.Width != 512 || clip.Height != 384) ? Resize(clip, 512, 384) : clip
 
    # RGB32化、フェード効果
    clip = ConvertToRGB32(clip).FadeIO(30)
 
    # モノラルの場合は、ステレオに
    clip = (clip.Audiochannels == 1) ? Mono2Stereo(clip) : clip
 
    # 音声の44.1Khz化
    clip = ResampleAudio(clip, 44100)
 
    # ランク変動情報表示
    clip = AddIntro(clip, mark, id)
 
    # フレーム追加
    clip = AddFrame(clip, id)
 
    return clip
}
 
# ---------- 1ch音声の2ch化
function Mono2Stereo(clip clip)
{
    audio = GetChannel(clip, 1)
    return AudioDub(clip, MergeChannels(audio, audio))
}
 
# ---------- アスペクト比保持リサイズ
function Resize(clip clip, int target_width, int target_height)
{
    # リサイズ
    resize_ratio_x = Float(target_width) / clip.Width
    resize_ratio_y = Float(target_height) / clip.Height
    resize_ratio   = (resize_ratio_x < resize_ratio_y) ? resize_ratio_x : resize_ratio_y
    resize_width   = Int(Round(clip.Width * resize_ratio))
    resize_height  = Int(Round(clip.Height * resize_ratio))
    clip = clip.Lanczos4Resize(resize_width, resize_height)
 
    # 不足した領域を補う
    border_width   = target_width - resize_width
    border_height  = target_height - resize_height
    border_left    = (border_width  / 2)
    border_top     = (border_height / 2)
    border_right   = (border_width  / 2) + (border_width  % 2)
    border_bottom  = (border_height / 2) + (border_height % 2)
    clip = clip.AddBorders(border_left, border_top, border_right, border_bottom)
 
    return clip
}
 
# ---------- フレーム表示前文字
function AddIntro(clip clip, string mark, int id)
{
    img = ImageSource(FrameDir + "text" + String(id) + ".png", pixel_type="RGB32")
 
    clip = (mark == "U") ? AddIntroUp(clip, img) : clip
    clip = (mark == "D") ? AddIntroDown(clip, img) : clip
    clip = (mark == "N") ? AddIntroNew(clip, img) : clip
    clip = (mark == "K") ? AddIntroNew(clip, img) : clip
    clip = (mark == "H") ? AddIntroNew(clip, img) : clip
    clip = (mark == "S") ? AddIntroNew(clip, img) : clip
 
    return clip
}
 
# ---------- ランクアップ
function AddIntroUp(clip clip, clip img)
{
    clip = clip.ApplyRange(15, 20, "MoveY", img,15,20,385,300)
    clip = clip.ApplyRange(21, 80, "MoveY", img,21,80,300,300)
    clip = clip.ApplyRange(81, 95, "MoveY", img,81,95,300,-70)
    return clip
}
 
# ---------- ランクダウン
function AddIntroDown(clip clip, clip img)
{
    clip = clip.ApplyRange(15, 29, "MoveY", img,15,29,-70,300)
    clip = clip.ApplyRange(30, 89, "MoveY", img,30,89,300,300)
    clip = clip.ApplyRange(90, 95, "MoveY", img,90,95,300,385)
    return clip
}
 
# ---------- New!
function AddIntroNew(clip clip, clip img)
{
    clip = clip.ApplyRange(15, 20, "MoveY", img,15,20,385,300)
    clip = clip.ApplyRange(21, 80, "MoveY", img,21,80,300,300)
    clip = clip.ApplyRange(81, 95, "MoveY", img,81,95,300,-70)
    return clip
}
 
# ---------- フレーム表示
function AddFrame(clip clip, int id)
{
    file = FrameDir + "frame" + String(id) + ".png"
    img = ImageSource(file, end=Int(29.97 * 8), fps=29.97, pixel_type="RGB32")
    return clip.ApplyRange(100, 100 + img.FrameCount, "Layer", img,"add",255,0,0 )
 
# フェード表示用
#    img = ImageSource(file, end=300, pixel_type="RGB32").FadeIO(10)
#    img = BlankClip(img, length=90) + img
#    return Layer(clip, img, "add", 255, 0, 0)
}
 
# ---------- 画像移動(縦方向)
function MoveY(clip clip1, clip clip2, int start_frame, int end_frame, int start_y, int end_y)
{
    x = Int((clip1.Width - clip2.Width) / 2)
 
    clip = Animate(start_frame, end_frame, "Layer",
\                    clip1, clip2, "add", 255, x, start_y,
\                    clip1, clip2, "add", 255, x, end_y)
 
    return clip
}