Files
sam2/notebooks/rvm_get_frames.sh
2024-10-19 13:09:37 -07:00

34 lines
1023 B
Bash
Executable File

#!/bin/bash
# Check if the output folder is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <output_folder>"
exit 1
fi
# Set the output folder variable
output_folder="$1"
# Process each segment folder
for segment_dir in "$output_folder"/segment_*; do
if [ -d "$segment_dir" ]; then
# Find the output_N.mp4 file in the segment folder
segment_file=$(find "$segment_dir" -name "output_*.mp4" -print -quit)
if [ -n "$segment_file" ]; then
# Create the frames directory
frames_dir="$segment_dir/frames"
mkdir -p "$frames_dir"
# Extract frames using ffmpeg with CUDA acceleration and save as JPEGs
ffmpeg -hwaccel cuda -i "$segment_file" -q:v 2 "$frames_dir/%04d.jpg"
echo "Frames extracted for $segment_file and stored in $frames_dir"
else
echo "No output_*.mp4 file found in $segment_dir"
fi
fi
done
echo "Frame extraction completed."