brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -af atempo=1.25 plays an audio file faster and saves it as a new one

Ffmpeg
~/tips/tip-ffmpeg-atempo-change-audio-speed

ffmpeg -i talk.mp3 -af atempo=1.25 talk-fast.mp3

Makes an audio file play faster or slower and writes it as a new file.

A long talk or audiobook goes faster at 1.25x, and ffmpeg can make a file that way once instead of relying on a player setting. The filter for it is atempo.

atempo adjusts the tempo of audio. The documentation gives the allowed range directly: tempo must be in the [0.5, 100.0] range. Below 1 it slows down, above 1 it speeds up. The examples in the docs are plain values like atempo=0.8 and atempo=3.

ffmpeg -i talk.mp3 -af atempo=1.25 talk-fast.mp3

That writes a new file that plays 25 percent faster. -af is the shorthand for an audio filter, and the filter takes the value after the equals sign.

The docs also show how to build a bigger factor out of several steps: atempo=sqrt(3),atempo=sqrt(3) is two filters in a row that multiply to 3. I would only reach for that to understand what the filter does, since one filter already covers a very wide range.

Since the audio is filtered, it gets decoded and encoded again. The file is not a copy of the original, so keep the original and give the new one another name. For a podcast I would pick a bitrate on purpose instead of taking the default, for example by adding -b:a 128k, which is the form the ffmpeg manual uses in its own example for a 64k MPEG audio file.

If the input is a video, the picture does not speed up along with the audio. The filter touches the audio only, so the two would drift apart. For a video you need a matching change to the picture as well, and I have not checked that part against the docs, so I will leave it out here.

Check the beginning and the end of the result. A speed that is high but still in range can make speech tiring, so 1.25 or 1.5 is where I would stop.

Further reading: ffmpeg filters documentation: atempo, ffmpeg documentation: audio options

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link