简体   繁体   English

如何使用 FFMPEG 将 MP3 转换为恒定比特率

[英]How to convert MP3's to constant bitrate using FFMPEG

I have found that MP3's encoded with variable bit rate cause the currentTime property to be reported incorrectly , especially when scrubbing.我发现使用可变比特率编码的 MP3 会导致错误报告currentTime 属性,尤其是在清理时。 That has wreaked havok on my app and has been a nightmare to debug.这对我的应用程序造成了严重破坏,并且是调试的噩梦。

I believe I need to convert all my MP3's to constant bitrate.我相信我需要将我所有的 MP3 转换为恒定比特率。 Can FFMPEG (or something else) help me do that efficiently? FFMPEG(或其他东西)可以帮助我有效地做到这一点吗?

I also had issues with HTML5 being inaccurate for large mp3s.我也遇到了 HTML5 对于大型 mp3 不准确的问题。 Since quality was not a big issue for my audio, I converted to constant bit rate of 8kbps, sample rate 8k, mono and it solved my issues.由于质量对我的音频来说不是大问题,我转换为 8kbps 的恒定比特率、8k 的采样率、单声道,它解决了我的问题。

You can convert to a contant bit rate for a few files using Audacity (export > save to mp3 > constant bit rate).您可以使用Audacity将一些文件转换为恒定比特率(导出 > 保存到 mp3 > 恒定比特率)。

Or, using FFMPEG :或者,使用FFMPEG

ffmpeg -i input.wav -codec:a libmp3lame -b:a 8k output.mp3

If you also want to reduce to mono and a 8k sample rate:如果您还想减少到单声道和 8k 采样率:

ffmpeg -i input.wav -codec:a libmp3lame -b:a 8k -ac 1 -ar 8000 output.mp3

Using the second compressed an hour of audio to under 5MB.使用第二个将一小时的音频压缩到 5MB 以下。

Something else is going on.还有其他事情正在发生。 currentTime should not be influenced by the fact that you are using variable-bit rate MP3s. currentTime不应受到您使用可变比特率 MP3 的影响。

Perhaps the context sampleRate is not the same as the sample rate as the MP3s?也许上下文 sampleRate 与 MP3 的采样率不同? That will mess up timing of the audio samples because WebAudio will resample the MP3s to the context sample rate.这会扰乱音频样本的时间,因为 WebAudio 会将 MP3 重新采样为上下文采样率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM