Created
May 22, 2015 10:15
-
-
Save atika/2c8a7a77967c1c5ca7d3 to your computer and use it in GitHub Desktop.
Split a QuickTime video in multiple part (set cut mark in seconds)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Split and export a QuickTime Movie | |
# Create a folder "exports" on the desktop | |
# Open one movie file in QuickTime | |
# Configure where you want to cut the video, if you want first and last part and the QuickTime window name (after modification) | |
# Launch this script and wait | |
#------------- BEGIN OF CONFIGURATION -------- | |
-- Middle Mark : Set where you want to cut the video (in seconds) | |
set cuts to {120, 1276, 1970, 3898, 4757, 5677, 6113, 7349, 9198} | |
-- Delay between export (seconds) | |
set delay_between_export to 10 | |
-- Export first part and last part ? (0/1) | |
set export_first_part to 1 | |
set export_last_part to 1 | |
-- QuickTime Preset | |
set export_preset to "720p" | |
-- Window name change after first modification | |
set windowname to "Sans titre" | |
#------------- END OF CONFIGURATION ----------- | |
set start_trim to 0 | |
set end_trim to 0 | |
set isLastPart to 0 | |
set parts_count to ((cuts's length)) | |
# Prompt base filename | |
display dialog "Enter the base name for the export movie file:" default answer "" | |
set the base_name to the text returned of the result | |
if base_name = "" then error "The base filename can't be empty." | |
tell application "QuickTime Player" | |
activate | |
set movie_length to the duration of document 1 | |
#set windowname to name of window 1 | |
end tell | |
repeat with i from 1 to (parts_count + 1) | |
if i is greater than the parts_count then | |
set end_trim to movie_length -- Last part of the movie | |
set isLastPart to 1 | |
else | |
set end_trim to item i of cuts | |
end if | |
repeat 1 times | |
if i = 1 and export_first_part ≠ 1 then exit repeat -- skip first part | |
if isLastPart = 1 and export_last_part ≠ 1 then exit repeat -- skip last part | |
tell application "QuickTime Player" | |
activate | |
if not (exists document 1) then error number -128 | |
log "cut movie from " & start_trim & "s to " & end_trim & "s" | |
-- Trim the movie | |
trim document 1 from start_trim to end_trim | |
-- Export to a folder named "exports" on desktop | |
set the target_file to ((path to desktop folder as string) & "exports:" & base_name & "-" & (i as string) & ".mov") | |
export document 1 in file target_file using settings preset export_preset | |
delay delay_between_export | |
end tell | |
-- Undo QuickTime modifications | |
undo_quicktime_trim(windowname) | |
end repeat | |
if isLastPart = 1 then exit repeat -- stop loop if this is the last part | |
set start_trim to (item i of cuts) -- set start trim to end of last part | |
end repeat | |
on undo_quicktime_trim(windowname) | |
tell application "System Events" to tell process "QuickTime Player" | |
set mywin to window 1 whose name is windowname | |
perform action "AXRaise" of mywin | |
delay 1 | |
set frontmost to true | |
keystroke "z" using {command down} | |
#click menu item 1 of menu 1 of menu bar item "Édition" of menu bar 1 | |
end tell | |
delay 1 | |
end undo_quicktime_trim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment