Last active
January 13, 2025 05:03
-
-
Save loshlee/367bd1964efd16e16e46bbffebce8c9a to your computer and use it in GitHub Desktop.
AppleScript Droplet source to create a video excerpt from a dropped video file
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
property tmpfile : "/tmp/execme.command" | |
on open the_items | |
my build_archive(the_items) | |
end open | |
on build_archive(the_items) | |
set the_item to item 1 of the_items as alias | |
set _start to (text returned of (display dialog "Start time of preserved segment:" default answer "00:00:00")) | |
set _end to (text returned of (display dialog "End time of preserved segment:" default answer "00:00:00")) | |
set seg_Number to (text returned of (display dialog "Enter segment number (for naming):" default answer "1")) | |
set theshellscript to "s=$(date -j -f '%H:%M:%S'" & space & _start & space & "'+%s') | |
e=$(date -j -f '%H:%M:%S' " & space & _end & space & " '+%s') | |
i=`expr $e - $s` | |
date -u -r $i +%T" | |
set theResult to (do shell script theshellscript) | |
set stampDiff to theResult & ".00" | |
try | |
tell application "Finder" | |
set sost to (container of the_item) as string | |
end tell | |
set pos_filepath to POSIX path of sost | |
end try | |
set this_filepath to (the_item as string) | |
set thesourcename to (name of (info for the_item)) | |
set namepart to (name extension of (info for the_item)) | |
set finalname to replace_chars(thesourcename, ("." & namepart), ("-" & seg_Number & "." & namepart)) | |
set theshellscript to "ffmpeg -i" & space & (quoted form of (POSIX path of this_filepath)) & space & "-ss" & space & _start & space & "-t" & space & stampDiff & space & "-async 1 -codec copy -map 0 -movflags +faststart" & space & (quoted form of (pos_filepath & finalname)) | |
set theshellscript to the theshellscript & ";sleep 3" & return | |
set theshellscript to theshellscript & ";/bin/echo ' | |
========================== | |
" & finalname & "_" & seg_Number & namepart & space & "FINISHED!" & " | |
========================== | |
';mv" & space & (quoted form of tmpfile) & space & (quoted form of (POSIX path of (path to trash))) | |
do shell script "echo " & quoted form of theshellscript & " > " & tmpfile | |
repeat | |
try | |
do shell script "open -a BBEdit.app" & space & tmpfile | |
do shell script "chmod +x " & tmpfile | |
do shell script "open -a Terminal.app" & space & tmpfile | |
exit repeat | |
on error | |
delay 1 | |
end try | |
end repeat | |
end build_archive | |
on replace_chars(this_text, _bad, _good) | |
set AppleScript's text item delimiters to the _bad | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the _good as string | |
set this_text to the item_list as string | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replace_chars | |
on run | |
try | |
build_archive(the_items) | |
on error | |
set the_items to ((choose file) as list) | |
build_archive(the_items) | |
end try | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run the AppleScript or drop a video file onto the icon of an app you create from it using Script Editor on a Mac to make a new file with the start and end points you specify. You need a working installation of ffmpeg, and you also need BBEdit to show you the shell script that you just ran to create the video clip. You can delete the BBEdit line from the script if you don't have it.