Same root cause as the visualize_clip.sh fix: showwavespic/ showspectrumpic render one summary frame for whatever stream they're given, and output-side -t/-ss placement doesn't restrict that -- so every prior use of this script showed the *entire* remaining file, regardless of the requested duration. Found directly: a requested 4s duration produced a byte-identical image to a 35s request for the same pair. Moved both -ss and -t to apply per-input, before each -i.
48 lines
1.9 KiB
Bash
Executable File
48 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Renders two audio clips' waveforms + spectrograms stacked in one image,
|
|
# aligned at the same timescale, for direct side-by-side visual
|
|
# comparison -- complementary to a numeric correlation value, which can
|
|
# be fooled by brittle thresholds or codec artifacts (see docs/DESIGN.md).
|
|
# A shared melodic/rhythmic pattern should be visually obvious as matching
|
|
# texture in both spectrograms at the same horizontal position; divergent
|
|
# content looks different from the point they diverge.
|
|
#
|
|
# Usage:
|
|
# tools/compare_clips.sh <file_a> <file_b> [start_seconds] [duration_seconds] [output.png]
|
|
#
|
|
# Example:
|
|
# tools/compare_clips.sh hpr0900.mp3 hpr0901.mp3 0 35 /tmp/compare.png
|
|
set -euo pipefail
|
|
|
|
if [ "$#" -lt 2 ]; then
|
|
echo "Usage: $0 <file_a> <file_b> [start_seconds] [duration_seconds] [output.png]" >&2
|
|
exit 1
|
|
fi
|
|
|
|
file_a="$1"
|
|
file_b="$2"
|
|
start="${3:-0}"
|
|
duration="${4:-40}"
|
|
default_out="compare_$(basename "${file_a%.*}")_vs_$(basename "${file_b%.*}").png"
|
|
out="${5:-$default_out}"
|
|
|
|
# -ss and -t MUST both be input options (before each -i), not placed after
|
|
# both -i's: showwavespic/showspectrumpic render one summary frame for the
|
|
# whole stream they're given, and output-side duration/seeking silently
|
|
# does nothing with them instead of erroring -- same root cause as the
|
|
# visualize_clip.sh fix. Found directly: a requested 4s duration produced
|
|
# a byte-identical image to a 35s request.
|
|
ffmpeg -v error -y \
|
|
-ss "$start" -t "$duration" -i "$file_a" \
|
|
-ss "$start" -t "$duration" -i "$file_b" \
|
|
-ar 16000 -ac 1 \
|
|
-filter_complex \
|
|
"[0:a]showwavespic=s=1200x150:colors=white[wave_a]; \
|
|
[0:a]showspectrumpic=s=1200x200:legend=0[spec_a]; \
|
|
[1:a]showwavespic=s=1200x150:colors=yellow[wave_b]; \
|
|
[1:a]showspectrumpic=s=1200x200:legend=0[spec_b]; \
|
|
[wave_a][spec_a][wave_b][spec_b]vstack=4" \
|
|
-frames:v 1 "$out"
|
|
|
|
echo "Wrote $out: top half = $(basename "$file_a"), bottom half = $(basename "$file_b"), both ${start}s-$((start + duration))s"
|