Created
February 15, 2023 00:38
-
-
Save aynik/e08123bbcbc264c6f0eaaa88002cf771 to your computer and use it in GitHub Desktop.
Mixtape video with cover art background and audio spectrum visualization
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
#!/usr/bin/env bash | |
set -e | |
font_file="~/Library/Fonts/GoNotoCurrent.ttf" | |
function ellipsis (){ | |
awk -v len=$1 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }' | |
} | |
for file in "$@"; do | |
title="$(exiftool -Title -b "$file" | ellipsis 35)" | |
artist="$(exiftool -Artist -b "$file" | ellipsis 60)" | |
album="$(exiftool -Album -b "$file" | ellipsis 70)" | |
year="$(exiftool -Date -b "$file" | cut -c1-4)" | |
duration="$(printf '%.3f' $(ffprobe -i "$file" -show_entries format=duration -v quiet -of csv="p=0"))" | |
half_duration="$(echo "$duration*.5" | bc)" | |
ffmpeg -y \ | |
-i "$file" \ | |
-filter_complex "[0:v]scale=1280:-1,setsar=1,boxblur=20:20,crop=1280:720[bg]; | |
[0:v]scale=500:500,crop=w=500:h=500[cover]; \ | |
[0:a]aformat=channel_layouts=mono:sample_rates=16000,highpass=f=200,lowpass=f=4000,showfreqs=mode=line:ascale=cbrt:fscale=lin:win_size=1024:s=580x280:r=30:colors=white[sw]; \ | |
[0:a]aformat=channel_layouts=mono:sample_rates=16000,highpass=f=200,lowpass=f=4000,showfreqs=mode=line:ascale=cbrt:fscale=lin:win_size=1024:s=580x280:r=30:[email protected][sws]; \ | |
[bg]drawtext=fontsize=36:fontfile='$font_file':fontcolor=white:[email protected]:shadowx=2:shadowy=2:text='${title//:/\\:}':x=(W/2)-20:y=H-(3.5*(H/10))[f1]; \ | |
[f1]drawtext=fontsize=26:fontfile='$font_file':fontcolor=white:[email protected]:shadowx=2:shadowy=2:text='${artist//:/\\:}':x=(W/2)-20:y=H-(4*(H/10))[f2]; \ | |
[f2]drawtext=fontsize=22:fontfile='$font_file':fontcolor=white:[email protected]:shadowx=2:shadowy=2:text='${album//:/\\:}':x=(W/2)-20:y=H-(2.5*(H/10))[f3]; \ | |
[f3]drawtext=fontsize=15:fontfile='$font_file':fontcolor=white:[email protected]:shadowx=2:shadowy=2:text='${year//:/\\:}':x=(W/2)-20:y=H-(2*(H/10))[cv]; \ | |
[cv]drawbox=x=((iw-w)/12)+1:y=((ih-h)/2)+2:w=500:h=500:[email protected][box]; \ | |
[box][sws]overlay=((W/2)-20)+2:((H/2)-h)+2[boxsws]; \ | |
[boxsws][sw]overlay=(W/2)-20:(H/2)-h[boxsw]; \ | |
[boxsw][cover]overlay=(W-w)/12:(H-h)/2" \ | |
-s "1280x720" \ | |
-c:v libx264 -preset slow -crf 18 -profile:v high -level 4.0 \ | |
-bf 2 -coder 1 -pix_fmt yuv420p -b:v 10M -threads 4 -cpu-used 0 -r 30 \ | |
-movflags +faststart "${file}.mp4" | |
done | |
ffmpeg -y -safe 0 -f concat \ | |
-i <(for f in "$@"; do echo "file '$PWD/${f}.mp4'"; done) \ | |
-c:v copy -c:a aac -b:a 320k mixtape.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment