Skip to content

Instantly share code, notes, and snippets.

@smellslikeml
Created June 26, 2023 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smellslikeml/8a444ac5aa9b4c5e5f4025fcf5545f44 to your computer and use it in GitHub Desktop.
Save smellslikeml/8a444ac5aa9b4c5e5f4025fcf5545f44 to your computer and use it in GitHub Desktop.
Concatenate videos with ffmpeg
#!/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