Search code examples
ffmpegandroid-ffmpeg

Best config for ffmpeg to convert MP3 file only


I want to compile FFMPEG to support conversion from MP3 to WAV and WAV to MP3.

as I only need that task, and output compiled size is really matter to me, Please correct me best compile config that accompilesh my requirement.

here is full config file:

function build_ffmpeg
{
    echo "Starting build ffmpeg for $ARCH"
    cd ffmpeg
    ./configure --target-os=linux \
        --prefix=$PREFIX \
        --enable-cross-compile \
        --extra-libs="-lgcc" \
        --arch=$ARCH \
        --cc=$CC \
        --cross-prefix=$CROSS_COMPILE \
        --nm=$NM \
        --sysroot=$PLATFORM \
        --extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums  -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS " \
        --disable-shared \
        --enable-static \
        --enable-runtime-cpudetect \
        --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -nostdlib -lc -lm -ldl -llog -L$PREFIX/lib" \
        --extra-cflags="-I$PREFIX/include" \
        --disable-everything \
        --enable-pthreads \
        --enable-libass \
        --enable-libvo-aacenc \
        --enable-libvo-amrwbenc \
        --enable-hwaccel=h264_vaapi \
        --enable-hwaccel=h264_vaapi \
        --enable-hwaccel=h264_dxva2 \
        --enable-hwaccel=mpeg4_vaapi \
        --enable-demuxer=mov \
        --enable-demuxer=h264 \
        --enable-demuxer=mpegvideo \
        --enable-demuxer=h263 \
        --enable-demuxer=mpegps \
        --enable-demuxer=mjpeg \
        --enable-demuxer=rtsp \
        --enable-demuxer=rtp \
        --enable-demuxer=hls \
        --enable-demuxer=matroska \
        --enable-muxer=rtsp \
        --enable-muxer=mp4 \
        --enable-muxer=mov \
        --enable-muxer=mjpeg \
        --enable-muxer=matroska \
        --enable-protocol=crypto \
        --enable-protocol=jni \
        --enable-protocol=file \
        --enable-encoder=libvo_amrwbenc \
        --enable-decoder=amrwb \
        --enable-muxer=mp2 \
        --enable-bsfs \
        --enable-decoders \
        --enable-encoders \
        --enable-parsers \
        --enable-hwaccels \
        --enable-muxers \
        --enable-avformat \
        --enable-avcodec \
        --enable-avresample \
        --enable-zlib \
        --disable-doc \
        --disable-ffplay \
        --disable-ffmpeg \
        --disable-ffplay \
        --disable-ffprobe \
        --disable-ffserver \
        --disable-avfilter \
        --disable-avdevice \
        --enable-nonfree \
        --enable-version3 \
        --enable-memalign-hack \
        --enable-asm \
        $ADDITIONAL_CONFIGURE_FLAG
    make clean
    make -j4 install
    make clean

    cd ..
    echo "FINISHED ffmpeg for $ARCH"
}

function build_one {
    echo "Starting build one for $ARCH"
    cd ffmpeg
    ${LD} -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -L$PREFIX/lib  -soname $SONAME -shared -nostdlib -Bsymbolic --whole-archive --no-undefined -o $OUT_LIBRARY -lavcodec -lavformat -lavresample -lavutil -lswresample -lass -lfreetype -lfribidi -lswscale -lvo-aacenc -lvo-amrwbenc -lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker -zmuldefs $PREBUILT/lib/gcc/$EABIARCH/$COMPILATOR_VERSION/libgcc.a
    cd ..
    echo "FINISHED one for $ARCH"
}

Solution

  • ./configure --disable-all --disable-autodetect --disable-network --enable-pthreads \
      --enable-avcodec --enable-avformat --enable-swresample --enable-avfilter \
      --enable-libmp3lame --enable-parser=mpegaudio --enable-demuxer=mp3,wav \
      --enable-muxer=mp3,wav --enable-decoder=pcm*,mp3* --enable-encoder=pcm*,libmp3lame \
      --enable-filter=aresample --enable-protocol=file --enable-ffmpeg --enable-small
    
    • Consider using libshine instead of libmp3lame is you need faster, but lower quality, MP3 encoding (especially on architectures without a FPU).

    • I usually don't recommend using --disable-all, but the size of the executable seems to be the most important factor for you. Using --disable-everything is easier to use because it does not disable the FFmpeg libraries, and is therefore less prone to forgotten components.

    • --disable-small optimizes for size instead of speed. It does make a size difference (1 MB vs 1.4 MB in this example), but I'm not sure how much of a speed difference it makes.

    • I did not include any additional options you may need for compiling for or on Android.

    • This may not work for MP3 inputs that contain album art because I did not enable any video options (specifically JPG and PNG related components). You may get by that by mapping just the audio with the -map option, such as with -map 0:a.