Created
December 5, 2023 21:24
-
-
Save saravanabalagi/7f15dabdf3cc6f9350cc991506de224c to your computer and use it in GitHub Desktop.
YouTube Trim into 60 second clips for Shorts
This file contains hidden or 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 | |
if [ "$#" -lt 1 ]; then | |
echo "Usage: $0 <input_video> [output_directory]" | |
exit 1 | |
fi | |
input_video="$1" | |
output_directory="${2:-segmented}" # Use "segmented" as the default if no second argument is provided | |
# Step 1: Split the video into segments and store them in the output directory | |
mkdir -p "$output_directory" | |
ffmpeg -i "$input_video" -c:v copy -c:a copy -f segment -segment_time 60 "$output_directory/output_%02d.mp4" | |
# Step 2: Create a temporary directory for trimmed videos | |
tmp_directory="tmp_trimmed_videos" | |
mkdir -p "$tmp_directory" | |
# Trim the videos and save them in the temporary directory | |
for file in "$output_directory"/*.mp4; do | |
filename=$(basename "$file") | |
trimmed_filename="$tmp_directory/${filename}" | |
ffmpeg -i "$file" -t 59.9 -c:v copy -c:a copy "$trimmed_filename" | |
done | |
# Move the trimmed videos back to the original directory with the specified naming pattern | |
for file in "$tmp_directory"/*.mp4; do | |
filename=$(basename "$file") | |
mv "$file" "$output_directory/${filename}" | |
done | |
# Clean up the temporary directory | |
rmdir "$tmp_directory" | |
echo "Segmentation and trimming completed. Trimmed videos are in the '$output_directory' folder." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment