Created
April 26, 2023 14:23
-
-
Save kenmickles/1bb9b438022753e0b3b17f9e37928c37 to your computer and use it in GitHub Desktop.
Extract the first frame from an mp4 with ffmpeg (ChatGPT wrote this for me)
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 | |
# Check if an input file is provided | |
if [[ -z "$1" ]]; then | |
echo "Usage: extract-first-frame.sh input.mp4 [output.jpg] [frame_number]" | |
exit 1 | |
fi | |
# Set the input file name | |
input_file="$1" | |
# Set the output file name | |
if [[ -z "$2" ]]; then | |
output_file="output.jpg" | |
else | |
output_file="$2" | |
fi | |
# Set the frame number | |
if [[ -z "$3" ]]; then | |
frame_number=1 | |
else | |
frame_number="$3" | |
fi | |
# Run the ffmpeg command | |
ffmpeg -i "$input_file" -vf "select=eq(n\,$frame_number)" -vframes 1 -q:v 2 "$output_file" | |
# Print a success message | |
echo "Frame number $frame_number of $input_file has been extracted as $output_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment