如何以编程方式将 mp3 转换为 itunes 可播放的 aac/m4a 文件?

发布于 2024-07-04 15:17:01 字数 272 浏览 7 评论 0原文

我一直在寻找一种以编程方式或通过命令行将 mp3 转换为 aac 的方法,但没有成功。 理想情况下,我有一段代码可以从我的 Rails 应用程序中调用,将 mp3 转换为 aac。 我安装了 ffmpeg 和 libfaac,并能够使用以下命令创建 aac 文件:

ffmpeg -i test.mp3 -acodec libfaac -ab 163840 dest.aac

当我将输出文件的名称更改为 dest 时。 m4a,它不能在 iTunes 中播放。

谢谢!

I've been looking for a way to convert an mp3 to aac programmatically or via the command line with no luck. Ideally, I'd have a snippet of code that I could call from my rails app that converts an mp3 to an aac. I installed ffmpeg and libfaac and was able to create an aac file with the following command:

ffmpeg -i test.mp3 -acodec libfaac -ab 163840 dest.aac

When i change the output file's name to dest.m4a, it doesn't play in iTunes.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

高跟鞋的旋律 2024-07-11 15:17:01

在运行 Rails 应用程序的 Linux/Windows 机器上安装转换应用程序后,使用 Ruby 中的“system()”命令来调用系统上的转换应用程序。 系统(“此处的命令”);

After installing the converting app on the linux/window machine you're running your Rails application on, use the "system()" command in Ruby to invoke the converting application on the system. system("command_here");

寂寞花火° 2024-07-11 15:17:01

我很幸运地使用了 mplayer (我相信它使用了 ffmpeg...)并且很差劲。 以至于我已经将它包装在一个脚本中:

#!/bin/sh

TARGET=$1

BASE=`basename "${TARGET}"`
echo TARGET: "${TARGET}"
echo BASE:   "${BASE}" .m4a

# Warning! Race condition vulnerability here! Should use a mktemp
# variant or something...
mkfifo encode
mplayer -quiet -ao pcm -aofile encode "${TARGET}" &
lame --silent encode "${BASE}".mp3
rm encode

抱歉,安全问题,有一天我在火车上把它搞砸了......

我的 mplayer 和 lame 来自 fink

I've had good luck using mplayer (which I believe uses ffmpeg...) and lame. To the point that I've wrapped it up in a script:

#!/bin/sh

TARGET=$1

BASE=`basename "${TARGET}"`
echo TARGET: "${TARGET}"
echo BASE:   "${BASE}" .m4a

# Warning! Race condition vulnerability here! Should use a mktemp
# variant or something...
mkfifo encode
mplayer -quiet -ao pcm -aofile encode "${TARGET}" &
lame --silent encode "${BASE}".mp3
rm encode

Sorry for the security issues, I banged this out on the train one day...

My mplayer and lame come from fink

一抹淡然 2024-07-11 15:17:01

实际上,语法是 ffmpeg -i input.mp3 -c:a aac -strict -2 -b:a 256k output.m4a; 如果模拟“正确”的比特率则更正确。
参见:编译方案的链接。 (rpmfusion包也工作正常:

配置:--prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/ lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-缓冲区大小=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-libass --enable-libcdio --启用libcelt --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect

Actually, syntax is ffmpeg -i input.mp3 -c:a aac -strict -2 -b:a 256k output.m4a; more correct if one is emulating "correct" bitrate.
cf.:link for a compilation scheme. (rpmfusion package works fine too:

configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-libass --enable-libcdio --enable-libcelt --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect

左秋 2024-07-11 15:17:01

据我所知,只有三个免费的 AAC 编码器可以通过命令行界面使用:

  1. FAAC (LPGL),说实话,它相当糟糕(在相同比特率下,质量明显比 LAME 差)。 不过,如果您愿意追求更高的比特率(>>128kbps)并且需要 AAC 是为了兼容性而不是质量原因,那也没关系。 使用 FAAC 最常见的方法是通过 ffmpeg,如 libfaac。

  2. Nero AAC,其命令行编码器可在 Windows 和 Linux 下免费使用,但仅限于非商业用途(并且相应地是封闭源代码)。

  3. ffmpeg 的 AAC 编码器仍在开发中,虽然我相信它在技术上确实有效,但它一点也不稳定、不好甚至快,因为它仍处于初始阶段。 据我所知,它在 trunk 中也不可用。

(编辑:似乎 iTunes 也可能有一个,我怀疑它的使用条款与 Nero 类似。据我所知,它的质量是可比的。)

There are only three free AAC encoders that I know of that are available through a commandline interface:

  1. FAAC (LPGL), which is honestly pretty bad (the quality is going to be significantly worse than LAME at the same bitrate). Its fine though if you're willing to go for higher bitrates (>>128kbps) and need AAC for compatibility, not quality reasons. The most common way to use FAAC is through ffmpeg, as libfaac.

  2. Nero AAC, the commandline encoder for which is available for free under Windows and Linux, but only for noncommercial use (and is correspondingly closed-source).

  3. ffmpeg's AAC encoder, which is still under development and while I believe it does technically work, it is not at all stable or good or even fast, since its still in the initial stages. Its also not available in trunk, as far as I know.

(Edit: Seems iTunes might have one too, I suspect its terms of use are similar to Nero's. AFAIK its quality is comparable.)

深者入戏 2024-07-11 15:17:01

FFmpeg 提供 AAC 编码工具(如果您已编译)。如果您使用的是 Windows,您可以获取来自此处的完整二进制文件

ffmpeg -i source.mp3 -acodec libfaac -ab 128k dest.aac

我不确定您如何从 ruby​​ 中调用它。

另外,请务必适当设置比特率。

FFmpeg provides AAC encoding facilities if you've compiled them in. If you are using Windows you can grab full binaries from here

ffmpeg -i source.mp3 -acodec libfaac -ab 128k dest.aac

I'm not sure how you would call this from ruby.

Also, be sure to set the bitrate appropriately.

合久必婚 2024-07-11 15:17:01

我意识到我参加这个聚会迟到了,但我质疑这个问题的前提。 为什么你甚至想将 MP3 转换为“itunes 可播放”格式? iTunes 本身已经可以处理 MP3。

看起来您正在进行不必要的转换,并且由于您正在从一种有损格式转换为另一种有损格式,因此您在此过程中失去了一些质量。

I realize I'm late to this party, but I'm questioning the premise of this question. Why do you even want to convert an MP3 to an "itunes playable" format? iTunes already handles MP3s natively.

It seems like you are doing an unnecessary conversion, and since you are converting from one lossy format to another, you are losing some quality in the process.

泪意 2024-07-11 15:17:01

在ffmpeg 0.5或更高版本中使用
ffmpeg -i source.mp3 target.m4a

为了获得更好的结果来传输元数据并覆盖默认比特率 ffmpeg 适用

ffmpeg -i "input.mp3" -ab 256k -map_meta_data input.mp3:output.m4a output.m4a

最好不要转换为ipod 播放 mp3 很好(我知道有这样的答案,但我的地位低不允许投票)

in ffmpeg 0.5 or later use
ffmpeg -i source.mp3 target.m4a

for better results to transfer metadata and to override default bitrate ffmpeg applies

ffmpeg -i "input.mp3" -ab 256k -map_meta_data input.mp3:output.m4a output.m4a

best do not convert as ipod plays mp3 fine (I know there is such answer but my low standing does not allow voting)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文