Created
June 26, 2023 04:03
-
-
Save smellslikeml/8a444ac5aa9b4c5e5f4025fcf5545f44 to your computer and use it in GitHub Desktop.
Concatenate videos with ffmpeg
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 | |
# Ensure a list of clips is provided | |
if [ $# -eq 0 ]; then | |
echo "Please provide a list of clips to process and concatenate." | |
exit 1 | |
fi | |
# Directory to store processed clips | |
mkdir -p processed_clips | |
# Process each clip | |
for clip in "$@"; do | |
# Get the base name of the clip | |
basename=$(basename "$clip") | |
# Create a name for the processed clip | |
processed_clip="processed_clips/$basename" | |
# Scale, set aspect ratio, and set frame rate | |
ffmpeg -i "$clip" -vf "scale=1920:1080,setsar=1,setdar=16/9,fps=30" "$processed_clip" | |
done | |
# Create a file list | |
echo "" > files.txt | |
for clip in processed_clips/*.mp4; do | |
echo "file '$clip'" >> files.txt | |
done | |
# Concatenate all processed clips | |
ffmpeg -f concat -safe 0 -i files.txt output.mp4 | |
# Cleanup | |
rm -rf processed_clips | |
rm files.txt | |
echo "All clips processed and concatenated into output.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment