Files
Lee Hanken ec492067f3 Fix visualize_clip.sh: -ss after -i silently produced an empty image
showwavespic/showspectrumpic render one summary frame for the whole
stream they're given; output-side seeking (-ss after -i, what the script
had) silently produces zero frames with them, rather than erroring.
Found directly: every prior use of this script happened to start at 0,
so a nonzero start offset was never actually exercised until now. Moved
-ss before -i (input-side seeking), which is both correct here and
normally faster since ffmpeg can seek without decoding up to that point.
2026-11-22 14:33:28 +00:00

45 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Renders a waveform + spectrogram image for a clip of an audio file, so a
# suspicious cut point can be inspected directly rather than only reasoned
# about from correlation numbers or transcript text. A dense, continuous
# band is speech or music; a flat/quiet stretch is silence; an abrupt
# change in texture is usually where one kind of content ends and another
# begins (e.g. the station's intro bed stopping and a host's raw recording
# starting).
#
# Usage:
# tools/visualize_clip.sh <audio_file> [start_seconds] [duration_seconds] [output.png]
#
# Examples:
# tools/visualize_clip.sh cache/audio/hpr4775.opus
# tools/visualize_clip.sh cache/audio/hpr4775.opus 0 55
# tools/visualize_clip.sh cache/audio/hpr3700.mp3 880 90 /tmp/hpr3700_outro.png
#
# Requires only ffmpeg (already a dependency of this repo); no Python, no
# extra packages.
set -euo pipefail
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <audio_file> [start_seconds] [duration_seconds] [output.png]" >&2
exit 1
fi
audio_file="$1"
start="${2:-0}"
duration="${3:-60}"
default_out="$(basename "${audio_file%.*}")_${start}-$((start + duration))s.png"
out="${4:-$default_out}"
# -ss MUST come before -i (input-side seeking): showwavespic/
# showspectrumpic render one summary frame for the whole stream they're
# given, and output-side seeking (-ss after -i) silently produces zero
# frames with them -- found directly, trying to inspect a nonzero start
# offset for the first time; every prior use of this script happened to
# start at 0, which is why this went unnoticed until now.
ffmpeg -v error -y -ss "$start" -i "$audio_file" -t "$duration" -ar 16000 -ac 1 \
-filter_complex \
"[0:a]showwavespic=s=1200x200:colors=white[wave];[0:a]showspectrumpic=s=1200x300:legend=0[spec];[wave][spec]vstack" \
-frames:v 1 "$out"
echo "Wrote $out (waveform on top, spectrogram below, covering ${start}s-$((start + duration))s of $audio_file)"