Jump to content

Command Crate ¿about?

Convert FLAC audio with artwork to WebM 1080p video with "intelligent", transparent, delay-compensated, faded, pill-shaped audio visualiser (find, ffmpeg, bash, metaflac, imagemagick)

find . -type f -wholename '*.flac' -exec bash -c 'DELAY_COMPENSATION=0.2; SMOOTHING_PX=2; FLAC_FILE="$0"; COVER_PATH=".meta/artwork/$(basename "${FLAC_FILE}" ".flac")-video_cover_l.jpeg"; BRIGHTNESS=$(magick "$COVER_PATH" -colorspace Gray -format "%[mean]" info:); VISUALISER_COLOR="white"; BRIGHTNESS_THRESHOLD=35000; if (( $(echo "$BRIGHTNESS > $BRIGHTNESS_THRESHOLD" | bc -l) )); then VISUALISER_COLOR="black"; fi; GEQ_FORMAT="r=r(X,Y):g=g(X,Y):b=b(X,Y):a=st(0,H/2*sin(X/W*PI));st(1,abs(Y-H/2));if(gt(ld(1),ld(0)),0,if(lt(ld(1),ld(0)-%s),alpha(X,Y),alpha(X,Y)*(ld(0)-ld(1))/%s))"; GEQ_FINAL=$(printf "$GEQ_FORMAT" "$SMOOTHING_PX" "$SMOOTHING_PX"); echo "Processing ${FLAC_FILE}. Cover brightness: $BRIGHTNESS. Using visualiser color: $VISUALISER_COLOR. Applying ${DELAY_COMPENSATION}s delay compensation. Applying ${SMOOTHING_PX}px edge smoothing."; ffmpeg -hide_banner -loglevel error -nostats -y -framerate 24 -i "$COVER_PATH" -i "$FLAC_FILE" -filter_complex "[0:v]scale=1920:1080,setsar=1[bg]; [1:a]asplit[a_out][a_viz]; [a_viz]asetpts=PTS-${DELAY_COMPENSATION}/TB[a_viz_shifted]; [a_viz_shifted]showwaves=s=1400x140:mode=cline:colors=${VISUALISER_COLOR}:draw=full:rate=24,format=rgba[waves_hr]; [waves_hr]scale=700:70:eval=init:flags=lanczos[waves]; [waves]geq='\''"$GEQ_FINAL"'\''[waves_faded]; [waves_faded]colorchannelmixer=aa=0.3[waves_transparent]; [bg][waves_transparent]overlay=(W-w)/2:910[outv]" -map "[outv]" -map "[a_out]" -metadata title="$(metaflac --show-tag=TITLE "${FLAC_FILE}" | cut -c7-)" -metadata artist="$(metaflac --show-tag=ARTIST "${FLAC_FILE}" | cut -c8-)" -metadata album="$(metaflac --show-tag=ALBUM "${FLAC_FILE}" | cut -c7-)" -metadata genre="$(metaflac --show-tag=GENRE "${FLAC_FILE}" | cut -c7-)" -metadata encoded_by="FFmpeg" -crf 45 -b:v 0 -codec:v libvpx-vp9 -cpu-used 0 -row-mt 1 -auto-alt-ref 1 -lag-in-frames 25 -g 250 -codec:a libopus -b:a 160k -vbr on -compression_level 10 -frame_duration 60 -application audio -pix_fmt yuv420p -threads 0 "./${FLAC_FILE%.*}_vp9_opus_visualiser_1080p.webm"' '{}' \;

This command automatically converts FLAC audio files into WebM videos. For each track, it uses the corresponding album art as a static background and overlays a custom audio visualiser. This transparent visualiser is styled as a pill-shape with faded edges, and its color is intelligently set to black or white to contrast with the brightness of the artwork. To ensure the visuals align perfectly with the sound, a delay is applied to the visualiser's audio stream for precise synchronization. Finally, all original metadata (like title, artist, and album) is transferred from the FLAC file to the new WebM video.

multimedia [kb:293]