ffmpeg, stretch audio to x seconds

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 19:21:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!