To correctly detect the scene changes (almost correctly some changes were still not detected) I used Davinci Resolve. Then I had to type the wanted scene's start frame and end frame into a program that automatically cut it.
From Davinci Resolve it was extremely hard to copy the frame numbers as they could not be selected. I am sure there is a better way of getting the start frames and end frames from Davinci Resolve but I couldn't find it.
The cutting can be done using ffmpeg
:
ffmpeg -i example.mp4 -vf trim=start_frame=10:end_frame=50 -an -fflags +genpts output.mp4
But it takes really long to get a clip from the end of a long movie for example.
It can also be done using applescript and that is much faster:
tell application "QuickTime Player"
activate
set startFrame to 84361
set endFrame to 84452
set fps to 23.976
set startTime to startFrame / fps
set endTime to endFrame / fps
set inFile to "Users:me:Documents:folder:infile.mov"
set outFile to "Users:me:Documents:folder:outfile.mov"
try
set theOpenedFile to open for access file outFile with write permission
set eof of theOpenedFile to 0
end try
open file inFile
trim front document from startTime to endTime
export front document in outFile using settings preset "1080p"
try
close access theOpenedFile
end try
close every document saving no
end tell