Add a click track for a metronome
A click track is a short percussive sound played at a steady tempo. Musicians use it to stay in time, podcasters use it to mark sections, and fitness apps use it to pace a workout. FFmpeg can generate one with a few lines: a sine wave at a fixed frequency, pulsed at the desired BPM.
The command
ffmpeg -f lavfi -i "sine=frequency=1000:duration=0.05" -af "apad,atrim=0:0.05" -c:a pcm_s16le click.wav
ffmpeg -f lavfi -i "anullsrc=r=48000" -f lavfi -i "sine=frequency=1000:duration=0.05" -filter_complex "[1:a]aloop=loop=-1:size=1[click];[0:a][click]amix=inputs=2:duration=first,atrim=0:60" -t 60 -c:a pcm_s16le click_track.wavWhat it does
The first command generates a single 50-millisecond click. The second command loops it at a steady interval for a 60-second track. For a 120 BPM click, you need a click every 0.5 seconds, so the loop and the gap need to be tuned together. The result is a stereo or mono file you can play in any audio player, with a click at the start of each beat.
Requirements
No input file. The `lavfi` virtual input lets you use a source filter as the only input. The output codec `pcm_s16le` is the standard 16-bit signed little-endian PCM. No hardware, no special build.
Things to avoid
- Using a single sine wave as the click. A 1 kHz sine is clean but boring; a short noise burst or a higher-pitched sine is more audible on small speakers.
- Looping the click without a gap. The `aloop` filter repeats the input, so the click will be a continuous tone, not a percussive blip.
- Forgetting the `-t 60` flag. The default output duration is 10 seconds; for a 60-second click track, set it explicitly.
- Relying on the click track for studio use. A real metronome generates a percussive sample with attack and decay; the sine version is a test signal, not a musical one.