Last active
November 3, 2017 08:02
-
-
Save jaburns/b423176fb4b6386f6619 to your computer and use it in GitHub Desktop.
Script to screengrab video, convert to webm, upload to server, and get link.
This file contains 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
#!/usr/bin/env bash | |
# | |
# Depends on ffmpeg with libvpx so you'll need to | |
# brew install ffmpeg --with-libvpx | |
# or | |
# brew reinstall ffmpeg --with-libvpx | |
# if you've already got ffmpeg, but it's not linked against libvpx. | |
# | |
vid_name='vidup_tmp' | |
remote='you@yourdomain.tld:/home/you/vidcaps' | |
remote_url='http://vidcaps.yourdomain.tld/' | |
start_recording() { | |
osascript -e ' | |
tell application "QuickTime Player" to activate | |
delay 1 | |
tell application "System Events" | |
activate | |
tell process "QuickTime Player" | |
click menu item "New Screen Recording" of menu "File" of menu bar 1 | |
end tell | |
end tell | |
tell application "QuickTime Player" | |
activate | |
tell application "System Events" to key code 49 | |
end tell | |
' | |
} | |
save_recording() { | |
osascript -e ' | |
set outfile to "'$vid_name'" | |
tell application "QuickTime Player" to activate | |
delay 1 | |
tell application "System Events" | |
tell process "QuickTime Player" | |
click (menu item 1 where its name starts with "iPad") of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1 | |
delay 1 | |
key code 36 # <Enter> on "iPhone or Apple TV etc." screen | |
delay 1.2 | |
keystroke outfile | |
key code 36 # <Enter> on save dialog | |
end tell | |
end tell | |
' | |
} | |
start_recording | |
echo 'Press enter when screen recording is complete' | |
read key | |
save_recording | |
echo 'Press enter when the file has been saved to the desktop' | |
read key | |
osascript -e 'quit application "QuickTime Player" without saving' | |
in_file="$HOME/Desktop/${vid_name}.m4v" | |
out_file_name="$(uuidgen | sed 's/-//g' | tr 'A-F' 'a-f' | cut -c 1-6).webm" | |
out_file="/tmp/$out_file_name" | |
ffmpeg -i "$in_file" -c:v libvpx -b:v 1M -c:a libvorbis "$out_file" | |
scp "$out_file" "$remote" | |
rm "$in_file" "$out_file" | |
printf "${remote_url}${out_file_name}" | pbcopy | |
osascript -e 'display notification "URL copied to clipboard." with title "Video clip uploaded"' | |
echo '' | |
echo 'Done! URL copied to clipboard.' | |
echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment