ffmpeg - 如何编译 ffmpeg 以仅获得 mp3 和 mp4 支持

标签 ffmpeg compilation

我正在构建 Electron 应用程序,并使用 ffmpeg 将 m4a 或 webm 文件转换为 mp3,并将仅视频 mp4 与 m4a 音频文件合并为 mp4。

我可以使用 [media-autobuild-suite] ( https://github.com/jb-alvarado/media-autobuild_suite ) 和 light build 选项来实现这一点,但静态文件的大小约为 20mb,我想再缩小一点。我已经使用此配置编译了 ffmpeg 和 ffprobe。

--disable-libaom
--disable-version3
# Full
--disable-chromaprint
--disable-cuda-sdk
--disable-decklink
--disable-frei0r
--disable-libbs2b
--disable-libcaca
--disable-libcdio
--disable-libfdk-aac
--disable-libflite
--disable-libfribidi
--disable-libgme
--disable-libgsm
--disable-libilbc
--disable-libkvazaar
--disable-libmodplug
--disable-libnpp
--disable-libopenh264
--disable-libopenmpt
--disable-librtmp
--disable-librubberband
--disable-libssh
--disable-libtesseract
--disable-libxavs
--disable-libzmq
--disable-libzvbi
--disable-opencl
--disable-opengl
--disable-libvmaf
--disable-libcodec2
--disable-libsrt
--disable-ladspa
--disable-ffplay
#--enable-vapoursynth
#--enable-liblensfun
--disable-libndi_newtek

--enable-demuxer=mp3
--enable-demuxer=mov
--enable-demuxer=opus

--enable-parser=ac3
--enable-parser=mpegaudio
--enable-parser=h264
--enable-parser=opus

--enable-protocol=file
--enable-protocol=pipe

--enable-decoder=mp3
--enable-decoder=mp4
--enable-decoder=opus

--enable-encoder=mp3
--enable-encoder=mp4
--enable-encoder=opus

使用此配置,我得到 ffmpeg 静态文件约为 2mb 和 ffprobe 静态文件约为 2mb,但出现此错误。

C:\Users\Admin\Desktop\ffmpeg compilations\2mb\local64>ffmpeg -i simple.m4a simple.mp3 
ffmpeg version N-93147-g9326117bf6 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 8.2.1 (Rev1, Built by MSYS2 project) 20181214
configuration:  .... //here comes configuration as described above
libavutil      56. 26.100 / 56. 26.100
libavcodec     58. 47.102 / 58. 47.102
libavformat    58. 26.101 / 58. 26.101
libavdevice    58.  6.101 / 58.  6.101
libavfilter     7. 48.100 /  7. 48.100
libswscale      5.  4.100 /  5.  4.100
libswresample   3.  4.100 /  3.  4.100
libpostproc    55.  4.100 / 55.  4.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'simple.m4a':
Metadata:
  major_brand     : dash
  minor_version   : 0
  compatible_brands: iso6mp41
  creation_time   : 2018-10-31T19:47:32.000000Z
Duration: 00:02:38.92, start: 0.000000, bitrate: 127 kb/s
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, 7 kb/s (default)
Metadata:
  creation_time   : 2018-10-31T19:47:32.000000Z
  handler_name    : SoundHandler
[NULL @ 0000000000486200] Unable to find a suitable output format for 'simple.mp3' 
simple.mp3: Invalid argument

你知道我还应该在这个静态文件中包含什么吗?

最佳答案

无需逐步禁用某些内容:只需使用 --disable-everything 然后启用您需要的内容。

您可以从以下示例开始:

./configure
--disable-everything
--disable-network
--disable-autodetect
--enable-small
--enable-decoder=aac*,ac3*,opus,vorbis
--enable-demuxer=mov,m4v,matroska
--enable-muxer=mp3,mp4
--enable-protocol=file
--enable-libshine
--enable-encoder=libshine
--enable-filter=aresample
  • 最终二进制文件大小约为 2-3 MB。
  • 无需启用任何解析器:所选解码器将自动选择所需的解码器。
  • FFmpeg 没有原生 MP3 编码器,因此您需要使用外部库,例如 libmp3lame 或 libshine。既然您提到了 Android,我假设您需要 libshine 而不是 libmp3lame 来编码 MP3。
  • 彻底测试。我可能忘记了什么。
  • 如果您真的想发疯,请使用 --disable-all 而不是 --disable-everything 并且您还必须手动包含 FFmpeg 库您想要的,但这是更多的工作和更多的头痛,而且返回不多。

这将允许您从大多数 M4A 和 Webm 输入编码 MP3 音频:

ffmpeg -i input.webm output.mp3

并且还可以让您将 MP4/M4V + M4A 重新混合到 MP4 中:

ffmpeg -i video.m4v -i audio.m4a -map 0:v -map 0:a -c copy output.mp4

关于ffmpeg - 如何编译 ffmpeg 以仅获得 mp3 和 mp4 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54750953/

相关文章:

python - python中关于ffmpeg的错误

javascript - 为什么我已经安装了错误查找模块

ffmpeg - 使用 avformat 的分段 mp4 广播

compilation - 如何动态链接你的 nim 应用程序和 musl?

ios - 在 Xcode 10 上出现错误 : "Swift does not support the SDK ' iPhoneSimulator11. 2.sdk'"

audio - FFMPEG:我可以将音频设置为仅在晚上播放吗?

ffmpeg - 编译 FFMPEG 时找不到静态 x265

compiler-construction - 实现 8051 的函数调用

python - 在运行脚本之前查找未初始化的变量

c++ - 什么是函数客户端?