Created
October 28, 2024 22:34
-
-
Save digiguru/1e664dedd53846926a6c14020f215b6e to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Usage: ./extract_frame.sh [path_to_video] [frame_time] | |
# - path_to_video: The path to the video file. | |
# - frame_time: The specific time in the video to capture a frame, in seconds (e.g., "00:01:23" or "90" for 90 seconds). | |
# Default is the last frame. | |
# Check for required tools: ffmpeg and pngpaste | |
if ! command -v ffmpeg &> /dev/null; then | |
echo "ffmpeg is required but not installed. Install it with 'brew install ffmpeg'." | |
exit 1 | |
fi | |
if ! command -v pngpaste &> /dev/null; then | |
echo "pngpaste is required but not installed. Install it with 'brew install pngpaste'." | |
exit 1 | |
fi | |
# Input arguments | |
VIDEO_PATH=${1:-"sample.mp4"} # Default to "sample.mp4" if not provided | |
FRAME_TIME=${2:-""} # If not provided, defaults to last frame | |
# Generate output filename | |
OUTPUT_FILE="extracted_frame.png" | |
# Extract frame | |
if [ -z "$FRAME_TIME" ]; then | |
# Get duration if frame time not provided | |
FRAME_TIME=$(ffmpeg -i "$VIDEO_PATH" 2>&1 | grep "Duration" | awk '{print $2}' | tr -d ,) | |
fi | |
ffmpeg -i "$VIDEO_PATH" -vf "select=gte(t\,$FRAME_TIME)" -vframes 1 "$OUTPUT_FILE" -y | |
# Copy to clipboard | |
pngpaste "$OUTPUT_FILE" | |
echo "Frame extracted and copied to clipboard: $OUTPUT_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment