ffmpeg, stretch audio to x seconds
Asked Answered
B

1

10

I am trying to make an audio file be exactly x second.

So far i tried using the atempo filter by doing the following calculation

Audio length / desired length = atempo.

But this is not accurate, and I am having to tweak the tempo manually to get it to an exact fit.

Are there any other solutions to get this work ? Or am I doing this incorrectly?

My original file is a wav file, and my output in an mp3

Here is a sample command

ffmpeg -i input.wav -codec:a libmp3lame -filter:a "atempo=0.9992323" -b:a 320K output.mp3

UPDATE:

I was able to correctly calculate the tempo by changing the way I am receiving the audio length.

I am now calculating the current audio length using the actual file size and the sample rate.

Audio Length = file size / (sample rate * 2)

Sample rate is something like 16000 Hz. You can get that by using ffprob or ffmpeg.

Burleson answered 19/2, 2016 at 21:47 Comment(3)
How much difference are you getting between desired and obtained duration?Manlike
For a 7 minute audio, the difference is a good 3 to 5 seconds.Burleson
Your originial formula seems right to me. atempo < 1 makes the audio longer, atempo > 1 makes it shorter. ffmpeg.org/ffmpeg-filters.html#atempoNorris
S
0

You are calculating the tempo incorrectly.

Audio length / desired length = atempo

should be:

desired length / Audio length = atempo

This answer was posted as an edit to the question ffmpeg, stretch audio to x seconds by the OP Max Doumit under CC BY-SA 3.0.

Superload answered 11/12, 2022 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.