Created
May 27, 2024 06:59
-
-
Save Frankenmint/5631201d743005fea6022df95912d803 to your computer and use it in GitHub Desktop.
Do you make music (without lyrics) and want a simple method for making visualizer videos? Use this to make 4k spectrograph videos from your MP3 files!
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 the required argument is provided | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <input_directory>" | |
exit 1 | |
fi | |
# Input directory containing MP3 files | |
INPUT_DIR="$1" | |
# Output directory | |
OUTPUT_DIR="$INPUT_DIR/output" | |
# Create the output directory if it doesn't exist | |
mkdir -p "$OUTPUT_DIR" | |
# Iterate through all MP3 files in the input directory | |
for INPUT_MP3 in "$INPUT_DIR"/*.mp3; do | |
# Extract the filename without the extension | |
FILENAME=$(basename "$INPUT_MP3" .mp3) | |
# Formatted title | |
TITLE="Frankenmint - $FILENAME" | |
# Output MP4 file | |
OUTPUT_MP4="$OUTPUT_DIR/${FILENAME}.mp4" | |
# Generate the video with the spectrogram and add the title | |
ffmpeg -i "$INPUT_MP3" -filter_complex "[0:a]showspectrum=s=3840x2160:legend=disabled:color=rainbow,drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:text='$TITLE':fontcolor=white:fontsize=100:x=(w-text_w)/2:y=(h-text_h)/10,format=yuv420p[v]" -map "[v]" -map 0:a -c:v libx264 -preset slow -crf 18 -c:a copy -shortest "$OUTPUT_MP4" | |
echo "Video created: $OUTPUT_MP4" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment