Extract Audio by Timestamp Using FFmpeg aselect

This article demonstrates how to use the FFmpeg aselect filter to extract specific audio segments from an audio file based on precise timestamps. You will learn the syntax for selecting single or multiple time ranges and how to properly reconstruct the audio timeline to avoid empty silent gaps in your output file.

The aselect filter works by evaluating an expression for each audio frame. If the expression evaluates to a non-zero value (true), the frame is kept; otherwise, it is discarded.

Extracting a Single Audio Segment

To extract a single segment of audio, use the between(t, start, end) function inside the aselect filter, where t represents the timestamp in seconds.

ffmpeg -i input.mp3 -af "aselect='between(t,10,25)', asetpts=N/SR/TB" output.mp3

Command breakdown: * -i input.mp3: Specifies the input audio file. * -af: Applies an audio filtergraph. * aselect='between(t,10,25)': Instructs FFmpeg to only keep audio frames where the timestamp t is between 10 and 25 seconds. * , asetpts=N/SR/TB: Resets the presentation timestamps of the output frames. Without this, the output audio would contain 10 seconds of silence at the beginning before the extracted audio plays.

Extracting Multiple Audio Segments

You can extract and combine multiple segments from the same file by joining between expressions with the + operator, which acts as a logical “OR”.

The following command extracts audio from 10 to 20 seconds, and from 50 to 60 seconds, merging them into a single continuous file:

ffmpeg -i input.mp3 -af "aselect='between(t,10,20)+between(t,50,60)', asetpts=N/SR/TB" output.mp3

Specifying Timestamps in Sexagesimal Format

If you prefer to work with hours, minutes, and seconds (HH:MM:SS) instead of raw seconds, you must convert those times into seconds inside the filter expression. For example, to extract from 1 minute 15 seconds (75 seconds) to 2 minutes 30 seconds (150 seconds):

ffmpeg -i input.mp3 -af "aselect='between(t,75,150)', asetpts=N/SR/TB" output.mp3