; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
IncludeFile "AutoX264_IncludeFile.pb"
Global inputfile.s,width.l,height.l,topcrop.l,rightcrop.l,bottomcrop.l
Global leftcrop.l,ar.s,dar.f,framecount.l,framerate.f,tsec.l,mess.s,twidth.l,theight.l
Global aspectinfo.f,outputfile.s,mencoderbat.s,inputfolder.s,vcrop.s
Global acleft.l, acright.l, twidth.l, theight.l, actop.l,acbottom.l,mess.s,queue.l,framer.s
Global passx.l, mpl.s,stop.l,mkvmerge.s,wait.l,here.s,parse.s,value.s,profilefile.s,line.s,audiofile.s
Global messinfo.s,videocodec.s,mplayer.s,mencoder.s,mp4creator.s,mkvmerge.s,fps.s,lavf.s,exts.s,preindex.s,handbrakecli.s
Global subs.s,wt.l,eac3toaudio.s="",decoder.s
Global Dim inputfileorder.s(10000)
Procedure handleaudio()
Debug("CountGadgetItems(#audiopid)="+Str(CountGadgetItems(#audiopid)))
For aa=1 To CountGadgetItems(#audiopid)
If GetGadgetItemState(#audiopid,aa) & #PB_ListIcon_Checked
Debug("audiopid(aa)="+Str(aa))
Debug("1-"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"="))
aid.s=StringField(GetGadgetItemText(#audiopid,aa,0),2,"=")
mencoderbat.s=mencoderbat.s+Chr(10)+mencoder.s+" -mc 0 -noskip -aid "+StringField(GetGadgetItemText(#audiopid,aa,0),2,"=")+" "+Chr(34)+inputfile.s+Chr(34)+" "
If GetGadgetText(#audioenc)="AAC Audio" : mencoderbat.s=mencoderbat.s+"-ovc frameno "+lavf.s+" -oac faac -faacopts br="+GetGadgetText(#abitrate)+":mpeg=4:tns:object=2 -channels "+GetGadgetText(#channels)+" " : EndIf
If GetGadgetText(#audioenc)="MP3 Audio" : mencoderbat.s=mencoderbat.s+"-ovc frameno "+lavf.s+" -oac mp3lame -lameopts "+GetGadgetText(#mp3mode)+":br="+GetGadgetText(#abitrate)+" channels=2 " : EndIf
If GetGadgetText(#audioenc)="Copy Audio" : mencoderbat.s=mencoderbat.s+"-ovc frameno "+lavf.s+" -oac copy " : EndIf
If GetGadgetState(#normalize)=1 : mencoderbat.s=mencoderbat.s+"-af volnorm=2 " : EndIf
If GetGadgetText(#samplerate)<>"AUTO" : mencoderbat.s=mencoderbat.s+"-srate "+GetGadgetText(#samplerate)+" " : EndIf
If GetGadgetText(#audioenc)="AAC Audio" : mencoderbat.s=mencoderbat.s+"-of rawaudio -o "+Chr(34)+here.s+"audiox264-pid"+aid.s+".aac"+Chr(34) : EndIf
If GetGadgetText(#audioenc)="MP3 Audio" : mencoderbat.s=mencoderbat.s+"-of rawaudio -o "+Chr(34)+here.s+"audiox264-pid"+aid.s+".mp3"+Chr(34) : EndIf
If GetGadgetText(#audioenc)="Copy Audio" : mencoderbat.s=mencoderbat.s+"-of rawaudio -o "+Chr(34)+here.s+"audiox264-pid"+aid.s+".ac3"+Chr(34) : EndIf
EndIf
Next aa
EndProcedure
Procedure loadpreset()
aa.l=0
Debug("here="+here.s)
ClearGadgetItems(#preset)
AddGadgetItem(#preset,-1,"NONE")
If ExamineDirectory(0,here.s+"profiles/","*.xml")
Repeat
type=NextDirectoryEntry(0)
If type=1 ; File.
Profile.s= DirectoryEntryName(0)
aa.l=aa.l+1
inputfileorder.s(aa.l)=DirectoryEntryName(0)
EndIf
Until type=0
FinishDirectory(0)
EndIf
ReDim inputfileorder.s(aa)
SortArray(inputfileorder.s(),2)
For bb=1 To aa
AddGadgetItem(#preset,-1,inputfileorder.s(bb))
Next bb
Dim inputfileorder.s(0)
SetGadgetState(#preset,0)
EndProcedure
Procedure saveprofile()
If FileSize(here.s+"profiles")=-1 : CreateDirectory(here.s+"profiles") : EndIf
file.s=SaveFileRequester("Save X264 XML profile",here.s+"profiles\"+"*.xml","*.xml",0)
If GetExtensionPart(file.s)="" : file.s=file.s+".xml" : EndIf
OpenFile(888,file.s)
If GetGadgetState(#pass1)=1 : WriteStringN(888,"0") : EndIf
If GetGadgetState(#pass2)=1 : WriteStringN(888,"4") : EndIf
If GetGadgetState(#passcrf)=1 : WriteStringN(888,"9") : EndIf
WriteStringN(888,""+GetGadgetText(#manualbitrate)+"")
WriteStringN(888,""+GetGadgetText(#vbitrate)+"")
WriteStringN(888,""+GetGadgetText(#keyint)+"")
WriteStringN(888,""+GetGadgetText(#bframes)+"")
WriteStringN(888,""+GetGadgetText(#qpmin)+"")
WriteStringN(888,""+GetGadgetText(#qpmax)+"")
If GetGadgetState(#turbo)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#turbo)=0 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#nodctdecimate)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#nodctdecimate)=0 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#nofastpskip)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#nofastpskip)=0 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#mixedrefs)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#mixedrefs)=0 :WriteStringN(888,"false") : EndIf
WriteStringN(888,""+Str(GetGadgetState(#trellis))+"")
WriteStringN(888,""+GetGadgetText(#refframes)+"")
WriteStringN(888,""+GetGadgetText(#deblockalpha)+"")
WriteStringN(888,""+GetGadgetText(#deblockbeta)+"")
WriteStringN(888,""+Str(GetGadgetState(#subme))+"")
WriteStringN(888,""+Str(GetGadgetState(#direct)-1)+"")
WriteStringN(888,""+GetGadgetText(#vbvbufsize)+"")
WriteStringN(888,""+GetGadgetText(#vbvmaxrate)+"")
WriteStringN(888,""+Str(GetGadgetState(#me))+"")
WriteStringN(888,""+GetGadgetText(#merange)+"")
WriteStringN(888,""+GetGadgetText(#keyintmin)+"")
WriteStringN(888,""+Str(16-1-GetGadgetState(#level))+"")
WriteStringN(888,""+GetGadgetText(#ipratio)+"")
WriteStringN(888,""+GetGadgetText(#pbratio)+"")
WriteStringN(888,""+GetGadgetText(#chromaqpoffset)+"")
WriteStringN(888,""+GetGadgetText(#vbvinit)+"")
WriteStringN(888,""+GetGadgetText(#ratetol)+"")
WriteStringN(888,""+GetGadgetText(#qcomp)+"")
WriteStringN(888,""+GetGadgetText(#cplxblur)+"")
WriteStringN(888,""+GetGadgetText(#qblur)+"")
WriteStringN(888,""+GetGadgetText(#scenecut)+"")
WriteStringN(888,""+GetGadgetText(#bbias)+"")
WriteStringN(888,""+StringField(GetGadgetText(#pysstrenght),1,":")+"")
WriteStringN(888,""+StringField(GetGadgetText(#pysstrenght),2,":")+"")
If GetGadgetState(#nocabac)=1 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#nocabac)=0 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#weightb)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#weightb)=0 :WriteStringN(888,"false") : EndIf
WriteStringN(888,""+Str(GetGadgetState(#badapt))+"")
If GetGadgetState(#bpyramid)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#bpyramid)=0 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#nochromame)=1 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#nochromame)=0 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#p8x8)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#p8x8)=0 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#b8x8)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#b8x8)=0 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#i4x4)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#i4x4)=0 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#i8x8)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#i8x8)=0 :WriteStringN(888,"false") : EndIf
If GetGadgetState(#dct8x8)=1 :WriteStringN(888,"true") : EndIf
If GetGadgetState(#dct8x8)=0 :WriteStringN(888,"false") : EndIf
WriteStringN(888,""+GetGadgetText(#deadzoneinter)+"")
WriteStringN(888,""+GetGadgetText(#deadzoneintra)+"")
WriteStringN(888,""+Str(GetGadgetState(#aqmode))+"")
WriteStringN(888,""+GetGadgetText(#aqstrenght)+"")
CloseFile(888)
Dim inputfileorder.s(1000)
loadpreset()
EndProcedure
Procedure handlesubs()
subs.s=""
If ExamineDirectory(0,here.s,"autox264__subs_*.*") ;delete already extracted subs
Repeat
type=NextDirectoryEntry(0)
If type=1 ; File.
file.s=DirectoryEntryName(0)
DeleteFile(here.s+file.s)
EndIf
Until type=0
FinishDirectory(0)
EndIf
If GetGadgetText(#subtitlepath)<>""
If GetGadgetState(#muxsubs)=1 And GetGadgetText(#muxer)="mp4"
subs.s=" -add "+Chr(34)+GetGadgetText(#subtitlepath)+Chr(34)+" "
EndIf
If GetGadgetState(#muxsubs)=1 And GetGadgetText(#muxer)="mkv"
subs.s=" "+Chr(34)+GetGadgetText(#subtitlepath)+Chr(34)+" "
EndIf
EndIf
EndProcedure
Procedure ardar()
acbottom.l=Val(GetGadgetText(#bottomcrop))
acleft.l=Val(GetGadgetText(#leftcrop))
acright.l=Val(GetGadgetText(#rightcrop))
actop.l=Val(GetGadgetText(#topcrop))
aspectinfo.f=ValF(GetGadgetText(#aspectratio))
If GetGadgetState(#itu)=1 : itu.f=53.3333/52 : EndIf ;*1.02564
If GetGadgetState(#itu)=0 : itu.f=1 : EndIf
dar.f = ((twidth.l-acleft.l-acright.l)/twidth.l)/((theight.l-actop.l-acbottom.l)/theight.l)*aspectinfo.f*itu.f
SetGadgetText(#dar,StrF(dar.f,4))
SetGadgetText(#arerror,StrF((dar.f/(ValF(GetGadgetText(#width))/ValF(GetGadgetText(#height))))*100-100,4))
EndProcedure
Procedure decoder()
decoder.s=""
If FindString(LCase(videocodec.s),"mpeg",0) : videocodec.s="Mpeg2" : decoder.s="Mencoder" : EndIf
If FindString(videocodec.s,"264",0) Or FindString(videocodec.s,"avc",0)
videocodec.s="H.264"
Debug(GetExtensionPart(inputfile.s)+" os="+Str(OSVersion()))
Select GetExtensionPart(inputfile.s)
Case "m2ts","ts","mkv"
decoder.s="Mencoder Or FFmpeg"
Default
decoder.s="Mencoder Or FFmpeg Or DirectShowSource"
EndSelect
EndIf
If FindString(LCase(videocodec.s),"divx",0) : videocodec.s="Mpeg4 ASP" : decoder.s="Mencoder" : EndIf
If FindString(LCase(videocodec.s),"wmv",0) : videocodec.s="Windows Media Video" : decoder.s="Mencoder or FFmpeg" : EndIf
If FindString(LCase(videocodec.s),"vc-1",0) : videocodec.s="Windows VC1 Video" : decoder.s="Mencoder or FFmpeg" : EndIf
If FindString(LCase(videocodec.s),"vc1",0) : videocodec.s="Windows VC1 Video" : decoder.s="Mencoder or FFmpeg" : EndIf
If decoder.s<>"" : messinfo.s=messinfo.s+"Suggested Decoder: "+decoder.s : EndIf
StatusBarText(#statusbar, 0, "Suggested Decoder: "+decoder.s)
EndProcedure
Procedure analyzewith()
If GetGadgetText(#mplayerpath)<>"" : AddGadgetItem(#analyzewith,-1,"mplayer") : EndIf
wait.l=RunProgram("mediainfo","","",#PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
If wait.l
While ProgramRunning(wait.l)
line.s=ReadProgramString(wait)
If FindString(line.s,"MediaInfo --Help",0)
AddGadgetItem(#analyzewith,-1,"mediainfo")
EndIf
Wend
WaitProgram(wait)
EndIf
SetGadgetState(#analyzewith,0)
EndProcedure
Procedure mux()
If GetGadgetState(#novideo)=0 : videofile.s=Chr(34)+here.s+"autox264.h264"+Chr(34) : EndIf
If GetGadgetText(#muxer)="mp4" And GetGadgetState(#novideo)=0 : videofile.s="-add "+videofile.s : EndIf
If GetGadgetState(#novideo)=1 : videofile.s="" : EndIf
If GetGadgetText(#audioenc)="No Audio" : audiofile.s="" : EndIf
If GetGadgetText(#muxer)="mp4"
mencoderbat.s=mencoderbat.s+Chr(10)+mp4creator.s+" "+videofile.s+" -fps "+fps.s+" "+audiofile.s+subs.s+Chr(34)+outputfile.s+Chr(34)
EndIf
If GetGadgetText(#muxer)="mkv"
outputfile.s=ReplaceString(outputfile.s,".mp4",".mkv")
mencoderbat.s=mencoderbat.s+Chr(10)+mkvmerge.s+" -o "+Chr(34)+outputfile.s+Chr(34)+" --default-duration 0:"+fps.s+"fps --aspect-ratio -1:"+GetGadgetText(#dar)+" "+videofile.s+" "+audiofile.s+subs.s
EndIf
If GetGadgetText(#muxer)="m2ts"
Select Mid(framer.s,0,5)
Case "29.97"
defdur.s=", fps=29.97"
Case "23.97"
defdur.s=", fps=23.976"
Case "25.00"
defdur.s=", fps=25"
Default
defdur.s=", fps="+StrF(ValF(Mid(framer.s,0,6)),0)
EndSelect
Select GetGadgetText(#mdeint)
Case "Change framerate to 23.976", "Progressive NTSC (29.97->23.976)", "Telecine"
defdur.s=" --default-duration 0:24000/1001fps "
Case "Change framerate to 25"
defdur.s=" --default-duration 0:25000/1000fps "
Case "Change framerate to 29.976"
defdur.s=" --default-duration 0:30000/1001fps "
EndSelect
CreateFile(333,here.s+"m2ts.meta")
WriteStringN(333,"MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbr --vbv-len=500")
WriteStringN(333,"V_MPEG4/ISO/AVC,"+Chr(34)+"autox264.h264"+Chr(34)+defdur.s+", insertSEI, contSPS")
For aa=0 To CountGadgetItems(#audiopid)
If GetGadgetText(#audioenc)="AAC Audio" : extaudio.s="aac" : EndIf
If GetGadgetText(#audioenc)="MP3 Audio" : extaudio.s="mp3" : EndIf
If GetGadgetItemState(#audiopid,aa)=#PB_ListIcon_Checked
Debug("1-"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"="))
If GetGadgetText(#audioenc)="AAC Audio"
WriteStringN(333,"A_AAC, "+Chr(34)+here.s+"audiox264-pid"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"=")+".aac"+Chr(34)+", timeshift=0,lang=und)")
EndIf
If GetGadgetText(#audioenc)="Copy Audio"
WriteStringN(333,"A_AC3, "+Chr(34)+here.s+"audiox264-pid"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"=")+".ac3"+Chr(34)+", timeshift=0,lang=und)")
EndIf
If GetGadgetText(#audioenc)="MP3 Audio"
WriteStringN(333,"A_MP3, "+Chr(34)+here.s+"audiox264-pid"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"=")+".mp3"+Chr(34)+", timeshift=0,lang=und)")
EndIf
EndIf
Next aa
CloseFile(333)
mencoderbat.s=mencoderbat.s+Chr(10)+Chr(34)+here.s+"applications\tsMuxeR.exe"+Chr(34)+" m2ts.meta "+Chr(34)+outputfile.s+Chr(34)
EndIf
EndProcedure
Procedure showinfo()
If GetGadgetText(#width)="" :
MessageRequester("AutoX264", "Attention!"+Chr(10)+"Analyze file First!")
ProcedureReturn
EndIf
messinfo.s="Input File: "+GetFilePart(inputfile.s)+Chr(10)
messinfo.s=messinfo.s+"Codec Video: "+videocodec.s+Chr(10)
messinfo.s=messinfo.s+Chr(10)
messinfo.s=messinfo.s+"Width: "+Str(twidth.l)+Chr(10)
messinfo.s=messinfo.s+"Heigh: "+Str(theight.l)+Chr(10)
messinfo.s=messinfo.s+"Framerate: "+StrF(framerate.f,3)+Chr(10)
messinfo.s=messinfo.s+"Framecount: "+Str(framecount.l)+Chr(10)
messinfo.s=messinfo.s+"Aspect Ratio: "+ar.s+Chr(10)
messinfo.s=messinfo.s+"Duration(sec): "+Str(tsec.l)+Chr(10)
messinfo.s=messinfo.s+"Resized resolution: "+GetGadgetText(#width)+" / "+GetGadgetText(#height)+Chr(10)
messinfo.s=messinfo.s+"Crop Left: "+GetGadgetText(#leftcrop)+Chr(10)
messinfo.s=messinfo.s+"Crop Top: "+GetGadgetText(#topcrop)+Chr(10)
messinfo.s=messinfo.s+"Crop Right: "+GetGadgetText(#rightcrop)+Chr(10)
messinfo.s=messinfo.s+"Crop Bottom: "+GetGadgetText(#bottomcrop)+Chr(10)
messinfo.s=messinfo.s+Chr(10)+Chr(10)
If decoder.s<>"" : messinfo.s=messinfo.s+"Suggested Decoder: "+decoder.s : EndIf
MessageRequester("AutoX264 File Information",messinfo.s)
EndProcedure
Procedure parseprofile(parse.s)
value.s="null"
;Debug(GetGadgetText(#preset))
profilefile.s=here.s+"profiles/"+GetGadgetText(#preset)
If ReadFile(888,profilefile.s)
While Eof(888)=0
line.s = ReadString(888)
If FindString(line.s,"<"+parse.s+">",1)
value.s=StringField(line.s,2,">")
value.s=StringField(value.s,1,"<")
Break
EndIf
Wend
CloseFile(888)
EndIf
EndProcedure
Procedure applypreset()
;#False=leave option blank Or Not used
;#True=For options without values (like 8x8dct)
;#numbers=For options that accepts numbers Or string
;#pass can be 1 Or 2 Or crf
;#container can be mp4 Or mkv
If GetGadgetText(#preset)="NONE" : ProcedureReturn : EndIf
If FileSize(here.s+"profiles/"+GetGadgetText(#preset))=-1 : MessageRequester("Attention","No profiles found"): ProcedureReturn : EndIf
parseprofile("AdaptiveDCT")
If value.s="true" : SetGadgetState(#dct8x8,1) : EndIf
If value.s="false" : SetGadgetState(#dct8x8,0) : EndIf
parseprofile("AQmode")
If value.s="true" : SetGadgetState(#aqmode,1)
ElseIf value.s="false" : SetGadgetState(#aqmode,0)
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#aqmode,Val(value.s))
EndIf
parseprofile("AQstrength")
If value.s="true" : SetGadgetText(#aqstrenght,"1")
ElseIf value.s="false" : SetGadgetText(#aqstrenght,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#aqstrenght,value.s)
EndIf
parseprofile("B8x8mv")
If value.s="true" : SetGadgetState(#b8x8,1) : EndIf
If value.s="false" : SetGadgetState(#b8x8,0) : EndIf
parseprofile("NewAdaptiveBFrames")
If value.s="1" : SetGadgetState(#badapt,1)
ElseIf value.s="0" : SetGadgetState(#badapt,0)
ElseIf value.s="2" : SetGadgetState(#badapt,2)
ElseIf value.s<>"1" And value.s<>"2" And value.s<>"false" : SetGadgetState(#badapt,Val(value.s)+1)
EndIf
parseprofile("BFramePyramid")
If value.s="true" : SetGadgetState(#bpyramid,1) : EndIf
If value.s="false" : SetGadgetState(#bpyramid,0) : EndIf
parseprofile("NbBframes")
If value.s="true" : SetGadgetText(#bframes,"3")
ElseIf value.s="false" : SetGadgetText(#bframes,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#bframes,value.s)
EndIf
parseprofile("TempComplexityBlur")
If value.s="true" : SetGadgetText(#cplxblur,"1")
ElseIf value.s="false" : SetGadgetText(#cplxblur,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null": SetGadgetText(#cplxblur,value.s)
EndIf
parseprofile("AlphaDeblock")
If value.s="true" : SetGadgetText(#deblockalpha,"-1")
ElseIf value.s="false" : SetGadgetText(#deblockalpha,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#deblockalpha,value.s)
EndIf
parseprofile("BetaDeblock")
If value.s="true" : SetGadgetText(#deblockbeta,"-1")
ElseIf value.s="false" : SetGadgetText(#deblockbeta,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#deblockbeta,value.s)
EndIf
parseprofile("BframePredictionMode")
If value.s="true" : SetGadgetState(#direct,3)
ElseIf value.s="false" : SetGadgetState(#direct,0)
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#direct,Val(value.s)+1)
EndIf
parseprofile("NbRefFrames")
If value.s="true" : SetGadgetText(#refframes,"3")
ElseIf value.s="false" : SetGadgetText(#refframes,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#refframes,value.s)
EndIf
parseprofile("I4x4mv")
If value.s="true" : SetGadgetState(#i4x4,1) : EndIf
If value.s="false" : SetGadgetState(#i4x4,0) : EndIf
parseprofile("I8x8mv")
If value.s="true" : SetGadgetState(#i8x8,1) : EndIf
If value.s="false" : SetGadgetState(#i8x8,0) : EndIf
parseprofile("KeyframeInterval")
If value.s="true" : SetGadgetText(#keyint,"250")
ElseIf value.s="false" : SetGadgetText(#keyint,"9999")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#keyint,value.s)
EndIf
parseprofile("MinGOPSize")
If value.s="true" : SetGadgetText(#keyint,"25")
ElseIf value.s="false" : SetGadgetText(#keyintmin,"9999")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#keyintmin,value.s)
EndIf
parseprofile("Level")
If value.s="15" : SetGadgetText(#level,"")
ElseIf value.s="false" : SetGadgetText(#level,"1")
ElseIf value.s<>"15" And value.s<>"true" And value.s<>"null" : SetGadgetState(#level,16-Val(value.s)-1)
EndIf
parseprofile("METype")
If value.s="true" : SetGadgetText(#me,"hex")
ElseIf value.s="false" : SetGadgetText(#me,"dia")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#me,Val(value.s))
EndIf
parseprofile("MERange")
If value.s="true" : SetGadgetText(#merange,"16")
ElseIf value.s="false" : SetGadgetText(#merange,"8")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#merange,value.s)
EndIf
parseprofile("BframeBias")
If value.s="true" : SetGadgetText(#bbias,"0")
ElseIf value.s="false" : SetGadgetText(#bbias,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#bbias,value.s)
EndIf
parseprofile("IPFactor")
If value.s="true" : SetGadgetText(#ipratio,"1.40")
ElseIf value.s="false" : SetGadgetText(#ipratio,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#ipratio,value.s)
EndIf
parseprofile("PBFactor")
If value.s="true" : SetGadgetText(#pbratio,"1.30")
ElseIf value.s="false" : SetGadgetText(#pbratio,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#pbratio,value.s)
EndIf
parseprofile("ChromaQPOffset")
If value.s="true" : SetGadgetText(#chromaqpoffset,"0")
ElseIf value.s="false" : SetGadgetText(#chromaqpoffset,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#chromaqpoffset,value.s)
EndIf
parseprofile("ChromaQPOffset")
If value.s="true" : SetGadgetText(#chromaqpoffset,"0")
ElseIf value.s="false" : SetGadgetText(#chromaqpoffset,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#chromaqpoffset,value.s)
EndIf
;parseprofile("MVRange")
;If value.s="true" : SetGadgetText(#mvrange,"-1")
;ElseIf value.s="false" : SetGadgetText(#mvrange,"0")
;ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#mvrange,value.s)
;EndIf
;parseprofile("MVRangethread")
;If value.s="true" : SetGadgetText(#mvrangethread,"-1")
;ElseIf value.s="false" : SetGadgetText(#mvrangethread,"0")
;ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#mvrangethread,value.s)
;EndIf
parseprofile("DeadZoneInter")
If value.s="true" : SetGadgetText(#deadzoneinter,"21")
ElseIf value.s="false" : SetGadgetText(#deadzoneinter,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#deadzoneinter,value.s)
EndIf
parseprofile("DeadZoneIntra")
If value.s="true" : SetGadgetText(#deadzoneintra,"11")
ElseIf value.s="false" : SetGadgetText(#deadzoneintra,"0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#deadzoneintra,value.s)
EndIf
;parseprofile("Aud")
;If value.s="true" : SetGadgetState(#deadzoneintra,1)
;ElseIf value.s="false" : SetGadgetState(#deadzoneintra,0)
;EndIf
parseprofile("MixedRefs")
If value.s="true" : SetGadgetState(#mixedrefs,1) : EndIf
If value.s="false" : SetGadgetState(#mixedrefs,0) : EndIf
parseprofile("Cabac")
If value.s="true" : SetGadgetState(#nocabac,0) : EndIf
If value.s="false" : SetGadgetState(#nocabac,1) : EndIf
parseprofile("ChromaME")
If value.s="true" : SetGadgetState(#nochromame,0) : EndIf
If value.s="false" : SetGadgetState(#nochromame,1) : EndIf
parseprofile("NoDCTDecimate")
If value.s="true" : SetGadgetState(#nodctdecimate,1) : EndIf
If value.s="false" : SetGadgetState(#nodctdecimate,0) : EndIf
parseprofile("noFastPSkip")
If value.s="true" : SetGadgetState(#nofastpskip,1) : EndIf
If value.s="false" : SetGadgetState(#nofastpskip,0) : EndIf
parseprofile("P8x8mv")
If value.s="true" : SetGadgetState(#p8x8,1) : EndIf
If value.s="false" : SetGadgetState(#p8x8,0) : EndIf
parseprofile("PsyRDO")
If value.s="true" : SetGadgetText(#pysstrenght,"1.0")
ElseIf value.s="false" : SetGadgetText(#pysstrenght,"0.0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#pysstrenght,value.s)
EndIf
parseprofile("PsyTrellis")
If value.s="true" : SetGadgetText(#pysstrenght,GetGadgetText(#pysstrenght)+":0.0")
ElseIf value.s="false" : SetGadgetText(#pysstrenght,"0.0")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#pysstrenght,GetGadgetText(#pysstrenght)+":"+value.s)
EndIf
parseprofile("TempQuanBlurCC")
If value.s="true" : SetGadgetText(#qblur,"")
ElseIf value.s="false" : SetGadgetText(#qblur,"")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#qblur,value.s)
EndIf
parseprofile("QuantCompression")
If value.s="true" : SetGadgetText(#qcomp,"")
ElseIf value.s="false" : SetGadgetText(#qcomp,"")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#qcomp,value.s)
EndIf
parseprofile("MaxQuantizer")
If value.s="true" : SetGadgetText(#qpmax,"51")
ElseIf value.s="false" : SetGadgetText(#qpmax,"51")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#qpmax,value.s)
EndIf
parseprofile("MinQuantizer")
If value.s="true" : SetGadgetText(#qpmin,"10")
ElseIf value.s="false" : SetGadgetText(#qpmin,"10")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#qpmin,value.s)
EndIf
parseprofile("BitrateVariance")
If value.s="true" : SetGadgetText(#ratetol,"10")
ElseIf value.s="false" : SetGadgetText(#ratetol,"10")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#ratetol,value.s)
EndIf
parseprofile("SCDSensitivity")
If value.s="true" : SetGadgetText(#scenecut,"40")
ElseIf value.s="false" : SetGadgetText(#scenecut,"40")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#scenecut,value.s)
EndIf
parseprofile("SubPelRefinement")
If value.s="true" : SetGadgetText(#subme,"6")
ElseIf value.s="false" : SetGadgetText(#subme,"1")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#subme,Val(value.s))
EndIf
parseprofile("X264Trellis")
If value.s="true" : SetGadgetState(#trellis,1)
ElseIf value.s="false" : SetGadgetState(#trellis,0)
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#trellis,Val(value.s))
EndIf
parseprofile("Turbo")
If value.s="true" : SetGadgetState(#turbo,1) : EndIf
If value.s="false" : SetGadgetState(#turbo,0) : EndIf
parseprofile("VBVBufferSize")
If value.s="-1" : SetGadgetText(#vbvbufsize,"")
ElseIf value.s="false" : SetGadgetText(#vbvbufsize,"")
ElseIf value.s<>"false" And value.s<>"-1" And value.s<>"null" : SetGadgetText(#vbvbufsize,value.s)
EndIf
parseprofile("VBVInitialBuffer")
If value.s="true" : SetGadgetText(#vbvinit,"")
ElseIf value.s="false" : SetGadgetText(#vbvinit,"")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#vbvinit,value.s)
EndIf
parseprofile("VBVMaxBitrate")
If value.s="true" : SetGadgetText(#vbvmaxrate,"25000")
ElseIf value.s="-1" : SetGadgetText(#vbvmaxrate,"")
ElseIf value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#vbvmaxrate,value.s)
EndIf
parseprofile("WeightedBPrediction")
If value.s="true" : SetGadgetState(#weightb,1) : EndIf
If value.s="false" : SetGadgetState(#weightb,0) : EndIf
parseprofile("container")
If value.s="mp4" : SetGadgetText(#muxer,"mp4") : EndIf
If value.s="mkv" : SetGadgetText(#muxer,"mkv") : EndIf
parseprofile("EncodingMode")
If value.s="0" : SetGadgetState(#pass1,1) : EndIf
If value.s="4" : SetGadgetState(#pass2,1) : EndIf
If value.s="9" : SetGadgetState(#passcrf,1) : EndIf
If value.s="1" : SetGadgetState(#passcrf,1) : EndIf
parseprofile("BitrateQuantizerAutoX264")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#vbitrate,value.s) : EndIf
parseprofile("ManualBitrateAutoX264")
If value.s<>"false" And value.s<>"" : SetGadgetText(#manualbitrate,value.s) : EndIf
parseprofile("audiocodec")
If value.s="mp3" : SetGadgetText(#audioenc,"MP3 Audio") : EndIf
If value.s="aac" : SetGadgetText(#audioenc,"AAC Audio") : EndIf
parseprofile("audiobitrate")
If value.s<>"null" : SetGadgetText(#abitrate,value.s) : EndIf
parseprofile("audiochannel")
If value.s<>"null" : SetGadgetText(#channels,value.s): EndIf
parseprofile("samplerate")
If value.s<>"null" : SetGadgetText(#samplerate,value.s) : EndIf
parseprofile("mp3mode")
If value.s<>"null" : SetGadgetText(#mp3mode,value.s) : EndIf
parseprofile("normalize")
If value.s="true" : SetGadgetState(#normalize,1) : EndIf
If value.s="false" : SetGadgetState(#normalize,0) : EndIf
parseprofile("resizer")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#resizer,Val(value.s)) : EndIf
parseprofile("priority")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#priority,Val(value.s)) : EndIf
parseprofile("denoise")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#denoise,Val(value.s)) : EndIf
parseprofile("manualbitrate")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#manualbitrate,value.s) : EndIf
parseprofile("aspectratio")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#aspectratio,value.s) : EndIf
parseprofile("deinterlace")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetState(#mdeint,Val(value.s)) : EndIf
parseprofile("framerate")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#framerate,value.s) : EndIf
parseprofile("height")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#height,value.s) : EndIf
parseprofile("width")
If value.s<>"false" And value.s<>"true" And value.s<>"null" : SetGadgetText(#width,value.s) : EndIf
EndProcedure
Procedure.f RoundByClosest(base.f, factor.l)
round = Int((base / factor)+0.5) * factor
ProcedureReturn round
EndProcedure
Procedure.f RoundUpBy(base.f, factor.l)
round = Int((base / factor)+1) * factor
ProcedureReturn round
EndProcedure
Procedure.f RoundDownBy(base.f, factor.l)
round = Int(base / factor) * factor
ProcedureReturn round
EndProcedure
Procedure.l RoundByX(base.f, factor.l, bool_roundup.l)
If bool_roundup = #True : ProcedureReturn Round((base / factor),1) * factor
ElseIf bool_roundup = #False : ProcedureReturn Round((base / factor),0) * factor
EndIf
EndProcedure
Procedure silentscale()
acbottom.l=Val(GetGadgetText(#bottomcrop))
acleft.l=Val(GetGadgetText(#leftcrop))
acright.l=Val(GetGadgetText(#rightcrop))
actop.l=Val(GetGadgetText(#topcrop))
Debug(twidth.l)
Debug(theight.l)
Debug(framerate.f)
Debug(tsec.l)
Debug(ar.s)
Debug(acleft.l)
Debug(acright.l)
Debug(actop.l)
Debug(acbottom.l)
aspectinfo.f=ValF(GetGadgetText(#aspectratio))
If GetGadgetState(#itu)=1 : itu.f=53.3333/52 : EndIf ;*1.02564
If GetGadgetState(#itu)=0 : itu.f=1 : EndIf
dar.f = ((twidth.l-acleft.l-acright.l)/twidth.l)/((theight.l-actop.l-acbottom.l)/theight.l)*aspectinfo.f*itu.f
SetGadgetText(#dar,StrF(dar.f,4))
SetGadgetText(#height,StrF(RoundByClosest(ValF(GetGadgetText(#width))/dar.f,4),0))
SetGadgetText(#arerror,StrF((dar.f/(ValF(GetGadgetText(#width))/ValF(GetGadgetText(#height))))*100-100,4))
height.l=ValF(GetGadgetText(#height))
width.l=ValF(GetGadgetText(#width))
EndProcedure
Procedure silentresize()
SetGadgetText(#width,Str(GetGadgetState(#TrackBarres)*4))
silentscale()
EndProcedure
Procedure preview()
If GetGadgetText(#width)=""
MessageRequester("AutoX264", "Attention!"+Chr(10)+"Analyze file First!")
ProcedureReturn
EndIf
If LCase(GetExtensionPart(inputfile.s))="d2v"
CreateFile(999,here.s+"inputfile.avs")
WriteString(999,"mpeg2source("+Chr(34)+inputfile.s+Chr(34)+")")
CloseFile(999)
inputfile.s=dest.s+"inputfile.avs"
EndIf
;"mplayer" -vf crop=720:432:0:72,scale=640:-2 -nosound "C:\Programmi\PureBasic402\AutoFM\_aaa.VOB"
mess4.s=""
For aa=1 To CountGadgetItems(#audiopid)
If GetGadgetItemState(#audiopid,aa) & #PB_ListIcon_Checked
Debug("audiopid(aa)="+Str(aa))
Debug("1-"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"="))
aid.s="-aid "+StringField(GetGadgetItemText(#audiopid,aa,0),2,"=")
EndIf
Next aa
vcrop.s="crop="+Str(twidth.l-Val(GetGadgetText(#leftcrop))-Val(GetGadgetText(#rightcrop)))+":"+Str(theight.l-Val(GetGadgetText(#topcrop))-Val(GetGadgetText(#bottomcrop)))+":"+GetGadgetText(#leftcrop)+":"+GetGadgetText(#topcrop)
RunProgram(mpl.s,mess4.s+" -vf "+vcrop.s+",scale="+GetGadgetText(#width)+":"+GetGadgetText(#height)+" -aspect "+GetGadgetText(#aspectratio)+" "+aid.s+" "+lavf.s+Chr(34)+inputfile.s+Chr(34),here.s)
EndProcedure
Procedure autocrop2()
If LCase(GetExtensionPart(inputfile.s))="d2v"
CreateFile(999,dest.s+"inputfile.avs")
WriteString(999,"mpeg2source("+Chr(34)+inputfile.s+Chr(34)+")")
CloseFile(999)
inputfile.s=dest.s+"inputfile.avs"
EndIf
If GetGadgetText(#width)=""
MessageRequester("AutoX264", "Attention!"+Chr(10)+"Analyze file First!")
ProcedureReturn
EndIf
acbottom.l=0
acleft.l=0
cropright.l=0
actop.l=0
mess.s=""
mess1.s=""
vcrop.s=""
If demuxer35.s="1" : mess4.s=" -demuxer 35 " : EndIf
If tsec.l<=60 : ss.s="" : EndIf
If tsec.l>60 : ss.s="-sstep "+StrF(tsec.l/10,0)+" " : EndIf
wait=RunProgram(mpl.s,mess4.s+"-benchmark -vf cropdetect -nosound "+lavf.s+" -vo null -frames 300 "+ss.s+Chr(34)+inputfile.s+Chr(34),here.s,#PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)
If wait
While ProgramRunning(wait)
mess.s=ReadProgramString(wait)
If FindString(mess.s,"-vf crop=",0)
mess1.s=StringField(mess.s,1,")")
vcrop.s=Mid(StringField(mess1.s,2,"("),10,1000)
vcrop1.s=vcrop.s
EndIf
Wend
EndIf
If wait : WaitProgram(wait) : EndIf
Debug(vcrop.s)
;crop=720:432:0:72
;crop=688:560:4:8
actop.l=theight.l-Val(StringField(vcrop.s,2,":"))-Val(StringField(vcrop.s,4,":"))
acleft.l=Val(StringField(vcrop.s,3,":"))
acright.l=twidth.l-acleft.l-Val(StringField(vcrop.s,1,":"))
acbottom.l=theight.l-(Val(StringField(vcrop.s,2,":"))+actop.l)
Debug(" -cropleft "+Str(acleft.l)+" -croptop "+Str(actop.l)+" -cropright "+Str(acright.l)+" -cropbottom "+Str(acbottom.l)+" " )
SetGadgetText(#bottomcrop,"")
SetGadgetText(#leftcrop,"")
SetGadgetText(#rightcrop,"")
SetGadgetText(#topcrop,"")
SetGadgetText(#bottomcrop,Str(acbottom.l))
SetGadgetText(#leftcrop,Str(acleft.l))
SetGadgetText(#rightcrop,Str(acright.l))
SetGadgetText(#topcrop,Str(actop.l))
If actop.l>144 Or acbottom.l>144 Or acleft.l>100 Or acright.l>100
MessageRequester("AutoCrop", "Please, check autocrop value", #PB_MessageRequester_Ok )
EndIf
dar.f = ((twidth.l-acleft.l-acright.l)/twidth.l)/((theight.l-actop.l-acbottom.l)/theight.l)*aspectinfo.f*1.02564
SetGadgetText(#dar,StrF(dar.f,3))
EndProcedure
Procedure mediainfoinfo()
Global Dim audiostring.s(128)
Dim audiostring.s(128)
aa.l=0
mess.s=""
videocodec.s=""
wait=RunProgram("mediainfo"," -full "+Chr(34)+inputfile.s+Chr(34),here.s,#PB_Program_Open|#PB_Program_Hide|#PB_Program_Read)
While ProgramRunning(wait)
mess.s=ReadProgramString(wait)
If FindString(mess.s,"aspect",0)
ar.s=Trim(StringField(mess.s,2,":"))
EndIf
If FindString(mess.s,"Width",0) And FindString(mess.s,"pixel",0)
twidth.l=Val(ReplaceString(StringField(StringField(mess.s,2,":"),1,"p")," ",""))
EndIf
If FindString(mess.s,"Height",0) And FindString(mess.s,"pixel",0)
theight.l=Val(ReplaceString(StringField(StringField(mess.s,2,":"),1,"p")," ",""))
EndIf
If FindString(mess.s,"Width",0) And FindString(mess.s,"pixel",0)=0
twidth.l=Val(Trim(StringField(mess.s,2,":")))
EndIf
If FindString(mess.s,"Height",0) And FindString(mess.s,"pixel",0)=0
theight.l=Val(Trim(StringField(mess.s,2,":")))
EndIf
If FindString(mess.s,"Frame count",0)
framecount.l=Val(Trim(StringField(StringField(mess.s,2,":"),2," ")))
EndIf
If FindString(mess.s,"fps",0)
framerate.f=ValF(ReplaceString(StringField(StringField(mess.s,2,":"),1,"f")," ",""))
EndIf
If FindString(mess.s,"Aspect",0)
ar.s=Trim(StringField(mess.s,2,":"))
EndIf
If FindString(mess.s,"Duration",0) And FindString(mess.s,"ms",0)=0 And FindString(mess.s,".",0)
tsec.l=Val(StringField(mess.s,2,":"))*3600+Val(StringField(mess.s,3,":"))*60+Val(StringField(mess.s,4,":"))
EndIf
If FindString(mess.s,"Codecs Video",0)
videocodec.s=StringField(mess.s,2,":")
EndIf
Wend
WaitProgram(wait)
If FindString(ar.s,"4/3",0) : ar.s="1.3334" : EndIf
If FindString(ar.s,"16/9",0) : ar.s="1.7778" : EndIf
If FindString(ar.s,"1/1",0) : ar.s="1" : EndIf
If FindString(ar.s,"2.35",0) : ar.s="2.35" : EndIf
If FindString(ar.s,"5/4",0) : ar.s="1.25" : EndIf
Debug("videocodec="+videocodec)
Debug("ar.s="+ar.s)
Debug("twidth.l="+Str(twidth.l))
Debug("theight.l="+Str(theight.l))
Debug("framecount.l="+Str(framecount.l))
Debug("framerate.f="+StrF(framerate.f))
Debug("tsec.f="+Str(tsec.l))
If framecount.l<2 And framerate.f>5 And tsec.l>2
framecount.l=Int(tsec.l*framerate.f)+1
EndIf
Debug("framecount.l="+Str(framecount.l))
wait1=RunProgram(mpl.s,mess4.s+" -vo null -identify -benchmark -nosound -frames 1 "+ss.s+Chr(34)+inputfile.s+Chr(34),here.s,#PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)
If wait1
While ProgramRunning(wait1)
mess.s=ReadProgramString(wait1)
If GetGadgetText(#ffmpegpath)<>""
If FindString(mess,"ID_AUDIO_ID",0)
aa.l=aa.l+1
audiostring.s(aa.l)=mess.s
EndIf
EndIf
If GetGadgetText(#ffmpegpath)=""
If FindString(mess,"ID_AUDIO_ID",0)
AddGadgetItem(#audiopid,-1,StringField(mess.s,1,":"))
EndIf
EndIf
If FindString(mess,"subtitle (",0) Or FindString(mess,"subtitles (",0)
AddGadgetItem(#subspid,-1,StringField(mess.s,2,":")+StringField(mess.s,3,":"))
EndIf
Wend
EndIf
If wait1 : WaitProgram(wait) : EndIf
If GetGadgetText(#ffmpegpath)<>""
aa=0
wait1=RunProgram(GetGadgetText(#ffmpegpath)," -i "+Chr(34)+inputfile.s+Chr(34),here.s,#PB_Program_Open|#PB_Program_Error|#PB_Program_Hide)
If wait1
While ProgramRunning(wait1)
mess.s=ReadProgramError(wait1)
If FindString(mess,"Audio: ",0)
aa=aa+1
AddGadgetItem(#audiopid,aa,audiostring.s(aa)+Chr(10)+StringField(mess.s,3,":")+StringField(mess.s,4,":"))
EndIf
Wend
EndIf
EndIf
SetGadgetItemState(#audiopid,1,#PB_ListIcon_Checked)
SetGadgetItemState(#subspid,0,#PB_ListIcon_Checked)
EndProcedure
Procedure mplayerinfo()
acbottom.l=0
acleft.l=0
cropright.l=0
actop.l=0
mess.s=""
mess1.s=""
vcrop.s=""
videocodec.s=""
theight.l=0
twidth.l=0
If GetGadgetState(#lavf)=1 : lavf.s="-demuxer lavf " : EndIf
If demuxer35.s="1" : mess4.s=" -demuxer 35 " : EndIf
ss.s=""
If tsec.l<=60 : ss.s="" : EndIf
If tsec.l>60 : ss.s="-sstep "+StrF(tsec.l/10,0)+" " : EndIf
aa.l=0
wait1=RunProgram("mplayer",mess4.s+" -vo null -identify "+lavf.s+" -benchmark -nosound -vf cropdetect -frames 200 "+ss.s+Chr(34)+inputfile.s+Chr(34),here.s,#PB_Program_Open|#PB_Program_Read)
If wait1
While ProgramRunning(wait1)
mess.s=ReadProgramString(wait1)
If FindString(mess,"ID_LENGTH",0)
tsec.l=ValF(Trim(StringField(mess.s,2,"=")))
EndIf
If FindString(mess,"VDec: vo config request",0)
twidth.l=ValF(Trim(Mid(mess.s,FindString(mess.s,"-",0)+1,FindString(mess.s,"x",0)-FindString(mess.s,"-",0)-2)))
theight.l=ValF(Trim(Mid(mess.s,FindString(mess.s,"x",0)+1,FindString(mess.s,"(",0)-FindString(mess.s,"x",0)-2)))
EndIf
If FindString(mess,"ID_VIDEO_WIDTH",0)
twidth.l=ValF(StringField(mess.s,2,"="))
EndIf
If FindString(mess,"ID_VIDEO_HEIGHT",0)
theight.l=ValF(StringField(mess.s,2,"="))
EndIf
If FindString(mess," fps ",0)
aaa.s=StringField(mess.s,0,"fps")
bbb.l=CountString(aaa.s," ")
framerate.f=ValF(StringField(aaa.s,bbb," "))
EndIf
If FindString(mess.s,"ID_VIDEO_ASPECT",0)
ar.s=StringField(mess.s,2,"=")
EndIf
If FindString(mess.s,"ID_VIDEO_CODEC",0)
videocodec.s=StringField(mess.s,2,"=")
EndIf
If FindString(mess.s,"Movie-Aspect is",0)
ar.s=Trim(Mid(mess.s,FindString(mess.s," ",16),FindString(mess.s,":",0)-16))
EndIf
If FindString(mess.s,"-vf crop=",0)
mess1.s=StringField(mess.s,1,")")
vcrop.s=Mid(StringField(mess1.s,2,"("),10,1000)
vcrop1.s=vcrop.s
EndIf
If FindString(mess,"subtitle (",0) Or FindString(mess,"subtitles (",0)
AddGadgetItem(#subspid,-1,StringField(mess.s,2,":")+StringField(mess.s,3,":"))
EndIf
Wend
EndIf
If theight.l<5
aa.l=0
MessageRequester("AutoX264","Got problems while analyzing, now trying with lavf demuxer")
ClearGadgetItems(#subspid)
lavf.s="-demuxer lavf "
wait1=RunProgram(mpl.s,mess4.s+" -vo null -identify -benchmark "+lavf.s+" -nosound -vf cropdetect -frames 200 "+ss.s+Chr(34)+inputfile.s+Chr(34),here.s,#PB_Program_Open|#PB_Program_Read)
If wait1
While ProgramRunning(wait1)
mess.s=ReadProgramString(wait1)
If FindString(mess,"ID_VIDEO_WIDTH",0)
twidth.l=ValF(StringField(mess.s,2,"="))
EndIf
If FindString(mess,"ID_VIDEO_HEIGHT",0)
theight.l=ValF(StringField(mess.s,2,"="))
EndIf
If FindString(mess,"ID_LENGTH",0)
tsec.l=ValF(Trim(StringField(mess.s,2,"=")))
EndIf
If FindString(mess,"VDec: vo config request",0)
twidth.l=ValF(Trim(Mid(mess.s,FindString(mess.s,"-",0)+1,FindString(mess.s,"x",0)-FindString(mess.s,"-",0)-2)))
theight.l=ValF(Trim(Mid(mess.s,FindString(mess.s,"x",0)+1,FindString(mess.s,"(",0)-FindString(mess.s,"x",0)-2)))
EndIf
If FindString(mess," fps ",0)
aaa.s=StringField(mess.s,0,"fps")
bbb.l=CountString(aaa.s," ")
framerate.f=ValF(StringField(aaa.s,bbb," "))
EndIf
If FindString(mess.s,"ID_VIDEO_ASPECT",0)
ar.s=StringField(mess.s,2,"=")
EndIf
If FindString(mess.s,"ID_VIDEO_CODEC",0)
videocodec.s=StringField(mess.s,2,"=")
EndIf
If FindString(mess.s,"Movie-Aspect is",0)
ar.s=Trim(Mid(mess.s,FindString(mess.s," ",16),FindString(mess.s,":",0)-16))
EndIf
If FindString(mess.s,"-vf crop=",0)
mess1.s=StringField(mess.s,1,")")
vcrop.s=Mid(StringField(mess1.s,2,"("),10,1000)
vcrop1.s=vcrop.s
EndIf
If FindString(mess,"subtitle ",0) Or FindString(mess,"subtitles ",0)
AddGadgetItem(#subspid,-1,StringField(mess.s,2,":")+StringField(mess.s,3,":"))
EndIf
Wend
EndIf
If wait1 : WaitProgram(wait) : EndIf
EndIf
aa=0
mess.s=""
wait2=RunProgram("ffmpeg","-i "+inputfile.s,"",#PB_Program_Open|#PB_Program_Error)
If wait2
While ProgramRunning(wait2)
Delay(3)
mess.s=ReadProgramError(wait2)
If FindString(mess.s,"Audio: ",0)
aa=aa+1
AddGadgetItem(#audiopid,aa,StringField(StringField(mess.s,1,"["),1," ")+Chr(10)+StringField(mess.s,3,":")+StringField(mess.s,4,":"))
EndIf
Wend
EndIf
CloseProgram(wait2)
framecount.l=tsec.l*framerate.f
Debug("twidth.f="+StrF(twidth.l))
Debug("theight.f="+StrF(theight.l))
Debug("framerate.f="+StrF(framerate.f))
Debug("framecount.l="+StrF(framecount.l))
Debug("tsec.l="+StrF(tsec.l))
Debug("ar.s="+ar.s)
Debug("videocodec="+videocodec)
Debug("ar.s="+ar.s)
Debug("twidth.l="+Str(twidth.l))
Debug("theight.l="+Str(theight.l))
Debug("framecount.l="+Str(framecount.l))
Debug("framerate.f="+StrF(framerate.f))
Debug("tsec.f="+Str(tsec.l))
If ((framecount.l/framerate.f)<3 And demuxer35.s<>"1") Or ar.s=""
If stop.l<>1
If exts.s<>"avs"
demuxer35.s="1"
stop.l=1
mediainfoinfo()
EndIf
EndIf
EndIf
If ((framecount.l/framerate.f)<3 And demuxer35.s<>"1") Or ar.s=""
MessageRequester("Parsing Problem","Mplayer is unable to determine movie propierties, please fill the values on File Information")
ProcedureReturn
EndIf
Debug(vcrop.s)
actop.l=theight.l-Val(StringField(vcrop.s,2,":"))-Val(StringField(vcrop.s,4,":"))
acleft.l=Val(StringField(vcrop.s,3,":"))
acright.l=twidth.l-acleft.l-Val(StringField(vcrop.s,1,":"))
acbottom.l=theight.l-(Val(StringField(vcrop.s,2,":"))+actop.l)
Debug(" -cropleft "+Str(acleft.l)+" -croptop "+Str(actop.l)+" -cropright "+Str(acright.l)+" -cropbottom "+Str(acbottom.l)+" " )
SetGadgetText(#bottomcrop,"")
SetGadgetText(#leftcrop,"")
SetGadgetText(#rightcrop,"")
SetGadgetText(#topcrop,"")
SetGadgetText(#bottomcrop,Str(acbottom.l))
SetGadgetText(#leftcrop,Str(acleft.l))
SetGadgetText(#rightcrop,Str(acright.l))
SetGadgetText(#topcrop,Str(actop.l))
SetGadgetItemState(#audiopid,1,#PB_ListIcon_Checked)
SetGadgetItemState(#subspid,0,#PB_ListIcon_Checked)
If actop.l>100 Or acbottom.l>100 Or acleft.l>100 Or acright.l>100
MessageRequester("AutoCrop", "Please, check autocrop value", #PB_MessageRequester_Ok )
EndIf
dar.f = ((twidth.l-acleft.l-acright.l)/twidth.l)/((theight.l-actop.l-acbottom.l)/theight.l)*aspectinfo.f*1.02564
SetGadgetText(#dar,StrF(dar.f,3))
EndProcedure
Procedure infomedia()
ClearGadgetItems(#audiopid)
ClearGadgetItems(#subspid)
AddGadgetItem(#audiopid,-1,"NONE")
AddGadgetItem(#subspid,-1,"NONE")
stop.l=0
demuxer35.s=""
; -map [0:0] -map [1:0] il prima map e' il flusso nuovo ,
;il secondo dice di tenere la prima traccia audio e la traccia video 0
exts.s=LCase(GetExtensionPart(inputfile.s))
SetGadgetText(#risoluzione,"")
SetGadgetText(#framerate,"")
SetGadgetText(#lenght,"")
SetGadgetText(#aspectratio,"")
SetGadgetText(#bottomcrop,"")
SetGadgetText(#leftcrop,"")
SetGadgetText(#rightcrop,"")
SetGadgetText(#topcrop,"")
SetGadgetText(#height,"")
SetGadgetText(#width,"")
SetGadgetText(#frames,"")
twidth.l=0
theight.l=0
framerate.f=0
framecount.l=0
tsec.l=0
ar.s=""
videocodec=""
topcrop=0
bottomcrop=0
rightcrop=0
leftcrop=0
Debug("inpufile="+inputfile.s)
If GetGadgetText(#analyzewith)="mplayer" : mplayerinfo() : EndIf
If GetGadgetText(#analyzewith)="mediainfo" : mediainfoinfo() : EndIf
If ar.s<>"" : SetGadgetText(#aspectratio,ar.s) : EndIf
Debug("tsec1="+StrF(tsec.l))
tsec.l=Int(framecount.l/framerate.f)+1
Debug("tsec2="+StrF(tsec.l))
Debug(twidth.l)
Debug(theight.l)
Debug(tsec.l)
Debug(ar.s)
If ar.s=""
ar.s=StrF(twidth.l/theight.l,4)
MessageRequester("AutoX264","Unable to compute correct Aspect Ratio"+Chr(10)+"Please check")
EndIf
SetGadgetText(#risoluzione,StrF(twidth.l,0)+" / "+StrF(theight.l,0))
SetGadgetText(#framerate,StrF(framerate.f,3))
SetGadgetText(#lenght,StrF(tsec.l,0))
SetGadgetState(#aspectratio,0)
SetGadgetText(#aspectratio,ar.s)
SetGadgetText(#frames,StrF(framecount.l,0))
If GetGadgetText(#aspectratio)="1.7778" : aspectinfo.f=16/9 : EndIf
If GetGadgetText(#aspectratio)="1.3334" : aspectinfo.f=4/3 : EndIf
If framerate.f<20 Or tsec.l<5
MessageRequester("File Check", "Please, check media proprierties", #PB_MessageRequester_Ok)
EndIf
Debug("wid"=StrF(twidth.l,0))
SetGadgetAttribute(#TrackBarres,#PB_TrackBar_Maximum,(twidth.l/4)*2)
SetGadgetState(#TrackBarres,(twidth.l/4))
silentresize()
EndProcedure
Procedure starthand()
If GetGadgetState(#copyvideo)=1 Or GetGadgetState(#novideo)=1
MessageRequester("AutoX264","You cannot copy video with HandBrakeCLI encoder")
EndIf
mplayer.s=GetGadgetText(#mplayerpath)
mencoder.s=Chr(34)+GetGadgetText(#mencoderpath)+Chr(34)
mp4creator.s=Chr(34)+GetGadgetText(#mp4creatorpath)+Chr(34)
mkvmerge.s=Chr(34)+GetGadgetText(#mkvcreatorpath)+Chr(34)
handbrakecli.s="HandBrakeCLI"
If GetGadgetText(#width)=""
MessageRequester("AutoX264", "Attention!"+Chr(10)+"Analyze file First!")
ProcedureReturn
EndIf
handbrakecli.s=handbrakecli.s+" --input "+Chr(34)+inputfile.s+Chr(34)+" -L "
If GetGadgetText(#muxer)="m2ts" : SetGadgetText(#muxer,"mp4") : EndIf
If outputfile.s="" : outputfile.s=GetPathPart(inputfile.s)+"autox264_"+GetFilePart(inputfile.s)+"."+GetGadgetText(#muxer) : EndIf
handbrakecli.s=handbrakecli.s+" --output "+Chr(34)+outputfile.s+Chr(34)+" "
handbrakecli.s=handbrakecli.s+"--width "+GetGadgetText(#width)+" "
handbrakecli.s=handbrakecli.s+"--height "+GetGadgetText(#height)+" "
If GetGadgetText(#topcrop)<>""
handbrakecli.s=handbrakecli.s+"--crop "+GetGadgetText(#topcrop)+":"
handbrakecli.s=handbrakecli.s+GetGadgetText(#bottomcrop)+":"
handbrakecli.s=handbrakecli.s+GetGadgetText(#leftcrop)+":"
handbrakecli.s=handbrakecli.s+GetGadgetText(#rightcrop)+" "
EndIf
If passx.l=1 Or passx.l=2 Or passx.l=3
If passx.l=3 : handbrakecli.s=handbrakecli.s+"--two-pass " : EndIf
If GetGadgetText(#manualbitrate)=""
handbrakecli.s=handbrakecli.s+"-size "+GetGadgetText(#vbitrate)+" "
EndIf
If GetGadgetText(#manualbitrate)<>""
handbrakecli.s=handbrakecli.s+"-vb "+GetGadgetText(#manualbitrate)+" "
EndIf
EndIf
If GetGadgetState(#turbo)=1 : handbrakecli.s=handbrakecli.s+"--turbo " : EndIf
If GetGadgetText(#mdeint)="Progressive NTSC (29.97->23.976)" : handbrakecli.s=handbrakecli.s+"--detelecine " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Interlaced" :handbrakecli.s=handbrakecli.s+"--deinterlace " : EndIf
If GetGadgetText(#mdeint)="Telecine" : handbrakecli.s=handbrakecli.s+"--detelecine " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Mixed progressive and telecine" : handbrakecli.s=handbrakecli.s+"--detelecine " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Mixed progressive and interlaced" : handbrakecli.s=handbrakecli.s+"--deinterlace " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 25" : handbrakecli.s=handbrakecli.s+"--rate 25.000 " : framer.s="25 " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 23.976" : handbrakecli.s=handbrakecli.s+"--rate 23.976 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 29.97" : handbrakecli.s=handbrakecli.s+"--rate 29.97 " : framer.s="29.97 " : EndIf
If GetGadgetText(#mdeint)="Half Framerate" : handbrakecli.s=handbrakecli.s+"--rate "+StrF(ValF(GetGadgetText(#framerate))*1000,0)+"/2000 " : framer.s=StrF(Int(ValF(framer.s)/2)) : EndIf
If GetGadgetText(#denoise)="Light" : handbrakecli.s=handbrakecli.s+"--denoise weak " : EndIf
If GetGadgetText(#denoise)="Normal" : handbrakecli.s=handbrakecli.s+"--denoise mendium " : EndIf
If GetGadgetText(#denoise)="Severe" : handbrakecli.s=handbrakecli.s+"--denoise strong " : EndIf
If GetGadgetState(#greyscale)=1 : handbrakecli.s=handbrakecli.s+"--grayscale " : EndIf
handbrakecli.s=handbrakecli.s+"-e x264 "
handbrakecli.s=handbrakecli.s+"--x264opts="
If passx.l=4 : handbrakecli.s=handbrakecli.s+"crf="+GetGadgetText(#vbitrate)+":" : EndIf
handbrakecli.s=handbrakecli.s+"ref="+Str(GetGadgetState(#refframes))+":"
If GetGadgetText(#deblockalpha)<>"" And GetGadgetText(#deblockbeta)<>"" : handbrakecli.s=handbrakecli.s+"deblock="+GetGadgetText(#deblockalpha)+","+GetGadgetText(#deblockbeta)+":" : EndIf
handbrakecli.s=handbrakecli.s+"direct="+LCase(GetGadgetText(#direct))+":"
handbrakecli.s=handbrakecli.s+"subme="+Str(GetGadgetState(#subme))+":"
handbrakecli.s=handbrakecli.s+"trellis="+Str(GetGadgetState(#trellis))+":"
handbrakecli.s=handbrakecli.s+"me="+GetGadgetText(#me)+":"
If GetGadgetState(#mixedrefs)=1 : handbrakecli.s=handbrakecli.s+"mixed-refs:" : EndIf
If GetGadgetState(#weightb)=1 : handbrakecli.s=handbrakecli.s+"weightb:" : EndIf
If GetGadgetState(#nofastpskip)=1 : mencoderbat.s=mencoderbat.s+"no-fast-pskip:" : EndIf
If GetGadgetState(#bpyramid)=1 : handbrakecli.s=handbrakecli.s+"bpyramid:" : EndIf
If GetGadgetState(#nocabac)=1 : handbrakecli.s=handbrakecli.s+"no-cabac:" : EndIf
If GetGadgetText(#keyint)<>"" : handbrakecli.s=handbrakecli.s+"keyint="+GetGadgetText(#keyint)+":" : EndIf
If GetGadgetText(#keyintmin)<>"126" : handbrakecli.s=handbrakecli.s+"min-keyint="+GetGadgetText(#keyintmin)+":" : EndIf
If GetGadgetState(#nocabac)=1 : handbrakecli.s=handbrakecli.s+"no-cabac:" : EndIf
If passx.l<>2
If GetGadgetState(#allpartition)=0
If GetGadgetState(#i4x4)=1 Or GetGadgetState(#i8x8)=1 Or GetGadgetState(#p8x8)=1 Or GetGadgetState(#b8x8)=1
partitions.s="partitions="
If GetGadgetState(#p8x8)=1 : partitions.s=partitions.s+"p8x8," : EndIf
If GetGadgetState(#i8x8)=1 : partitions.s=partitions.s+"i8x8," : EndIf
If GetGadgetState(#b8x8)=1 : partitions.s=partitions.s+"b8x8," : EndIf
;If GetGadgetState(#p4x4)=1 : partitions.s=partitions.s+"p4x4" : EndIf
If Right(partitions.s,1)="," : partitions.s=RSet(partitions.s,Len(partitions.s)-1)+" " : EndIf
If GetGadgetState(#dct8x8)=1 : partitions.s=partitions.s+"8x8dct:" : EndIf
EndIf
handbrakecli.s=handbrakecli.s+partitions.s+" "
EndIf
EndIf
If GetGadgetState(#allpartition)=1 And passx.l<>2 : handbrakecli.s=handbrakecli.s+"partitions=all:" : EndIf
If passx.l<>2
If GetGadgetState(#dct8x8)=1 : handbrakecli.s=handbrakecli.s+"8x8dct:" : EndIf
EndIf
handbrakecli.s=handbrakecli.s+"aq-mode="+Str(GetGadgetState(#aqmode))+":"
handbrakecli.s=handbrakecli.s+"aq-strength="+GetGadgetText(#aqstrenght)+":"
If GetGadgetText(#pysstrenght)<>"" : handbrakecli.s=handbrakecli.s+"psy-rd="+GetGadgetText(#pysstrenght)+":" : EndIf
handbrakecli.s=handbrakecli.s+"bframes="+GetGadgetText(#bframes)+":"
If GetGadgetText(#vbvmaxrate)<>"" : handbrakecli.s=handbrakecli.s+"vbv-maxrate="+GetGadgetText(#vbvmaxrate)+":" : EndIf
If GetGadgetText(#vbvbufsize)<>"" : handbrakecli.s=handbrakecli.s+"vbv-bufsize="+GetGadgetText(#vbvbufsize)+":" : EndIf
If GetGadgetState(#allpartition)=1 And passx.l<>2 : handbrakecli.s=handbrakecli.s+"partitions=all:" : EndIf
If GetGadgetText(#bbias)<>"0" : handbrakecli.s=handbrakecli.s+"b-bias="+GetGadgetText(#bbias)+":" : EndIf
If GetGadgetText(#ipratio)<>"1.40" : handbrakecli.s=handbrakecli.s+"ipratio="+GetGadgetText(#ipratio)+":" : EndIf
If GetGadgetText(#pbratio)<>"1.40" : handbrakecli.s=handbrakecli.s+"pbratio="+GetGadgetText(#pbratio)+":" : EndIf
If GetGadgetText(#chromaqpoffset)<>"0" : handbrakecli.s=handbrakecli.s+"chroma-qp-offset="+GetGadgetText(#chromaqpoffset)+":" : EndIf
If GetGadgetText(#mvrange)<>"-1" : handbrakecli.s=handbrakecli.s+"mvrange="+GetGadgetText(#mvrange)+":" : EndIf
If GetGadgetText(#mvrangethread)<>"-1" : handbrakecli.s=handbrakecli.s+"mvrange-thread="+GetGadgetText(#mvrangethread)+":" : EndIf
If GetGadgetText(#deadzoneinter)<>"21" : handbrakecli.s=handbrakecli.s+"deadzone-inter="+GetGadgetText(#deadzoneinter)+":" : EndIf
If GetGadgetText(#deadzoneintra)<>"11" : handbrakecli.s=handbrakecli.s+"deadzone-intra="+GetGadgetText(#deadzoneintra)+":" : EndIf
If GetGadgetState(#aud)=1 : handbrakecli.s=handbrakecli.s+"aud:": EndIf
If GetGadgetState(#badapt)=2 : handbrakecli.s=handbrakecli.s+"b-adapt=2:" : EndIf
handbrakecli.s=handbrakecli.s+"aq-mode="+Str(GetGadgetState(#aqmode))+":"
handbrakecli.s=handbrakecli.s+"aq-strength="+GetGadgetText(#aqstrenght)+":"
If GetGadgetState(#bframes)>1 And GetGadgetState(#weightb)=1 : handbrakecli.s=handbrakecli.s+"weightb:" : EndIf
If GetGadgetState(#nochromame)=1 : handbrakecli.s=handbrakecli.s+"nochroma-me:" : EndIf
If GetGadgetState(#nodctdecimate)=1 : handbrakecli.s=handbrakecli.s+"--no-dct-decimate " : EndIf
If GetGadgetState(#nofastpskip)=1 : handbrakecli.s=handbrakecli.s+"--no-fast-pskip " : EndIf
If GetGadgetState(#bpyramid)=1 : handbrakecli.s=handbrakecli.s+"--b-pyramid " : EndIf
If GetGadgetText(#level)<>"AUTO" : handbrakecli.s=handbrakecli.s+"--level "+GetGadgetText(#level)+" " : EndIf
If GetGadgetText(#vbvinit)<>"" And GetGadgetText(#vbvinit)<>"0.9" : handbrakecli.s=handbrakecli.s+"vbv-init="+GetGadgetText(#vbvinit)+":" : EndIf
If GetGadgetText(#qcomp)<>"0.6" And GetGadgetText(#qcomp)<>"": handbrakecli.s=handbrakecli.s+"qcomp="+GetGadgetText(#qcomp)+":" : EndIf
If GetGadgetText(#qpmin)<>"10" : handbrakecli.s=handbrakecli.s+"qpmin="+GetGadgetText(#qpmin)+":" : EndIf
If GetGadgetText(#qpmax)<>"51" : handbrakecli.s=handbrakecli.s+"qpmax="+GetGadgetText(#qpmax)+":" : EndIf
If passx<>4 And GetGadgetText(#ratetol)<>"1.0" : handbrakecli.s=handbrakecli.s+"ratetol="+GetGadgetText(#ratetol)+":" : EndIf
If GetGadgetText(#scenecut)<>"40" : handbrakecli.s=handbrakecli.s+"scenecut="+GetGadgetText(#scenecut)+":" : EndIf
If passx=3 And GetGadgetText(#cplxblur)<>"20" : handbrakecli.s=handbrakecli.s+"cplx_blur="+GetGadgetText(#cplxblur)+":" : EndIf
If passx=3 And GetGadgetText(#qblur)<>"0" : handbrakecli.s=handbrakecli.s+"qblur="+GetGadgetText(#qblur)+":" : EndIf
If Right(handbrakecli.s,1)=":" : handbrakecli.s=Mid(handbrakecli.s,0,Len(handbrakecli.s)-1)+" " : EndIf
If GetGadgetText(#audioenc)<>"No Audio"
handbrakecli.s=handbrakecli.s+"--audio "
Debug("CountGadgetItems(#audiopid)="+Str(CountGadgetItems(#audiopid)))
For aa=1 To CountGadgetItems(#audiopid)
If GetGadgetItemState(#audiopid,aa) & #PB_ListIcon_Checked
handbrakecli.s=handbrakecli.s+Str((GetGadgetItemState(#audiopid,aa))-1)+","
EndIf
Next aa
If Right(handbrakecli.s,1)="," : handbrakecli.s=RSet(handbrakecli.s,Len(handbrakecli.s)-1)+" " : EndIf
down.s="" : samplerate.s="" : drc.s=""
;If GetGadgetText(#channels)="6" : down.s="-6 " : EndIf
If GetGadgetText(#channels)="1" : down.s="--mixdown mono " : EndIf
If GetGadgetText(#samplerate)<>"AUTO" : samplerate.s="--arate "+GetGadgetText(#samplerate)+" " : EndIf
If GetGadgetText(#audioenc)="AAC Audio" : handbrakecli.s=handbrakecli.s+down.s+"--aencoder faac --ab="+GetGadgetText(#abitrate)+" "+samplerate.s+drc.s+" " : EndIf
If GetGadgetText(#audioenc)="MP3 Audio" : handbrakecli.s=handbrakecli.s+down.s+"--aencoder lame --ab="+GetGadgetText(#abitrate)+" "+samplerate.s+drc.s+" " : EndIf
If GetGadgetText(#audioenc)="Copy Audio" : handbrakecli.s=handbrakecli.s+"--aencoder ac3 " : EndIf
If GetGadgetState(#normalize)=1 : drc.s="--drc 1.0 " : EndIf
EndIf
If queue.l=1
AddGadgetItem(#queue,-1,handbrakecli.s)
ProcedureReturn
EndIf
If passx.l<>3
CreateFile(777,GetCurrentDirectory()+"autox264.bat")
EndIf
If passx.l=3
OpenFile(777,GetCurrentDirectory()+"autox264.bat")
FileSeek(777, Lof(777) )
EndIf
WriteStringN(777,handbrakecli.s)
CloseFile(777)
If passx.l<>2
RunProgram("chmod"," 777 autox264.bat",GetCurrentDirectory())
RunProgram("xterm","-e ./autox264.bat",GetCurrentDirectory())
EndIf
queue.l=0
EndProcedure
Procedure start()
mplayer.s=GetGadgetText(#mplayerpath)
mencoder.s=Chr(34)+GetGadgetText(#mencoderpath)+Chr(34)
mp4creator.s=Chr(34)+GetGadgetText(#mp4creatorpath)+Chr(34)
mkvmerge.s=Chr(34)+GetGadgetText(#mkvcreatorpath)+Chr(34)
If GetGadgetText(#width)=""
MessageRequester("AutoX264", "Attention!"+Chr(10)+"Analyze file First!")
ProcedureReturn
EndIf
mencoderbat.s=""
mencoderbat.s=mencoderbat.s+GetGadgetText(#mencoderpath)+" "
If GetGadgetText(#mdeint)="Progressive NTSC (29.97->23.976)" : mdeint.s=",pullup,softskip -ofps 24000/1001 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Interlaced" : mdeint.s=",yadif " : EndIf
If GetGadgetText(#mdeint)="Telecine" : mdeint.s=",pullup,softskip -ofps 24000/1001 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Mixed progressive and telecine" : mdeint.s=",pullup,softskip -ofps 24000/1001 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Mixed progressive and interlaced" : mdeint.s=",yadif " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 25" : mdeint.s=" -ofps 25000/1000 " : framer.s="25 " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 23.976" : mdeint.s=" -ofps 24000/1000 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 29.97" : mdeint.s=" -ofps 30000/1001 " : framer.s="29.97 " : EndIf
If GetGadgetText(#mdeint)="Half Framerate" : mdeint.s=" -ofps "+StrF(ValF(GetGadgetText(#framerate))*1000,0)+"/2000 " : framer.s=StrF(Int(ValF(framer.s)/2)) : EndIf
If GetGadgetText(#mdeint)="none" Or GetGadgetText(#mdeint)="Threat as 25 fps": mdeint.s=" " : EndIf
;If GetExtensionPart(inputfile.s)="dvr-ms" : mdeint.s=mdeint.s+" -demuxer 35 " : EndIf
If GetGadgetText(#bottomcrop)<>"" Or GetGadgetText(#topcrop)<>"" Or GetGadgetText(#leftcrop)<>"" Or GetGadgetText(#rightcrop)<>""
vcrop.s="crop="+Str(twidth.l-Val(GetGadgetText(#leftcrop))-Val(GetGadgetText(#rightcrop)))+":"+Str(theight.l-Val(GetGadgetText(#topcrop))-Val(GetGadgetText(#bottomcrop)))+":"+GetGadgetText(#leftcrop)+":"+GetGadgetText(#topcrop)
EndIf
If GetGadgetText(#bottomcrop)=""
If vcrop.s="" : vcrop.s="crop=0:0:0:0" : EndIf
EndIf
mencoderbat.s=mencoderbat.s+"-vf harddup,"+vcrop.s+",scale="+GetGadgetText(#width)+":"+GetGadgetText(#height)
If GetGadgetText(#denoise)="None" : denoise.s="" : EndIf
If GetGadgetText(#denoise)="Light" : denoise.s=",hqdn3d=2:1:2" : EndIf
If GetGadgetText(#denoise)="Normal" : denoise.s=",hqdn3d" : EndIf
If GetGadgetText(#denoise)="Severe" : denoise.s=",hqdn3d=6:4:8" : EndIf
mencoderbat.s=mencoderbat.s+denoise.s+mdeint.s+" "
mencoderbat.s=mencoderbat.s+"-sws "+Str(GetGadgetState(#resizer))+" "
If GetGadgetText(#aspectratio)<>"Automatic" : mencoderbat.s=mencoderbat.s+"-aspect "+GetGadgetText(#aspectratio)+" " : EndIf
sid.s=""
; store sid selected
For aa=1 To CountGadgetItems(#subspid)
If GetGadgetItemState(#subspid,aa) & #PB_ListIcon_Checked
sid.s="-sid "+Str(aa-1)+" "
EndIf
Next aa
If GetGadgetItemState(#subspid,0) & #PB_ListIcon_Checked ; if no subs selected set SID to high value will disable automatic subs encoding
sid.s="-sid "+Str(CountGadgetItems(#subspid)+2)+" "
EndIf
mencoderbat.s=mencoderbat.s+sid.s
mencoderbat.s=mencoderbat.s+"-of rawvideo -o "+Chr(34)+here.s+"autox264.h264"+Chr(34)+" "+lavf.s+" "
If GetGadgetState(#copyvideo)=0 And GetGadgetState(#novideo)=0
mencoderbat.s=mencoderbat.s+"-nosound -ovc x264 -x264encopts "
bitrate.s=StrF(((Val(GetGadgetText(#vbitrate))*1000*1000-Val(GetGadgetText(#frames))*24-Val(GetGadgetText(#abitrate))*1000*Val(GetGadgetText(#lenght))*0.126)/((Val(GetGadgetText(#lenght))*0.126)/1024)/1000)/1005,0)
If GetGadgetText(#manualbitrate)<>"" : bitrate.s=GetGadgetText(#manualbitrate) : EndIf
If passx.l=1 : bitrate.s="bitrate="+bitrate.s+":" : EndIf
If passx.l=2 : bitrate.s="bitrate="+bitrate.s+":pass=1:" : EndIf
If passx.l=3 : bitrate.s="bitrate="+bitrate.s+":pass=2:" : EndIf
If passx.l=4 : bitrate.s="crf="+GetGadgetText(#vbitrate)+":" : EndIf
mencoderbat.s=mencoderbat.s+bitrate.s+"threads=auto:"
mencoderbat.s=mencoderbat.s+"bframes="+GetGadgetText(#bframes)+":"
partitions.s="partitions="
If passx.l<>2
If GetGadgetState(#allpartition)=0
If GetGadgetState(#i4x4)=1 Or GetGadgetState(#i8x8)=1 Or GetGadgetState(#p8x8)=1 Or GetGadgetState(#b8x8)=1
If GetGadgetState(#i4x4)=1 : partitions.s=partitions.s+"i4x4," : EndIf
If GetGadgetState(#i8x8)=1 : partitions.s=partitions.s+"i8x8," : EndIf
If GetGadgetState(#p8x8)=1 : partitions.s=partitions.s+"p8x8," : EndIf
If GetGadgetState(#b8x8)=1 : partitions.s=partitions.s+"b8x8" : EndIf
If Right(partitions.s,1)="," : partitions.s=Mid(partitions.s,0,Len(partitions.s)-1) : EndIf
EndIf
EndIf
EndIf
If GetGadgetState(#allpartition)=1 And passx.l<>2 : partitions="partitions=all" : EndIf
If partitions.s<>"partitions=" : mencoderbat.s=mencoderbat.s+partitions.s+":" : EndIf
If GetGadgetState(#dct8x8)=1 : mencoderbat.s=mencoderbat.s+"8x8dct:" : EndIf
If GetGadgetState(#bframes)>0
If GetGadgetText(#direct)<>""
mencoderbat.s=mencoderbat.s+"direct_pred="+GetGadgetText(#direct)+":"
EndIf
EndIf
mencoderbat.s=mencoderbat.s+"me="+GetGadgetText(#me)+":"
mencoderbat.s=mencoderbat.s+"subq="+Str(GetGadgetState(#subme)+1)+":"
If GetGadgetState(#badapt)=2 : mencoderbat.s=mencoderbat.s+"b_adapt=2:": EndIf
If GetGadgetState(#nocabac)=1 : mencoderbat.s=mencoderbat.s+"nocabac:" : EndIf
If GetGadgetState(#turbo)=1 : mencoderbat.s=mencoderbat.s+"turbo=2:" : EndIf
If GetGadgetState(#refframes)>1 : mencoderbat.s=mencoderbat.s+"frameref="+Str(GetGadgetState(#refframes))+":" : EndIf
If GetGadgetText(#deblockalpha)<>"" And GetGadgetText(#deblockbeta)<>"" : mencoderbat.s=mencoderbat.s+"deblock="+GetGadgetText(#deblockalpha)+","+GetGadgetText(#deblockbeta)+":" : EndIf
If OSVersion()<>1200 : mencoderbat.s=mencoderbat.s+"aq_mode="+Str(GetGadgetState(#aqmode))+":" : EndIf
If OSVersion()<>1200 : mencoderbat.s=mencoderbat.s+"aq_strength="+GetGadgetText(#aqstrenght)+":" : EndIf
If OSVersion()<>1200 : mencoderbat.s=mencoderbat.s+"psy-rd="+StringField(GetGadgetText(#pysstrenght),1,":")+","+StringField(GetGadgetText(#pysstrenght),2,":")+":" : EndIf
If GetGadgetState(#bframes)>1 And GetGadgetState(#weightb)=1 : mencoderbat.s=mencoderbat.s+"weight_b:" : EndIf
If GetGadgetText(#merange)<>"16" : mencoderbat.s=mencoderbat.s+"me_range="+GetGadgetText(#merange )+":" : EndIf
If GetGadgetState(#trellis)>0 : mencoderbat.s=mencoderbat.s+"trellis="+Str(GetGadgetState(#trellis))+":" : EndIf
If GetGadgetState(#nochromame)=1 : mencoderbat.s=mencoderbat.s+"nochroma_me:" : EndIf
If GetGadgetState(#mixedrefs)=1 : mencoderbat.s=mencoderbat.s+"mixed_refs:" : EndIf
If GetGadgetState(#nodctdecimate)=1 : mencoderbat.s=mencoderbat.s+"nodct_decimate:" : EndIf
If GetGadgetState(#nofastpskip)=1 : mencoderbat.s=mencoderbat.s+"nofast_pskip:" : EndIf
If GetGadgetState(#bpyramid)=1 : mencoderbat.s=mencoderbat.s+"b_pyramid:" : EndIf
If GetGadgetText(#keyint)<>"250" : mencoderbat.s=mencoderbat.s+"keyint="+GetGadgetText(#keyint)+":" : EndIf
If GetGadgetText(#keyintmin)<>"126" : mencoderbat.s=mencoderbat.s+"keyint_min="+GetGadgetText(#keyintmin)+":" : EndIf
If GetGadgetText(#level)<>"AUTO" And GetGadgetText(#level)<>"" : mencoderbat.s=mencoderbat.s+"level="+GetGadgetText(#level)+":" : EndIf
If GetGadgetText(#vbvmaxrate)<>"" : mencoderbat.s=mencoderbat.s+"vbv_maxrate="+GetGadgetText(#vbvmaxrate)+":" : EndIf
If GetGadgetText(#vbvbufsize)<>"" : mencoderbat.s=mencoderbat.s+"vbv_bufsize="+GetGadgetText(#vbvbufsize)+":" : EndIf
If GetGadgetText(#vbvinit)<>"" And GetGadgetText(#vbvinit)<>"0.9" : mencoderbat.s=mencoderbat.s+"vbv_init="+GetGadgetText(#vbvinit)+":" : EndIf
If GetGadgetText(#qcomp)<>"0.6" And GetGadgetText(#qcomp)<>"": mencoderbat.s=mencoderbat.s+"qcomp="+GetGadgetText(#qcomp)+":" : EndIf
If GetGadgetText(#qpmin)<>"10" : mencoderbat.s=mencoderbat.s+"qp_min="+GetGadgetText(#qpmin)+":" : EndIf
If GetGadgetText(#qpmax)<>"51" : mencoderbat.s=mencoderbat.s+"qp_max="+GetGadgetText(#qpmax)+":" : EndIf
If passx<>4 And GetGadgetText(#ratetol)<>"1.0" : mencoderbat.s=mencoderbat.s+"ratetol="+GetGadgetText(#ratetol)+":" : EndIf
If GetGadgetText(#scenecut)<>"40" : mencoderbat.s=mencoderbat.s+"scenecut="+GetGadgetText(#scenecut)+":" : EndIf
If passx=3 And GetGadgetText(#cplxblur)<>"20" : mencoderbat.s=mencoderbat.s+"cplx_blur="+GetGadgetText(#cplxblur)+":" : EndIf
If passx=3 And GetGadgetText(#qblur)<>"0" : mencoderbat.s=mencoderbat.s+"qblur="+GetGadgetText(#qblur)+":" : EndIf
If Right(mencoderbat.s,1)=":" : mencoderbat.s=Mid(mencoderbat.s,0,Len(mencoderbat.s)-1) : EndIf
EndIf
If GetGadgetState(#copyvideo)=1 : mencoderbat.s=mencoderbat.s+"-ovc copy -nosound " : EndIf
If GetGadgetText(#subtitlepath)<>""
If GetGadgetState(#encrustsubs)=1 : mencoderbat.s=mencoderbat.s+" -sub "+Chr(34)+GetGadgetText(#subtitlepath)+Chr(34)+" " : EndIf
EndIf
inputfiletoprocess.s=Chr(34)+GetGadgetText(#inputfilepath)+Chr(34)
If FindString(inputfile.s,"_1",0)
For aa=1 To 128
If FileSize(GetPathPart(inputfile)+Mid(GetFilePart(inputfile),0,Len(GetFilePart(inputfile))-3-Len(GetExtensionPart(inputfile)))+"_"+Str(aa)+"."+GetExtensionPart(inputfile))<>-1
MessageRequester("",GetPathPart(inputfile)+Mid(GetFilePart(inputfile),0,Len(GetFilePart(inputfile))-3-Len(GetExtensionPart(inputfile)))+"_"+Str(aa)+"."+GetExtensionPart(inputfile))
inputfile1.s=inputfile1.s+" "+Chr(34)+GetPathPart(inputfile)+Mid(GetFilePart(inputfile),0,Len(GetFilePart(inputfile))-3-Len(GetExtensionPart(inputfile)))+"_"+Str(aa)+"."+GetExtensionPart(inputfile)+Chr(34)
EndIf
Next aa
inputfile1.s=ReplaceString(inputfile1.s,inputfile.s,Chr(34)+inputfile.s)
inputfiletoprocess.s=Mid(inputfile1.s,3,Len(inputfile1.s)-2)
EndIf
mencoderbat.s=mencoderbat.s+" "+inputfiletoprocess.s
mplayer.s=GetGadgetText(#mplayerpath)
mencoder.s=GetGadgetText(#mencoderpath)
mp4creator.s=GetGadgetText(#mp4creatorpath)
mkvmerge.s=GetGadgetText(#mkvcreatorpath)
If GetGadgetText(#audioenc)="No Audio" Or passx.l=2 : mencoderbat.s=mencoderbat.s+" -nosound " : EndIf
If GetGadgetState(#novideo)=1 : mencoderbat.s="" : EndIf
If GetGadgetText(#audioenc)<>"No Audio" And passx.l<>2
handleaudio()
EndIf
handlesubs()
mencoderbat.s=mencoderbat.s+eac3toaudio.s
If outputfile.s="" : outputfile.s=GetPathPart(inputfile.s)+"autox264_"+GetFilePart(inputfile.s)+"."+GetGadgetText(#muxer) : EndIf
fps.s=GetGadgetText(#framerate)
If Mid(fps.s,0,4)="29.9"
If GetGadgetText(#mdeint)="Progressive NTSC (29.97->23.976)" Or GetGadgetText(#mdeint)="Change framerate to 23.976" Or GetGadgetText(#mdeint)="Telecine"
fps.s="23.976"
EndIf
EndIf
audiofile.s=""
For aa=1 To CountGadgetItems(#audiopid)
If GetGadgetText(#audioenc)="AAC Audio" : extaudio.s="aac" : EndIf
If GetGadgetText(#audioenc)="Copy Audio" : extaudio.s="ac3" : EndIf
If GetGadgetText(#audioenc)="MP3 Audio" : extaudio.s="mp3" : EndIf
If GetGadgetState(#neroq)=1 : extaudio.s="mp4" : EndIf
If GetGadgetState(#enceac3to)=1 : extaudio.s=GetGadgetText(#eac3tocodec) : EndIf
If GetGadgetItemState(#audiopid,aa) & #PB_ListIcon_Checked
Debug("1-"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"="))
aid.s=StringField(StringField(GetGadgetItemText(#audiopid,aa,0),2,","),2," ")
If GetGadgetText(#muxer)="mkv"
audiofile.s=audiofile.s+" "+Chr(34)+here.s+"audiox264-pid"+aid.s+"."+extaudio.s+Chr(34)+" "
EndIf
If GetGadgetText(#muxer)="mp4"
audiofile.s=audiofile.s+" -add "+Chr(34)+here.s+"audiox264-pid"+aid.s+"."+extaudio.s+Chr(34)+" "
EndIf
EndIf
Next aa
If passx.l<>2
mux()
EndIf
If GetGadgetState(#deletetempfile)=1
mencoderbat.s=mencoderbat.s+Chr(10)+"rm "+GetCurrentDirectory()+"autox264-pid*.*"
mencoderbat.s=mencoderbat.s+Chr(10)+"rm "+GetCurrentDirectory()+"autox264.h264"
EndIf
If queue.l=1
AddGadgetItem(#queue,-1,mencoderbat.s)
ProcedureReturn
EndIf
If passx.l<>3
CreateFile(777,GetCurrentDirectory()+"autox264.bat")
EndIf
If passx.l=3
OpenFile(777,GetCurrentDirectory()+"autox264.bat")
FileSeek(777, Lof(777) )
EndIf
WriteStringN(777,mencoderbat.s)
CloseFile(777)
If passx.l<>2
RunProgram("chmod"," 777 autox264.bat",GetCurrentDirectory())
RunProgram("xterm","-e ./autox264.bat",GetCurrentDirectory())
EndIf
queue.l=0
EndProcedure
Procedure ffmpeg()
If GetGadgetText(#width)=""
MessageRequester("AutoX264", "Attention!"+Chr(10)+"Analyze file First!")
ProcedureReturn
EndIf
mencoderbat.s=""
mplayer.s=GetGadgetText(#mplayerpath)
mencoder.s=mencoder.s+"ffmpeg "
mp4creator.s=Chr(34)+GetGadgetText(#mp4creatorpath)+Chr(34)
mkvmerge.s=Chr(34)+GetGadgetText(#mkvcreatorpath)+Chr(34)
fps.s=GetGadgetText(#framerate)
Select GetGadgetState(#mdeint)
Case 1,3,4,6
fps.s="23.976"
Case 7
fps.s="25"
Case 8
fps.s="29.97"
Case 9
fps.s=StrF(ValF(GetGadgetText(#framerate))/2,3)
EndSelect
mencoderbat.s=mencoderbat.s+"ffmpeg "
mencoderbat.s=mencoderbat.s+"-i "+Chr(34)+inputfile.s+Chr(34)+" -an "
If GetGadgetState(#copyvideo)=0 Or GetGadgetState(#novideo)=0
If GetGadgetText(#mdeint)="Progressive NTSC (29.97->23.976)" : mdeint.s="-fps 23.976 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Interlaced" : mdeint.s="-deinterlace " : EndIf
If GetGadgetText(#mdeint)="Telecine" : mdeint.s="-fps 23.976 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Mixed progressive and telecine" : mdeint.s="-fps 23.976 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Mixed progressive and interlaced" : mdeint.s="-deinterlace " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 25" : mdeint.s=" -fps 25 " : framer.s="25 " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 23.976" : mdeint.s="-fps 23.976 " : framer.s="23.976 " : EndIf
If GetGadgetText(#mdeint)="Change framerate to 29.97" : mdeint.s="-fps 29.97 " : framer.s="29.97 " : EndIf
If GetGadgetText(#mdeint)="Half Framerate" : mdeint.s=" -fps "+StrF(ValF(GetGadgetText(#framerate))*0.5,0) : framer.s=StrF(Int(ValF(framer.s)/2)) : EndIf
mencoderbat.s=mencoderbat.s+mdeint.s
If GetGadgetText(#bottomcrop)<>"" Or GetGadgetText(#topcrop)<>"" Or GetGadgetText(#leftcrop)<>"" Or GetGadgetText(#rightcrop)<>""
vcrop.s="-cropleft "+GetGadgetText(#leftcrop)+" -croptop "+GetGadgetText(#topcrop)+" -cropright "+GetGadgetText(#rightcrop)+" -cropbottom "+GetGadgetText(#bottomcrop)+" "
EndIf
mencoderbat.s=mencoderbat.s+vcrop.s+"-s "+GetGadgetText(#width)+"x"+GetGadgetText(#height)+" "
If GetGadgetText(#aspectratio)<>"Automatic" : mencoderbat.s=mencoderbat.s+"-aspect "+GetGadgetText(#aspectratio)+" " : EndIf
bitrate.s=StrF(((Val(GetGadgetText(#vbitrate))*1000*1016-Val(GetGadgetText(#frames))*24-Val(GetGadgetText(#abitrate))*1000*Val(GetGadgetText(#lenght))*0.126)/((Val(GetGadgetText(#lenght))*0.126)/1024)/1000)/1000,0)
If GetGadgetText(#manualbitrate)<>"" : bitrate.s=GetGadgetText(#manualbitrate) : EndIf
If passx.l=1 : mencoderbat.s=mencoderbat.s+"-b "+bitrate.s+"k " : EndIf
If passx.l=2 : mencoderbat.s=mencoderbat.s+"-pass 1 -b "+bitrate.s+"k " : EndIf
If passx.l=3 : mencoderbat.s=mencoderbat.s+"-pass 2 -b "+bitrate.s+"k " : EndIf
If passx.l=4 : mencoderbat.s=mencoderbat.s+"-crf "+GetGadgetText(#vbitrate)+" " : EndIf
mencoderbat.s=mencoderbat.s+"-threads 0 "
mencoderbat.s=mencoderbat.s+"-bf "+GetGadgetText(#bframes)+" "
If passx.l<>2
If GetGadgetState(#allpartition)=0
If GetGadgetState(#i4x4)=1 Or GetGadgetState(#i8x8)=1 Or GetGadgetState(#p8x8)=1 Or GetGadgetState(#b8x8)=1
partitions.s="-partitions "
If GetGadgetState(#p8x8)=1 : partitions.s=partitions.s+"+partp8x8" : EndIf
If GetGadgetState(#i8x8)=1 : partitions.s=partitions.s+"+parti8x8" : EndIf
If GetGadgetState(#b8x8)=1 : partitions.s=partitions.s+"+partb8x8" : EndIf
If GetGadgetState(#p4x4)=1 : partitions.s=partitions.s+"+partp4x4" : EndIf
partitions.s=partitions.s+" "
If GetGadgetState(#dct8x8)=1 : partitions.s=partitions.s+"-flags2 +dct8x8 " : EndIf
EndIf
mencoderbat.s=mencoderbat.s+partitions.s+" "
EndIf
EndIf
If GetGadgetState(#allpartition)=1 And passx.l<>2 : mencoderbat.s=mencoderbat.s+"-partitions all " : EndIf
If passx.l<>2
If GetGadgetState(#dct8x8)=1 : mencoderbat.s=mencoderbat.s+"-flags2 +dct8x8 " : EndIf
EndIf
If GetGadgetState(#bframes)>0
If GetGadgetText(#direct)<>""
Select GetGadgetText(#direct)
Case "none"
mencoderbat.s=mencoderbat.s+"-directpred 0 "
Case "spatial"
mencoderbat.s=mencoderbat.s+"-directpred 1 "
Case "temporal"
mencoderbat.s=mencoderbat.s+"-directpred 2 "
Case "auto"
mencoderbat.s=mencoderbat.s+"-directpred auto "
EndSelect
EndIf
EndIf
If passx.l=1 Or passx.l=2 Or passx.l=4
Select GetGadgetState(#me)
Case 0
mencoderbat.s=mencoderbat.s+"-me_method epzs "
Case 1
mencoderbat.s=mencoderbat.s+"-me_method hex "
Case 2
mencoderbat.s=mencoderbat.s+"-me_method umh "
Case 3,4
mencoderbat.s=mencoderbat.s+"-me_method full "
EndSelect
EndIf
If passx.l=3
Select GetGadgetState(#me)
Case 0
mencoderbat.s=mencoderbat.s+"-dia_size 1 "
Case 1
mencoderbat.s=mencoderbat.s+"-dia_size 2 "
Case 2
mencoderbat.s=mencoderbat.s+"-dia_size -1 "
Case 3,4
mencoderbat.s=mencoderbat.s+"-dia_size -2 "
EndSelect
EndIf
mencoderbat.s=mencoderbat.s+"-subq "+Str(GetGadgetState(#subme)+1)+" "
If passx.l<>3
If GetGadgetState(#badapt)=0 : mencoderbat.s=mencoderbat.s+"-b_strategy 0 " : EndIf
If GetGadgetState(#badapt)=1 : mencoderbat.s=mencoderbat.s+"-b_strategy 1 " : EndIf
If GetGadgetState(#badapt)=2 : mencoderbat.s=mencoderbat.s+"-b_strategy 2 " : EndIf
EndIf
If GetGadgetState(#nocabac)=1 : mencoderbat.s=mencoderbat.s+"-coder 0 " : EndIf
If GetGadgetState(#nocabac)=0 : mencoderbat.s=mencoderbat.s+"-coder 1 " : EndIf
If GetGadgetState(#refframes)>1 : mencoderbat.s=mencoderbat.s+"-refs "+Str(GetGadgetState(#refframes))+" " : EndIf
If GetGadgetText(#deblockalpha)<>"" And GetGadgetText(#deblockbeta)<>"" : mencoderbat.s=mencoderbat.s+"-deblockalpha "+GetGadgetText(#deblockalpha)+" -deblockbeta "+GetGadgetText(#deblockbeta)+" " : EndIf
;mencoderbat.s=mencoderbat.s+"--aq-mode "+Str(GetGadgetState(#aqmode))+" " ; supported by ffmpeg
;mencoderbat.s=mencoderbat.s+"--aq-strength "+GetGadgetText(#aqstrenght)+" " ; supported by ffmpeg
;mencoderbat.s=mencoderbat.s+"--psy-rd ["+StringField(GetGadgetText(#pysstrenght),1,":")+":"+StringField(GetGadgetText(#pysstrenght),2,":")+"] " ; supported by ffmpeg
If GetGadgetState(#bframes)>1 And GetGadgetState(#weightb)=1 : mencoderbat.s=mencoderbat.s+"-flags2 +wpred " : EndIf
If GetGadgetText(#merange)<>"16" : mencoderbat.s=mencoderbat.s+"-me_range "+GetGadgetText(#merange )+" " : EndIf
If GetGadgetState(#trellis)>0 : mencoderbat.s=mencoderbat.s+"-trellis "+Str(GetGadgetState(#trellis))+" " : EndIf
;If GetGadgetState(#nochromame)=1 : mencoderbat.s=mencoderbat.s+"--nochroma-me " : EndIf ; supported by ffmpeg
If GetGadgetState(#mixedrefs)=1 : mencoderbat.s=mencoderbat.s+"-flags2 +mixed_refs " : EndIf
;If GetGadgetState(#nodctdecimate)=1 : mencoderbat.s=mencoderbat.s+"--no-dct-decimate " : EndIf ; supported by ffmpeg
If GetGadgetState(#nofastpskip)=1 : mencoderbat.s=mencoderbat.s+"-flags2 -fastpskip " : EndIf
If GetGadgetState(#bpyramid)=1 : mencoderbat.s=mencoderbat.s+"-flags2 +bpyramid " : EndIf
If GetGadgetText(#keyint)<>"250" : mencoderbat.s=mencoderbat.s+"-g "+GetGadgetText(#keyint)+" " : EndIf
If GetGadgetText(#keyintmin)<>"126" : mencoderbat.s=mencoderbat.s+"-keyint_min "+GetGadgetText(#keyintmin)+" " : EndIf
;If GetGadgetText(#level)<>"" : mencoderbat.s=mencoderbat.s+"-level "+GetGadgetText(#level)+" " : EndIf ; use autosignaling always
If GetGadgetText(#vbvmaxrate)<>"" : mencoderbat.s=mencoderbat.s+"-maxrate "+GetGadgetText(#vbvmaxrate)+"k " : EndIf
If GetGadgetText(#vbvbufsize)<>"" : mencoderbat.s=mencoderbat.s+"-bufsize "+GetGadgetText(#vbvbufsize)+"k " : EndIf
If GetGadgetText(#vbvinit)<>"" And GetGadgetText(#vbvinit)<>"0.9" : mencoderbat.s=mencoderbat.s+"-rc_init_occupancy "+GetGadgetText(#vbvinit)+" " : EndIf
If GetGadgetText(#qcomp)<>"0.6" And GetGadgetText(#qcomp)<>"": mencoderbat.s=mencoderbat.s+"-qcomp "+GetGadgetText(#qcomp)+" " : EndIf
If GetGadgetText(#qpmin)<>"10" : mencoderbat.s=mencoderbat.s+"-qpmin "+GetGadgetText(#qpmin)+" " : EndIf
If GetGadgetText(#qpmax)<>"51" : mencoderbat.s=mencoderbat.s+"-qpmax "+GetGadgetText(#qpmax)+" " : EndIf
If passx<>4 And GetGadgetText(#ratetol)<>"1.0" : mencoderbat.s=mencoderbat.s+"-bt "+GetGadgetText(#ratetol)+" " : EndIf
If GetGadgetText(#scenecut)<>"40" : mencoderbat.s=mencoderbat.s+"-sc_threshold "+GetGadgetText(#scenecut)+" " : EndIf
If passx=3 And GetGadgetText(#cplxblur)<>"20" : mencoderbat.s=mencoderbat.s+"-complexityblur "+GetGadgetText(#cplxblur)+" " : EndIf
If passx=3 And GetGadgetText(#qblur)<>"0" : mencoderbat.s=mencoderbat.s+"-qblur "+GetGadgetText(#qblur)+" " : EndIf
EndIf
If GetGadgetState(#copyvideo)=1
mencoderbat.s="ffmpeg "
mencoderbat.s=mencoderbat.s+"-i "+Chr(34)+inputfile.s+Chr(34)+" -an -vcodec copy "
EndIf
If outputfile.s="" : outputfile.s=Chr(34)+here.s+"autox264_"+GetFilePart(inputfile.s)+"."+GetGadgetText(#muxer)+Chr(34) : EndIf
mencoderbat.s=mencoderbat.s+" -y autox264.h264"
If GetGadgetState(#novideo)=1 : mencoderbat.s="" : EndIf
If GetGadgetText(#audioenc)<>"No Audio" And passx.l<>2
Debug("CountGadgetItems(#audiopid)="+Str(CountGadgetItems(#audiopid)))
For aa=1 To CountGadgetItems(#audiopid)
If GetGadgetItemState(#audiopid,aa)& #PB_ListIcon_Checked
Debug("audiopid(aa)="+Str(aa))
Debug("1-"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"="))
mencoderbat.s=mencoderbat.s+Chr(10)+mencoder.s+" -i "+Chr(34)+inputfile.s+Chr(34)+" -vn -map ["+Str(GetGadgetItemState(#audiopid,aa)-1)+":0] "
aid.s=StringField(StringField(GetGadgetItemText(#audiopid,aa,0),2,","),2," ")
If GetGadgetText(#audioenc)="AAC Audio" : mencoderbat.s=mencoderbat.s+"-acodec libfaac -ab "+GetGadgetText(#abitrate)+"k -ac "+GetGadgetText(#channels)+" " : EndIf
If GetGadgetText(#audioenc)="MP3 Audio" : mencoderbat.s=mencoderbat.s+"-acodec libmp3lame -ab "+GetGadgetText(#abitrate)+"k -ac 2 " : EndIf
If GetGadgetText(#audioenc)="Copy Audio" : mencoderbat.s=mencoderbat.s+"-acodec copy " : EndIf
If GetGadgetState(#normalize)=1 : mencoderbat.s=mencoderbat.s+"-vol 256 " : EndIf
If GetGadgetText(#samplerate)<>"AUTO" : mencoderbat.s=mencoderbat.s+"-ar "+GetGadgetText(#samplerate)+" " : EndIf
If GetGadgetText(#audioenc)="AAC Audio" : mencoderbat.s=mencoderbat.s+"-y audiox264-pid"+aid.s+".aac" : EndIf
If GetGadgetText(#audioenc)="MP3 Audio" : mencoderbat.s=mencoderbat.s+"-y audiox264-pid"+aid.s+".mp3" : EndIf
If GetGadgetText(#audioenc)="Copy Audio" : mencoderbat.s=mencoderbat.s+"-y audiox264-pid"+aid.s+".ac3" : EndIf
EndIf
Next aa
EndIf
handlesubs()
mencoderbat.s=mencoderbat.s+eac3toaudio.s
audiofile.s=""
For aa=0 To CountGadgetItems(#audiopid)
If GetGadgetText(#audioenc)="AAC Audio" : extaudio.s="aac" : EndIf
If GetGadgetText(#audioenc)="MP3 Audio" : extaudio.s="mp3" : EndIf
If GetGadgetText(#audioenc)="Copy Audio" : extaudio.s="ac3" : EndIf
If GetGadgetState(#neroq)=1 : extaudio.s="mp4" : EndIf
If GetGadgetState(#flac)=1 : extaudio.s="flac" : EndIf
If GetGadgetItemState(#audiopid,aa)& #PB_ListIcon_Checked
Debug("1-"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"="))
If GetGadgetText(#muxer)="mkv"
audiofile.s=audiofile.s+" "+Chr(34)+here.s+"audiox264-pid"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"=")+"."+extaudio.s+Chr(34)+" "
EndIf
If GetGadgetText(#muxer)="mp4"
audiofile.s=audiofile.s+" -add "+Chr(34)+here.s+"audiox264-pid"+StringField(GetGadgetItemText(#audiopid,aa,0),2,"=")+"."+extaudio.s+Chr(34)+" "
EndIf
EndIf
Next aa
If passx.l<>2
mux()
EndIf
If GetGadgetState(#deletetempfile)=1
mencoderbat.s=mencoderbat.s+Chr(10)+"rm "+GetCurrentDirectory()+"autox264.mp3"
mencoderbat.s=mencoderbat.s+Chr(10)+"rm "+GetCurrentDirectory()+"autox264.h264"
mencoderbat.s=mencoderbat.s+Chr(10)+"rm "+GetCurrentDirectory()+"autox264.aac"
EndIf
If queue.l=1
AddGadgetItem(#queue,-1,mencoderbat.s)
ProcedureReturn
EndIf
If passx.l<>3
CreateFile(777,GetCurrentDirectory()+"autox264.bat")
EndIf
If passx.l=3
OpenFile(777,GetCurrentDirectory()+"autox264.bat")
FileSeek(777, Lof(777) )
EndIf
WriteStringN(777,mencoderbat.s)
CloseFile(777)
If passx.l<>2
RunProgram("chmod"," 777 autox264.bat",GetCurrentDirectory())
RunProgram("xterm","-e ./autox264.bat",GetCurrentDirectory())
EndIf
queue.l=0
EndProcedure
Procedure removequeuejob()
RemoveGadgetItem(#queue,GetGadgetState(#queue))
EndProcedure
Procedure startqueue()
CreateFile(666,GetCurrentDirectory()+"queue.bat")
WriteStringN(666,"")
WriteStringN(666,GetGadgetText(#queue))
CloseFile(666)
RunProgram("chmod"," 777 "+GetCurrentDirectory()+"queue.bat",GetCurrentDirectory())
RunProgram("xterm","-e ./queue.bat",GetCurrentDirectory())
EndProcedure
Procedure savesetting()
CreatePreferences(here.s+"autox264.ini")
PreferenceComment("AutoX264 default parameters")
PreferenceGroup("AutoX264")
WritePreferenceString("AutoX264 version ",ver.s)
WritePreferenceString("Path to Mencoder",GetGadgetText(#mencoderpath))
WritePreferenceString("Path to Mplayer",GetGadgetText(#mplayerpath))
WritePreferenceString("Path to Mp4box",GetGadgetText(#mp4creatorpath))
WritePreferenceString("Path to Mkvmerge",GetGadgetText(#mkvcreatorpath))
WritePreferenceString("Path to FFmpeg",GetGadgetText(#ffmpegpath))
If GetGadgetState(#deletetempfile)=1
WritePreferenceString("Delete temporary files","yes")
EndIf
If GetGadgetState(#deletetempfile)=0
WritePreferenceString("Delete temporary files","no")
EndIf
WritePreferenceString("Muxer",GetGadgetText(#muxer))
WritePreferenceString("Resizer",GetGadgetText(#resizer))
WritePreferenceString("Denoise",GetGadgetText(#denoise))
If GetGadgetState(#itu)=1
WritePreferenceString("Follow ITU","yes")
Else
WritePreferenceString("Follow ITU","no")
EndIf
ClosePreferences()
MessageRequester("AutoX264","Path saved")
EndProcedure
Procedure loaddefault()
DisableGadget(#savepath,0)
OpenPreferences(here.s+"autox264.ini")
PreferenceGroup("AutoX264")
SetGadgetText(#mencoderpath,ReadPreferenceString("Path to Mencoder", GetCurrentDirectory()))
SetGadgetText(#mplayerpath,ReadPreferenceString("Path to Mplayer", GetCurrentDirectory()))
SetGadgetText(#mp4creatorpath,ReadPreferenceString("Path to Mp4box", GetCurrentDirectory()))
SetGadgetText(#mkvcreatorpath,ReadPreferenceString("Path to Mkvmerge", GetCurrentDirectory()))
SetGadgetText(#ffmpegpath,ReadPreferenceString("Path to FFmpeg", GetCurrentDirectory()))
SetGadgetText(#resizer,ReadPreferenceString("Resizer", "2 bicubic"))
SetGadgetText(#denoise,ReadPreferenceString("Denoise", "Light"))
SetGadgetText(#manualbitrate,ReadPreferenceString("Manual Bitrate", ""))
SetGadgetText(#mdeint,ReadPreferenceString("Deinterlace", "none"))
If ReadPreferenceString("Follow ITU", "yes") : SetGadgetState(#itu,1) : EndIf
If ReadPreferenceString("Follow ITU", "no") : SetGadgetState(#itu,0) : EndIf
If GetGadgetText(#mp4creatorpath)<>"" : AddGadgetItem(#muxer,-1,"mp4") : SetGadgetState(#muxer,0) : EndIf
If GetGadgetText(#mkvcreatorpath)<>"" : AddGadgetItem(#muxer,-1,"mkv") : EndIf
If ReadPreferenceString("Delete temporary files","yes") = "yes" : SetGadgetState(#deletetempfile, 1) : EndIf
If ReadPreferenceString("Delete temporary files","yes") = "no" : SetGadgetState(#deletetempfile, 0) : EndIf
SetGadgetText(#muxer, ReadPreferenceString("Muxer","mp4"))
ClosePreferences()
If OSVersion()=1200 : mpl.s="mplayer" : EndIf
If OSVersion()<>1200 : mpl.s=GetGadgetText(#mplayerpath) : EndIf
If GetGadgetText(#mplayerpath)="" Or GetGadgetText(#mencoderpath)="" Or GetGadgetText(#mp4creatorpath)=""
MessageRequester("AutoX264","Missing some components"+Chr(13)+"Please check Program Path panel")
EndIf
EndProcedure
Procedure checkpath()
If FileSize("/usr/bin/mencoder")<>-1 Or FileSize("/usr/local/bin/mencoder")<>-1
SetGadgetText(#mencoderpath,"mencoder")
EndIf
If FileSize("/usr/bin/mplayer")<>-1 Or FileSize("/usr/local/bin/mplayer")<>-1
SetGadgetText(#mplayerpath,"mplayer")
EndIf
If FileSize("/usr/bin/MP4Box")<>-1 Or FileSize("/usr/local/bin/MP4Box")<>-1
SetGadgetText(#mp4creatorpath,"MP4Box")
AddGadgetItem(#muxer,-1,"mp4")
EndIf
If FileSize("/usr/bin/mkvmerge")<>-1 Or FileSize("/usr/local/bin/mkvmerge")<>-1
SetGadgetText(#mkvcreatorpath,"mkvmerge")
AddGadgetItem(#muxer,-1,"mkv")
EndIf
If FileSize("/usr/bin/tsmuxer")<>-1 Or FileSize("/usr/local/bin/tsmuxer")<>-1
SetGadgetText(#mkvcreatorpath,"tsmuxer")
AddGadgetItem(#muxer,-1,"m2ts")
EndIf
If FileSize("/usr/bin/ffmpeg")<>-1 Or FileSize("/usr/local/bin/ffmpeg")<>-1
SetGadgetText(#ffmpegpath,"ffmpeg")
AddGadgetItem(#decoding,-1,"Use FFmpeg")
EndIf
If FileSize("/usr/bin/HandBrakeCLI")<>-1 Or FileSize("/usr/local/bin/HandBrakeCLI")<>-1
AddGadgetItem(#decoding,-1,"Use HandBrakeCLI")
EndIf
If GetGadgetText(#mplayerpath)="" Or GetGadgetText(#mencoderpath)="" Or GetGadgetText(#mp4creatorpath)=""
MessageRequester("AutoX264","Missing some components"+Chr(13)+"Please check Program Path panel")
EndIf
mpl.s="mplayer"
If GetGadgetText(#mencoderpath)<>""
wait=RunProgram(GetGadgetText(#mencoderpath),"","",#PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
While ProgramRunning(wait)
line.s=ReadProgramString(wait)
If FindString(line.s,"MEncoder ",0)
SetWindowTitle(#Window_0,"AutoX264 "+ver.s+" with "+StringField(line.s,1,"("))
EndIf
Wend
WaitProgram(wait)
EndIf
If FileSize(here.s+"applications\mkvmerge.exe")<>-1
wait.l=RunProgram(here.s+"applications\mkvmerge.exe"," --version","",#PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
If wait.l
While ProgramRunning(wait.l)
line.s=ReadProgramString(wait)
If FindString(line.s,"mkvmerge",0)
AddGadgetItem(#muxer,-1,"mkv")
EndIf
Wend
WaitProgram(wait)
EndIf
EndIf
SetGadgetState(#muxer,0)
EndProcedure
Procedure title()
If GetGadgetText(#decoding)="Use MEncoder"
DisableGadget(#copyvideo,0)
line.s=""
If GetGadgetText(#mencoderpath)<>""
wait=RunProgram(GetGadgetText(#mencoderpath),"","",#PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
While ProgramRunning(wait)
line.s=ReadProgramString(wait)
If FindString(line.s,"MEncoder ",0)
SetWindowTitle(#Window_0,"AutoX264 "+ver.s+" - "+StringField(line.s,1,"("))
EndIf
Wend
WaitProgram(wait)
EndIf
EndIf
If GetGadgetText(#decoding)="Use HandBrakeCLI"
If OSVersion()=1200
SetWindowTitle(#Window_0,"AutoX264 "+ver.s+" with HandBrakeCLI")
EndIf
DisableGadget(#copyvideo,0)
EndIf
If GetGadgetText(#decoding)="Use FFmpeg"
DisableGadget(#copyvideo,0)
line.s=""
If GetGadgetText(#ffmpegpath)<>""
wait=RunProgram(GetGadgetText(#ffmpegpath)," -version","",#PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
If wait
While ProgramRunning(wait)
line.s=ReadProgramString(wait)
If FindString(line.s,"FFmpeg",0)
SetWindowTitle(#Window_0,"AutoX264 "+ver.s+" - "+line.s)
EndIf
Wend
WaitProgram(wait)
EndIf
EndIf
EndIf
EndProcedure
Open_Window_0()
here.s=GetPathPart(ProgramFilename())
If FileSize(here.s+"autox264.ini")=-1 : checkpath() : EndIf
If FileSize(here.s+"autox264.ini")<>-1 : loaddefault() : EndIf
loadpreset()
If ExamineDirectory(0,here.s,"autox264-pid*")
Repeat
type=NextDirectoryEntry(0)
If type=1
file.s=DirectoryEntryName(0)
DeleteFile(here.s+file.s)
EndIf
Until type=0
FinishDirectory(0)
EndIf
If ExamineDirectory(0,here.s+"filters\","*.avs")
Repeat
type=NextDirectoryEntry(0)
If type=1
file.s=DirectoryEntryName(0)
If GetExtensionPart(file.s)="avs" : AddGadgetItem(#qmf,-1,file.s) : EndIf
EndIf
Until type=0
FinishDirectory(0)
EndIf
analyzewith()
Repeat ; Start of the event loop
Event = WaitWindowEvent() ; This line waits until an event is received from Windows
WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadget() ; Is it a gadget event?
EventType = EventType() ; The event type
;You can place code here, and use the result as parameters for the procedures
If Event = #PB_Event_Gadget
If GadgetID = #buttonopenfile
outputfile.s=""
inputfile.s=OpenFileRequester("Open File to Encode", GetCurrentDirectory(), "*.vob,*.mpeg,*.mpg,*.ts,*.tp,*.avi,*.m1v,*.m2v,*.dvr-ms,*.mkv,*.mp4,*.vro,*.mov,*.m2ts,*.mpv,*.m2t,*.mts|*.vob;*.mpeg;*.mpg;*.ts;*.tp*avi;*.m1v;*.m2v*.dvr-ms;*.mkv;*.mp4;*.vro;*.mov;*.m2ts;*.mpv;*.m2t;*.mts|*.*|*.*",0)
If inputfile.s<>""
SetGadgetText(#inputfilepath,inputfile.s)
Select GetExtensionPart(inputfile.s)
Case "m2ts","mts","ts"
SetGadgetState(#lavf,1)
EndSelect
StatusBarText(#statusbar, 0, "Input file selected. Don't forget to analyze it")
EndIf
ElseIf GadgetID = #analizer
If inputfile.s<>""
infomedia()
If GetGadgetText(#analyzewith)="mediainfo" : StatusBarText(#statusbar, 0, "File analyzed. Medianfo don't detect crop. So hit Detect Crop button") : EndIf
EndIf
decoder()
ElseIf GadgetID = #inputfilepath
ElseIf GadgetID = #flac
StatusBarText(#statusbar, 0, "WARNING! FLAC audio con be muxed only in MKV container")
ElseIf GadgetID = #aspectratio
ardar()
ElseIf GadgetID = #inputfilepath
ElseIf GadgetID = #enceac3to
If GetGadgetState(#enceac3to)=1 And FileSize(here.s+"applications\eac3to.exe")<>-1
DisableGadget(#eac3tocodec,0)
EndIf
ElseIf GadgetID = #showinfo
showinfo()
StatusBarText(#statusbar, 0, "Information about input")
ElseIf GadgetID = #decoding
title()
StatusBarText(#statusbar, 0, "Selecting a decoder/encoder...")
ElseIf GadgetID = #preset
applypreset()
StatusBarText(#statusbar, 0, "Please check Final MB/CRF")
ElseIf GadgetID = #start
preindex.s=""
StatusBarText(#statusbar, 0, "Starting encoding!!!")
If GetGadgetText(#decoding)="Use MEncoder"
queue.l=0
preindex.s=""
If GetGadgetState(#pass1)=1 : passx.l=1 : start() : EndIf
If GetGadgetState(#copyvideo)=1 : passx.l=1 : start() : EndIf
If GetGadgetState(#novideo)=1 : passx.l=1 : start() : EndIf
If GetGadgetState(#pass2)=1
passx.l=2 : start()
passx.l=3 : start()
EndIf
If GetGadgetState(#passcrf)=1 : passx=4 : start() : EndIf
EndIf
If GetGadgetText(#decoding)="Use HandBrakeCLI"
queue.l=0
preindex.s=""
If GetGadgetState(#pass1)=1 : passx.l=1 : starthand() : EndIf
If GetGadgetState(#copyvideo)=1 : passx.l=1 : starthand() : EndIf
If GetGadgetState(#novideo)=1 : passx.l=1 : starthand() : EndIf
If GetGadgetState(#pass2)=1
passx.l=3 : starthand()
EndIf
If GetGadgetState(#passcrf)=1 : passx=4 : starthand() : EndIf
EndIf
If GetGadgetText(#decoding)="Use FFmpeg"
queue.l=0
preindex.s=""
If GetGadgetState(#pass1)=1 : passx.l=1 : ffmpeg() : EndIf
If GetGadgetState(#copyvideo)=1 : passx.l=1 : ffmpeg() : EndIf
If GetGadgetState(#novideo)=1 : passx.l=1 : ffmpeg() : EndIf
If GetGadgetState(#pass2)=1
passx.l=2 : ffmpeg()
passx.l=3 : ffmpeg()
EndIf
If GetGadgetState(#passcrf)=1 : passx=4 : ffmpeg() : EndIf
EndIf
ElseIf GadgetID = #saveprofile
saveprofile()
ElseIf GadgetID = #risoluzione
ElseIf GadgetID = #savepath
If GetGadgetText(#mencoderpath)<>"" And GetGadgetText(#mplayerpath)<>"" And GetGadgetText(#mp4creatorpath)<>""
DisableGadget(#savepath,0)
StatusBarText(#statusbar, 0, "Changed save location")
EndIf
savesetting()
ElseIf GadgetID = #mencoderbutton
mencoderpath.s=OpenFileRequester("Select the mencoder to use",GetCurrentDirectory(),"*.*|*.*",0)
If mencoderpath.s : SetGadgetText(#mencoderpath,mencoderpath.s) : EndIf
ElseIf GadgetID = #mplayerpathbutton
mplayer.s=OpenFileRequester("Select the mplayer to use",GetCurrentDirectory(),"*.*|*.*",0)
If mplayer.s : SetGadgetText(#mplayerpath,mplayer.s) : EndIf
ElseIf GadgetID = #ffmpegpathbutton
ffmpeg.s=OpenFileRequester("Select the ffmpeg to use",GetCurrentDirectory(),"*.*|*.*",0)
If ffmpeg.s : SetGadgetText(#ffmpegpath,ffmpeg.s) : EndIf
ElseIf GadgetID = #mp4creatorpathbutton
mp4box.s=OpenFileRequester("Select the mp4creator to use",GetCurrentDirectory(),"*.*|*.*",0)
If mp4box.s : SetGadgetText(#mp4creatorpath,mp4box.s) : EndIf
ElseIf GadgetID = #mkvcreatorpathbutton
mkvmerge.s=OpenFileRequester("Select the mkvmerge to use",GetCurrentDirectory(),"*.*|*.*",0)
If mkvmerge.s : SetGadgetText(#mkvcreatorpath,mkvmerge.s) : EndIf
ElseIf GadgetID = #paypal
MessageRequester("Thanks For Your Donation!", "Thanks ! Without your support AutoX264 will be never a better application!", #PB_MessageRequester_Ok )
RunProgram("xdg-open"," https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2094554","")
ElseIf GadgetID = #browsesubs
mess.s=OpenFileRequester("Select the subtitle file to use",GetCurrentDirectory(),"*.srt;*.ssa;*.ass;*.idx/sub|*.srt;*.ssa;*.ass;*.idx|*.*|*.*",0)
If mess.s : SetGadgetText(#subtitlepath,mess.s) : EndIf
ElseIf GadgetID = #topcrop
silentresize()
ElseIf GadgetID = #detectcrop
StatusBarText(#statusbar, 0, "Activating crop detection... please wait")
autocrop2()
ElseIf GadgetID = #leftcrop
silentresize()
ElseIf GadgetID = #rightcrop
silentresize()
ElseIf GadgetID = #bottomcrop
silentresize()
ElseIf GadgetID = #preview
preview()
ElseIf GadgetID = #TrackBarres
StatusBarText(#statusbar, 0, "Changing resolution...")
silentresize()
ardar()
ElseIf GadgetID = #width
silentscale()
ardar()
ElseIf GadgetID = #height
ardar()
ElseIf GadgetID = #outputfile
mess.s=GetCurrentDirectory()
If inputfile.s<>"" : mess.s=GetPathPart(inputfile.s) : EndIf
outputfile.s=SaveFileRequester("Save your mp4 file",mess.s,"*.mp4;*.mkv;*.m2ts|*.mp4;*.mkv;*.m2ts",0)
If GetExtensionPart(outputfile.s)="" : outputfile.s=outputfile.s+".mp4" : EndIf
If GetExtensionPart(outputfile.s)="mp4" : SetGadgetText(#muxer,"mp4") : EndIf
If GetExtensionPart(outputfile.s)="mkv" : SetGadgetText(#muxer,"mkv") : EndIf
If GetExtensionPart(outputfile.s)="m2ts" : SetGadgetText(#muxer,"m2ts") : EndIf
SetGadgetText(#outputfilepath,outputfile.s)
ElseIf GadgetID = #outputfilepath
ElseIf GadgetID = #addtoqueue
StatusBarText(#statusbar, 0, "Added job to queue")
If GetGadgetText(#decoding)="Use MEncoder"
queue.l=1
preindex.s=""
If GetGadgetState(#pass1)=1 : passx.l=1 : start() : EndIf
If GetGadgetState(#copyvideo)=1 : passx.l=1 : start() : EndIf
If GetGadgetState(#novideo)=1 : passx.l=1 : start() : EndIf
If GetGadgetState(#pass2)=1
passx.l=2 : start()
passx.l=3 : start()
EndIf
If GetGadgetState(#passcrf)=1 : passx=4 : start() : EndIf
EndIf
If GetGadgetText(#decoding)="Use HandBrakeCLI"
queue.l=1
preindex.s=""
If GetGadgetState(#pass1)=1 : passx.l=1 : starthand() : EndIf
If GetGadgetState(#copyvideo)=1 : passx.l=1 : starthand() : EndIf
If GetGadgetState(#novideo)=1 : passx.l=1 : starthand() : EndIf
If GetGadgetState(#pass2)=1
passx.l=3 : starthand()
EndIf
If GetGadgetState(#passcrf)=1 : passx=4 : starthand() : EndIf
EndIf
If GetGadgetText(#decoding)="Use FFmpeg"
queue.l=1
preindex.s=""
If GetGadgetState(#pass1)=1 : passx.l=1 : ffmpeg() : EndIf
If GetGadgetState(#copyvideo)=1 : passx.l=1 : ffmpeg() : EndIf
If GetGadgetState(#novideo)=1 : passx.l=1 : ffmpeg() : EndIf
If GetGadgetState(#pass2)=1
passx.l=2 : ffmpeg()
passx.l=3 : ffmpeg()
EndIf
If GetGadgetState(#passcrf)=1 : passx=4 : ffmpeg() : EndIf
EndIf
ElseIf GadgetID = #removequeuejob
StatusBarText(#statusbar, 0, "Removed job from queue")
removequeuejob()
ElseIf GadgetID = #startqueue
StatusBarText(#statusbar, 0, "Queue started! Please wait")
startqueue()
EndIf
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
;
; IDE Options = PureBasic 4.30 (Linux - x86)
; CursorPosition = 1057
; FirstLine = 1045
; Folding = ------
; EnableXP
; EnableUser
; Executable = autox264
; DisableDebugger
; CompileSourceDirectory
; Debugger = IDE
; EnableCompileCount = 1983
; EnableBuildCount = 186
; EnableExeConstant
; IncludeVersionInfo
; VersionField0 = 0.19.%BUILDCOUNT.%COMPILECOUNT
; VersionField1 = 0.19.0.0
; VersionField2 = BHH
; VersionField3 = AutoX264
; VersionField4 = 0.19
; VersionField5 = 0.19.%BUILDCOUNT.%COMPILECOUNT
; VersionField6 = Easy GUI for X264
; VersionField7 = autox264
; VersionField8 = autox264
; VersionField9 = Copyright owned by Andres Zanzani
; VersionField13 = azanzani@gmail.com
; IncludeVersionInfoeExeConstant