Last active
September 29, 2021 19:14
-
-
Save bobbigmac/fee2d804d853e207ee32cc60497beefd to your computer and use it in GitHub Desktop.
Generate a sample preview video for each of the win_func, ascale and fscale (and others) options in ffmpegs showfreqs filter, given in input audio file
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
| trap 'exit 130' INT | |
| soundfile=$1 | |
| if [ ! -f "${soundfile}" ]; then | |
| echo "Pass sound file as first parameter" | |
| exit | |
| fi | |
| soundname=$(basename "$soundfile" --) | |
| counter=0 | |
| duration=10 | |
| size="1280x720" | |
| colors="red|blue" | |
| # showfreqs options | |
| modes=("line") # "bar" "dot") | |
| winFuncs=("hanning" "hamming" "rect" "bartlett" "blackman" "welch" "flattop" "bharris" "bnuttall" "bhann" "sine" "nuttall" "lanczos" "gauss" "tukey" "dolph" "cauchy" "parzen" "poisson" "bohman") | |
| ascales=("log" "sqrt" "cbrt") # ("lin" "sqrt" "cbrt" "log") | |
| fscales=("lin" "log" "rlog") | |
| winSizes=(1024 4096) # (512 1024 2048 4096 8192) | |
| averages=("0.75" "1") # ("0.1" "0.5" "0.9" "1") | |
| overlaps=("0.75" "1") # ("0.1" "0.5" "0.9" "1") | |
| datas=("magnitude") # "phase" "delay") | |
| mkdir -p "./test-freqs/out" | |
| for mode in ${modes[@]}; do | |
| for winFunc in ${winFuncs[@]}; do | |
| for winSize in ${winSizes[@]}; do | |
| for average in ${averages[@]}; do | |
| for overlap in ${overlaps[@]}; do | |
| for ascale in ${ascales[@]}; do | |
| for fscale in ${fscales[@]}; do | |
| for data in ${datas[@]}; do | |
| outName="./test-freqs/out/${counter}_showfreqs_m-${mode}_wf-${winFunc}_as-${ascale}_fs-${fscale}_ws-${winSize}_avg-${average}_ov-${overlap}_d-${data}.mp4" | |
| outDescFile="./test-freqs/out/${counter}_showfreqs_m-${mode}_wf-${winFunc}_as-${ascale}_fs-${fscale}_ws-${winSize}_avg-${average}_ov-${overlap}_d-${data}.txt" | |
| outDescription="File: $soundname\nmode: ${mode}\nwin_func: ${winFunc}\nascale: ${ascale}\nfscale: ${fscale}\nwin_size: ${winSize}\naveraging: ${average}\noverlap: ${overlap}\ndata: ${data}" | |
| echo -e "$outDescription" > "$outDescFile" | |
| drawText="drawtext=textfile=${outDescFile}:x=20:y=20:fontsize=30:fontcolor=white" | |
| doFreqs="showfreqs=size=${size}:mode=${mode}:ascale=${ascale}:fscale=${fscale}:win_size=${winSize}:overlap=${overlap}:colors=${colors}:data=${data}:win_func=${winFunc}:averaging=${average},${drawText},format=yuv420p[out]" | |
| if [ ! -f "${outName}" ]; then | |
| echo "Rendering: ${outName}"; | |
| ffmpeg -i "$soundfile" \ | |
| -filter_complex "${doFreqs}" \ | |
| -map "[out]" -map "0:a:0" \ | |
| -vcodec libx264 -crf 18 -y \ | |
| -t "${duration}s" \ | |
| "$outName" | |
| fi | |
| rm -f "$outDescFile" | |
| ((counter=counter+1)) | |
| done | |
| done | |
| done | |
| done | |
| done | |
| done | |
| done | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment