Skip to content

Instantly share code, notes, and snippets.

@thomaswitt
Created October 31, 2024 16:36
Show Gist options
  • Save thomaswitt/1e22723a2da062129c76fc8b52db1cb3 to your computer and use it in GitHub Desktop.
Save thomaswitt/1e22723a2da062129c76fc8b52db1cb3 to your computer and use it in GitHub Desktop.
A script to capture frames from a QuickTime video
#!/bin/zsh
# Check if the video filename is provided as an argument
if [ $# -eq 0 ]; then
echo "Please provide the video filename as an argument."
exit 1
fi
video_filename=$1
# Function to convert time in seconds to HH:MM:SS format
function seconds_to_hms {
local total_seconds=$1
local hours=$((total_seconds / 3600))
local minutes=$(((total_seconds % 3600) / 60))
local seconds=$((total_seconds % 60))
printf "%02d:%02d:%02d\n" $hours $minutes $seconds
}
# Function to capture frame
function capture_frame {
local current_time=$1
local formatted_time=$(seconds_to_hms $current_time)
local filename="/tmp/frame_${formatted_time//:/}.jpg"
# Run ffmpeg to capture the frame
ffmpeg -ss $formatted_time -i "$video_filename" -frames:v 1 $filename
echo "Saved frame to $filename"
}
# Main loop
while true; do
echo "Press any key to capture the current video frame..."
read -sk 1 key
# Use osascript to get the current time from QuickTime Player
current_time=$(osascript -e 'tell application "QuickTime Player" to tell document 1 to get current time')
# Capture the frame at the current time
capture_frame $current_time
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment