Skip to content

Instantly share code, notes, and snippets.

@SammysHP
Created December 30, 2015 20:05
Show Gist options
  • Save SammysHP/2f6703a8cc08328a5545 to your computer and use it in GitHub Desktop.
Save SammysHP/2f6703a8cc08328a5545 to your computer and use it in GitHub Desktop.
Concatenate audio files into single opus file
#!/bin/bash
TMP=$(mktemp -d)
# syntax check
if [ -z "$3" ]; then
echo "Syntax: $0 <output>.opus <input1> <input2> ..."
exit 1
fi
# split arguments (inputs in $@)
output="$1"
shift
# decode inputs
intermediates=""
i=1
for f in "$@"; do
mkfifo $TMP/fifo_$i
ffmpeg -y -i "$f" -vn -f u16le -c:a pcm_s16le -ac 2 -ar 48000 $TMP/fifo_$i 2>/dev/null </dev/null &
intermediates="$intermediates $TMP/fifo_$i"
let i++
done
# concatenate
mkfifo $TMP/fifo_all
cat $intermediates > $TMP/fifo_all &
# encode
ffmpeg -f u16le -c:a pcm_s16le -ac 2 -ar 48000 -i $TMP/fifo_all -c:a libopus -b:a 48k "$output.opus"
# cleanup
rm $TMP/fifo_*
rmdir $TMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment