Skip to content

Instantly share code, notes, and snippets.

@rudolfbyker
Last active January 26, 2022 21:35
Show Gist options
  • Save rudolfbyker/0c613d20842b36e13b8482c6b34ff058 to your computer and use it in GitHub Desktop.
Save rudolfbyker/0c613d20842b36e13b8482c6b34ff058 to your computer and use it in GitHub Desktop.
Linux ffmpeg background audio recorder
#!/usr/bin/env bash
# Delete old recordings.
DIR="$HOME/rec"
EXPIRE=7
find $DIR -mtime +$EXPIRE -type f -delete
#!/usr/bin/env bash
# Put recordings in this folder
DIR="$HOME/rec"
# Prefix each file name with a timestamp
NAME=$(date +%Y%m%d%H%M%S)
# Split recording after $SEG seconds
SEG=3600
# Start recording
# ALSA: (this works more directly with the hardware, but it disables pulseaudio, which is not so nice)
#ffmpeg -loglevel warning -f alsa -i hw:0 -f segment -segment_time $SEG ${DIR}/${NAME}_%d.mp3
# Pulseaudio:
# TODO: Wait for pulseaudio to start!
ffmpeg -loglevel warning -f pulse -i alsa_input.pci-0000_00_1b.0.analog-stereo -f segment -segment_time $SEG ${DIR}/${NAME}_%d.mp3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment