[sync.avs]
SetMemoryMax(64)
Import("file_info.txt")
Exist(AviSynth_Plugins_Path + "mpasource.dll") ? \
LoadPlugin(AviSynth_Plugins_Path + "mpasource.dll") : nop
Exist(AviSynth_Plugins_Path + "MPEGDecoder.dll") ? \
LoadPlugin(AviSynth_Plugins_Path + "MPEGDecoder.dll") : nop
Exist(AviSynth_Plugins_Path + "ac3source.dll") ? \
LoadPlugin(AviSynth_Plugins_Path + "ac3source.dll") : nop
Function PropertyRevision_Frame_rate (float F_r) {
ReturnFrame_rate = (F_r == 15) ? 12 : F_r
ReturnFrame_rate = (F_r == 24) ? 23.976 : ReturnFrame_rate
ReturnFrame_rate = (F_r == 30) ? 29.970 : ReturnFrame_rate
ReturnFrame_rate = (F_r == 60) ? 59.94 : ReturnFrame_rate
ReturnFrame_rate = (F_r == 120) ? 59.94 : ReturnFrame_rate
return(default(ReturnFrame_rate, F_r))
}
Function GetFileClip (String F_N, float F_r) {
v = DirectShowSource(F_N, F_r)
ChangeFPS(v, F_r)
AssumeFrameBased(v)
AssumeTFF(v)
AssumeFPS(v, F_r, True)
return(v)
}
Function GetAudio (clip v, String F_P, String F_N, String A_S) {
##求Audio 檔名、副檔名##
A_S_FrontNameChrNum = Findstr(A_S, ".")
A_S_Temp = RightStr(A_S, (StrLen(A_S)- A_S_FrontNameChrNum))
Audio_Style = (A_S_FrontNameChrNum > 0) ? UCase(A_S_Temp) : UCase(A_S)
F_N_FrontNameChrNum = Findstr(F_N, ".")
A_N_Temp = LeftStr(F_N, F_N_FrontNameChrNum)
Audio_Name = (A_S_FrontNameChrNum == 0) ? F_P + A_N_Temp + Audio_Style : F_P + A_S
#####Audio = Vedio######
Audio_Style = (F_N == A_S) ? "Vedio" : Audio_Style
Temp_Clip_Vedio = (F_N == A_S) ? v : nop
#####Audio File存在#####
Temp_Clip_AVI = (Audio_Style == "AVI") ? v : nop
Temp_Clip_MP3 = (Audio_Style == "MP3") ? mpaSource(Audio_Name) : nop
Temp_Clip_AC3 = (Audio_Style == "AC3") ? v.ac3source(Audio_Name).AmplifydB(18,18) : nop
Temp_Clip_WAV = (Audio_Style == "WAV") ? WavSource(F_P + F_N) : nop
Temp_Clip_RA = (Audio_Style == "RA") ? DirectShowSource(Audio_Name, fps= v.framerate, seek= false, audio= True, video= True) : nop
Return_Audio = Eval("Temp_Clip_"+ Audio_Style)
return(Return_Audio)
}
Function ErrorText (int err_num) {
vedio_Subtitle = (err_num == -1) ?
\ "File_info.txt 內的 Offset_Start_Time 時間設定錯誤" :
\ (err_num == 2) ? "檔案沒發現" :
\ ""
vedio_Subtitle = vedio_Subtitle + "avs腳本無作用"
return(vedio_Subtitle)
}
Function Get_Offset_Time(String O_S_T, float F_r) {
Temp_Str = LeftStr(O_S_T, 2)
Time_Temp = Value(LeftStr(Temp_Str, 1)) * 10 + Value(RightStr(Temp_Str, 1))
Hour_Time = (Time_Temp < 60) ? Time_Temp * 360 : -1
Temp_Str = MidStr(O_S_T, 4, 2)
Time_Temp = Value(LeftStr(Temp_Str, 1)) * 10 + Value(RightStr(Temp_Str, 1))
Minute_Time = (Time_Temp < 60) ? Time_Temp * 60 : -1
Temp_Str = RightStr(O_S_T, 2)
Time_Temp = Value(LeftStr(Temp_Str, 1)) * 10 + Value(RightStr(Temp_Str, 1))
Second_Timp = (Time_Temp < 60) ? Time_Temp : -1
Time_Total = ((Hour_Time < 0) || (Minute_Time < 0) || (Second_Timp < 0)) ? -1 : Hour_Time + Minute_Time + Second_Timp
Return_Frame_Count = Int(Time_Total * F_r)
return (Return_Frame_Count)
}
#EX: Vedio_DelayAudio(Vedio, Audio, Offset_Frame, Delay_Time)
Function Vedio_DelayAudio (clip Vedio, clip Audio, Int Offset_Frame, float Delay_Time) {
Global v = Vedio
Global a = !IsClip(Audio) ? Vedio : Audio
Global O_F = Offset_Frame
Global Delay_TimeF = Int(Delay_Time * Vedio.Framerate)
#####Vedio1_NullAudio+Vedio2_Audio2#####
Function DelayTimeis_positive{
Temp_audio = BlankClip(v).Trim(O_F, O_F + Delay_TimeF- 1)
VA_temp1 = AudioDub(v, Temp_audio).Trim(O_F, O_F + Delay_TimeF- 1)
Temp_vedio = v.trim(O_F + Delay_TimeF, v.framecount).KillAudio
VA_temp2 = AudioDub(Temp_vedio, a)
return UnalignedSplice(VA_temp1, VA_temp2)
}
#####Vedio1_Audio1+Vedio2_Audio2########
Function DelayTimeis_negative {
VA_temp1 = v.Trim(O_F, v.Framecount).KillAudio
VA_temp2 = v.Trim(O_F - Delay_TimeF, v.Framecount)
return AudioDub(VA_temp1, VA_temp2)
}
###[Function Vedio_DelayAudio Start]####
Return_VA =
\ (Delay_Time < 0) ? DelayTimeis_negative :
\ (Delay_Time > 0) ? DelayTimeis_positive :
\ AudioDub(Vedio, Audio)
return Return_VA
}
#DivideVedio(Vedio, Audio, Offset_Frame, Delay_Time)
Function DivideVedio (clip v, clip a, Int O_F, float D_T) {
Return_va1 = AudioDub(v, a).Trim(0, O_F- 1)
Return_va2 = AudioDub(v, a).Trim(O_F, v.Framecount).DelayAudio(D_T)
Return_va = Return_va1 + Return_va2
return (Return_va)
}
#####[主程序開始]#####
####參數修正、判斷####
Frame_rate = Property_Revision ? PropertyRevision_Frame_rate(Frame_rate) : Frame_rate
File_Path = File_Path + If_FilePath_Exist_necessary_word
Work_Movie_File = File_Path + File_Name
Work_Audio_File = File_Path + Audio_Style
AudioFile_Exist = Exist(Work_Audio_File)
##獲得Vedio及Audio Clip##
Vedio = GetFileClip(Work_Movie_File, Frame_rate)
Audio = (AudioFile_Exist || (Audio_Style <> "")) ? GetAudio(Vedio, File_Path, File_Name, Audio_Style) : Vedio
IsClip(Audio) ? KillAudio(Vedio) : nop
Offset_Frame = (Delay_Time <> 0) ? Get_Offset_Time(Offset_Start_Time, Frame_rate) : Get_Offset_Time("00:00:00", Frame_rate)
PlayFile =
\ ((Offset_Frame == 0) && (Delay_Time == 0)) ?
\ AudioDub(Vedio, Audio) :
\ (Offset_Frame == 0) ?
\ Vedio_DelayAudio(Vedio, Audio, Offset_Frame, Delay_Time) :
\ (Offset_Frame > 0) ?
\ DivideVedio(Vedio, Audio, Offset_Frame, Delay_Time) :
\ AudioDub(Vedio, Audio)
Offset_Frame < 0 ? PlayFile.Subtitle(ErrorText(-1)) : PlayFile