How to add offset or delay to audio file with ffmpeg?
Asked Answered
I

3

6

I need offset (some silence) in the start of file, so I tried:

./ffmpeg -itsoffset 100 -i 3.mp3 offset_test.mp3

But it doesn't work.

How to add offset to audio file with ffmpeg?

Impeachable answered 21/9, 2018 at 15:5 Comment(4)
Try concatenating silence instead.Aksum
Doesn't offset work with audio at all?Impeachable
itsoffset is for adjusting timestamps... that's not at all what you actually want to do. You want to add some silence to the start of your file, and therefore you need to concatenate silence with your audio.Aksum
see also Add 1 second of silence to audio through FFmpegPsychopath
F
10

For formats without timestamps, you'll need to add silence, as @Brad mentioned.

ffmpeg -i 3.mp3 -af adelay=100000|100000 delayed.mp3

The adelay takes delay in milliseconds per channel, separated by |.

Fanfaron answered 21/9, 2018 at 15:17 Comment(9)
Thanks, adelay is exactly what I need.Impeachable
It works in command: ffmpeg -vn -i 1.mp3 -i 2.mp3 -filter_complex "[a]adelay=2000|2000[a];[a][b]amix=inputs=2:dropout_transition=0" -q:a 1 -acodec libmp3lame -y amix_test.mp3, but when I try ffmpeg -i 3.mp3 -af adelay=100000|100000 delayed.mp3 it says At least one output file must be specified maybe you can say how specify output?Impeachable
If you're on windows, you'll need to enclose the adelay string in quotes.Fanfaron
What if, instead, of delay, we want to remove time (bring it forward) from the audio?Atworth
You would use the atrim filter. Or simply use ffmpeg -ss X -i 3.mp3 -c copy trimmed.mp3 where X is the duration in seconds of leading content to be trimmed.Fanfaron
Hi Gyan, thanks for your reply. I was hoping that if there is some single filter that could handle the positive delay (add delay to audio) or negative delay (remove time from the audio). Like the -itsoffset filter. Do you know if -itsoffset could be used only for audio files? wjwoodrow.wordpress.com/2013/02/04/…Atworth
itsoffset is relevant only when combining with other audio or video streams - not for solitary audio-only files like a .mp3Fanfaron
It extends audio to 10 times of original length. Here's my command ffmpeg -i output-audio.aac -af "adelay=58000|58000" output2-audio.aacAtomize
@Atworth I had to mix a video file without audio, with another audio file. The audio file was a bit in advance, trimming the video file by 0.5 second did the trick ! $ ffmpeg -ss 0.5 -i silent_video.mp4 -i audio.flac -c:v copy -c:a aac -strict experimental synchronized_video_with_sound.mp4Triceratops
S
4

The easiest way I found so far for ffmpeg ver > 4.2:

ffmpeg -i audio_in.wav -af areverse,apad=pad_dur=1s,areverse audio_out.wav

This will add an offset of 1 second to the audio.

Seaway answered 5/3, 2022 at 12:36 Comment(0)
M
-1

The correct way for -itsoffset should be:

ffmpeg -i audiofile.mp3 -itsoffset 100 offsetted.mp3

however, I'm not sure if -itsoffset will work.

Midland answered 22/10, 2023 at 2:31 Comment(1)
Not true! itsoffset is an input option and as such need to precede the input file. See ffmpeg: "As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file."Orson

© 2022 - 2025 — McMap. All rights reserved.