ffmpeg can do the job without recoding , it is fast and the filesize does not increase .
Potplayer displayed 4k without delays and provide frame select accuracy using hotkeys. The only thing missing is getting the full filepath from an already loaded video file , if anyone has a solution that would be great .
The workaround is getting the file using the Gui and then starting potplayer with it , potplayer must be the default for the video filetype to work.
The way to use it is to select a video file using the button in the Gui , the mark the begin point on the timeline of potplayer and press " Space " it will send the converted time to the gui and moves the focus to the next editcontrol for the end point of the first segment.
If more segments are choosen you can merge them after trimming.
Code: Select all
setworkingdir , %a_scriptdir%
/*
Lossless trimming and merging of video fragments ( must be same encoder and format )
The commandwindow stays open to catch errors if any during processing.
ffmeg.exe must be in the same directory as script
for download : https ffmpeg.org /download.html#build-windows Broken Link for safety
potplayer must be the default app for opening the file
for download : https potplayer.daum.net / Broken Link for safety
hotkeys:
spacebar will set the time from the timeline to the window
thanks to x32 for the sendmessage functions: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=45385
*/
; ***** clear all existing work files **** be aware that it will remove any video filename !
filedelete,mylist.txt
FileDelete, video*
filedelete,output.mp4 ; used when no filename is given when merging
gui , +alwaysontop
Gui, add ,edit , section w100 h20 vs1
Gui, add ,edit , ys xs+120 w100 h20 vs2
Gui, add ,edit , y40 xm section w100 h20 vs3
Gui, add ,edit , ys xs+120 w100 h20 vs4
Gui, add ,edit , y80 xm section w100 h20 vs5
Gui, add ,edit , ys xs+120 w100 h20 vs6
Gui, add ,button , y120 xs+120 w100 h60 ggetfile ,select file
Gui, add ,button , y120 xm w100 h20 gtrim ,trim
Gui, add ,button , y160 xm w100 h20 gmerge ,merge
Gui, show,,trimcut
WinMove, trimcut,,% A_ScreenWidth-500,100
return
getfile:
FileSelectFile, svideo,,e:\
Run, %svideo%
sleep 2000
SendMessage,0x0111,20000,,,ahk_class PotPlayer64
Winactivate,trimcut
WinWaitActive, trimcut
ControlFocus, edit1,trimcut
return
merge:
loop %counter%
data .="file video" A_Index ".mp4" "`n"
FileAppend, %data%,mylist.txt ; create file containing the video fragments to merge
loop 20
{
IfNotExist, mylist.txt
sleep 1000
}
InputBox, ofile,set outputfile with extension mp4,,,300,180
if !regexmatch(ofile,"\.mp4")
{
ofile:=ofile ".mp4"
msgbox added ext to filename %ofile% !
}
if (ofile="")
ofile=output.mp4 ; if no file name is given use this one.....
run , ffmpeg -f concat -safe 0 -i mylist.txt -c copy %ofile%
return
space::
Winactivate,trimcut
WinWaitActive, trimcut
ControlGetFocus, focus_ , trimcut
controlsettext,%focus_%,% 2time(ppctm()),trimcut
sleep 200
send ,{tab}
return
trim:
ifnotexist %svideo%
{
msgbox video file " %svideo% " not found or none selected
exit
}
gui ,submit,nohide
time1:={start:s1,stop:s2}
time2:={start:s3,stop:s4}
time3:={start:s5,stop:s6}
if (s2="")
{
msgbox error no first end time
exit
}
if (s4="")
counter:=1
else if (s6="")
counter:=2
else
counter:=3
goto runtrim
return
runtrim:
Loop, %counter%
{
starttime:=time%A_Index%.start
endtime:=time%A_Index%.stop
ovideo=video%A_Index%.mp4
run %comSpec% /k "ffmpeg.exe -i %svideo% -ss %starttime% -to %endtime% -vcodec copy -acodec copy %ovideo% "
sleep 1000
loop 20 ; waiting for the file to exist
{
IfNotExist, %ovideo%
sleep 1000
}
}
return
ppctm() ; returns timeline position
{
SendMessage, 0x0400, 0x5004,,, ahk_class PotPlayer64
Return, %ErrorLevel%
}
2time(x){ ; convert potlayer time format to ffmpeg format
RegExMatch( x,"U)^(\d+)(\d\d\d$)",m)
time = 19990101
time += %m1%, seconds
FormatTime, mmss, %time%, HH:mm:ss
if m2
return mmss "." m2
else
return mmss
}
guiclose:
ExitApp,