问题
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.
EDIT - Solved
Figured it out. I was calculating the tempo incorrectly.
Audio length / desired length = atempo
Should be
desired length / Audio length = atempo
I had to do a bit more reading on what the tempo actually does. Hope this helps someone.
来源:https://stackoverflow.com/questions/35515678/ffmpeg-stretch-audio-to-x-seconds