30 lines
No EOL
929 B
Bash
30 lines
No EOL
929 B
Bash
#!/bin/bash
|
|
# Concatenate multiple WAV/audio files into a single mp3 using ffmpeg concat demuxer
|
|
#
|
|
# Usage: ./concat_wav.sh <output.mp3> <input1.WAV> <input2.WAV> ...
|
|
# Example: ./concat_wav.sh transcription/saramonic.mp3 20260325-091912.WAV 20260325-095007.WAV
|
|
|
|
set -euo pipefail
|
|
|
|
if [ $# -lt 3 ]; then
|
|
echo "Usage: $0 <output.mp3> <input1> <input2> [input3 ...]"
|
|
exit 1
|
|
fi
|
|
|
|
OUTPUT="$1"
|
|
shift
|
|
|
|
LISTFILE=$(mktemp /tmp/ffmpeg_concat_XXXXXX.txt)
|
|
trap "rm -f '$LISTFILE'" EXIT
|
|
|
|
for f in "$@"; do
|
|
ABSPATH="$(cd "$(dirname "$f")" && pwd)/$(basename "$f")"
|
|
echo "file '$ABSPATH'" >> "$LISTFILE"
|
|
done
|
|
|
|
echo "Concatenating $# files -> $OUTPUT"
|
|
ffmpeg -y -f concat -safe 0 -i "$LISTFILE" -ac 1 -ar 16000 -b:a 64k "$OUTPUT" 2>/dev/null
|
|
|
|
DUR=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$OUTPUT" | cut -d. -f1)
|
|
SIZE=$(du -h "$OUTPUT" | cut -f1)
|
|
echo "Done: ${DUR}s ($(( DUR / 60 ))m$(( DUR % 60 ))s), $SIZE" |