tanersener / mobile-ffmpeg

FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.
https://tanersener.github.io/mobile-ffmpeg
GNU General Public License v3.0
3.87k stars 791 forks source link

[Android] Custom configuration of ffmpeg to build minimal binary size aar #243

Closed StevenMichael3213 closed 5 years ago

StevenMichael3213 commented 5 years ago

Description Hello, Thanks for the great project. It helps me a lot, it can compile .wav file to .mp3 so fast on some supported -neon devices. But it binary size too big. So I want to modify the configuration of android-ffmpeg.sh after studied this project ( wiki + issues) ,then build a minimal binary size aar. I have successfully compiled an aar use below configuration, but the function failed to use. Could u help me to check the configure is right?

I need to execute 3 commands:

  1. convert a .m4a file to a .wav file -hide_banner -y -i input.m4a -ac 2 -ar 44100 -acodec pcm_s16le -f wav out.wav
  2. cut the .wav file -hide_banner -y -i input.wav -ss 20 -t 300 -acodec copy out.wav
  3. merge two .wav file -hide_banner -y -i input1.wav -i input2.wav -filter_complex [0:a]volume=0.3,adelay=1000|1000[a];[1:a]volume=0.7,adelay=1000|1000[b];[a] [b]amix=inputs=2:duration=shortest -c:a libmp3lame -qscale:a 2 -b:a 128k output.mp3

This is my ffmpeg configuration:

./configure \ --cross-prefix="${TARGET_HOST}-" \ --sysroot="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/sysroot" \ --prefix="${BASEDIR}/prebuilt/android-$(get_target_build)/${LIB_NAME}" \ --pkg-config="${HOST_PKG_CONFIG_PATH}" \ --disable-version3 \ --arch="${TARGET_ARCH}" \ --cpu="${TARGET_CPU}" \ --cc="${CC}" \ --cxx="${CXX}" \ --target-os=android \ ${ASM_FLAGS} \ --enable-cross-compile \ --enable-pic \ --enable-jni \ --enable-optimizations \ --enable-swscale \ --enable-shared \ --disable-v4l2-m2m \ --disable-outdev=v4l2 \ --disable-outdev=fbdev \ --disable-indev=v4l2 \ --disable-indev=fbdev \ --disable-openssl \ --disable-xmm-clobber-test \ ${DEBUG_OPTIONS} \ --disable-doc \ --disable-htmlpages \ --disable-manpages \ --disable-podpages \ --disable-txtpages \ --enable-ffmpeg \ --disable-ffprobe \ --disable-ffplay \ --disable-programs \ --disable-everything \ --disable-network \ --enable-avcodec \ --enable-avformat \ --enable-swresample \ --enable-avfilter \ --enable-libmp3lame \ --enable-parser=mpegaudio \ --enable-demuxer=mp3,aac,wav \ --enable-muxer=mp3,wav,aac \ --enable-decoder=aac,pcm,mp3 \ --enable-encoder=pcm,libmp3lame \ --enable-filter=aresample,anull \ --enable-protocol=file \ --disable-devices \ ${CONFIGURE_POSTFIX} 1>>${BASEDIR}/build.log 2>&1

Expected behavior I just want to --disable-some libs , --enable-some libs and filter ect, and only keep some functions involved .m4a .mp3 .wav volume adelay amix cut. Then get a minimum size of ffmpeg files to reduce the size of the final apk.

Current behavior Use the above configuration. I have successfully compiled an aar. I have imported it to my project. But when I excuted the first command -hide_banner -y -i input.m4a -ac 2 -ar 44100 -acodec pcm_s16le -f wav out.wav I see the error log from ffmepg:

Estimating duration from bitrate, this may be inaccurate [mp3 @ 0x7bbfe84200] Could not find codec parameters for stream 1 (Video: mjpeg, none): unspecified size Consider increasing the value for the 'analyzeduration' and 'probesize' options Input #0, mp3, from '/storage/emulated/0/abc/full.m4a': Metadata: title : XXX artist : XXX album : XXX genre : XXX date : 2018 Duration: 00:03:00.24, start: 0.000000, bitrate: 196 kb/s Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 192 kb/s Stream #0:1: Video: mjpeg, none, 90k tbr, 90k tbn, 90k tbc Metadata: comment : Other Stream mapping: Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) Press [q] to stop, [?] for help Output pad "default" with type audio of the filter instance "Parsed_anull_0" of anull not connected to any destination Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 Conversion failed!

Now could you please help me point out errors in my configuration?

Thanks in advance for the answer and help.

Environment

tanersener commented 5 years ago

According your logs, input.m4a file includes both audio and video. ffmpeg tries to decode stream 1 (video: mjpeg) as an mp3 stream and fails. Because it is mjpeg.

I think your configuration is fine and it will work without any issues on m4a audio files. But on files with video you need to enable video demuxers or find an option to skip demuxing of video streams.

StevenMichael3213 commented 5 years ago

Thank you for your replay sincerely.

After many attempts, I found that remove --disable-everything then respectively disable encoders disable decoders disable muxers etc then enable what I need from my configuration will achieve my goal.

This is my new configuration :

./configure \ --cross-prefix="${TARGET_HOST}-" \ --sysroot="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/sysroot" \ --prefix="${BASEDIR}/prebuilt/android-$(get_target_build)/${LIB_NAME}" \ --pkg-config="${HOST_PKG_CONFIG_PATH}" \ --arch="${TARGET_ARCH}" \ --cpu="${TARGET_CPU}" \ --cc="${CC}" \ --cxx="${CXX}" \ --target-os=android \ ${ASM_FLAGS} \ --enable-cross-compile \ --enable-pic \ --enable-jni \ --enable-optimizations \ --enable-swscale \ --enable-shared \ --disable-v4l2-m2m \ --disable-outdev=v4l2 \ --disable-outdev=fbdev \ --disable-indev=v4l2 \ --disable-indev=fbdev \ ${SIZE_OPTIONS} \ --disable-openssl \ --disable-xmm-clobber-test \ ${DEBUG_OPTIONS} \ --disable-neon-clobber-test \ --disable-programs \ --disable-postproc \ --disable-doc \ --disable-htmlpages \ --disable-manpages \ --disable-podpages \ --disable-txtpages \ --disable-static \ --disable-sndio \ --disable-schannel \ --disable-securetransport \ --disable-xlib \ --disable-cuda \ --disable-cuvid \ --disable-nvenc \ --disable-vaapi \ --disable-vdpau \ --disable-videotoolbox \ --disable-audiotoolbox \ --disable-appkit \ --disable-alsa \ --disable-cuda \ --disable-cuvid \ --disable-nvenc \ --disable-vaapi \ --disable-vdpau \ --disable-gray \ --disable-network \ --disable-postproc \ --disable-pixelutils \ --disable-encoders \ --disable-decoders \ --disable-muxers \ --disable-parsers \ --disable-bsfs \ --disable-protocols \ --disable-devices \ --disable-demuxers \ --enable-protocol=file \ --enable-encoder=wavpack,wav,pcm_s16le,pcm_u8,aac \ --enable-decoder=wavpack,wav,pcm_s16le,aac \ --enable-muxer=wav,pcm_u8,adts \ --enable-demuxer=wav,pcm_u8,aac,pcm_s16le,mov,mp3 \ --enable-parser=aac \ ${CONFIGURE_POSTFIX} 1>>${BASEDIR}/build.log 2>&1

lucazin commented 4 years ago

@StevenMichael3213 you can help me?

My apk is to big when i full full-gpl , i just need compress video that user record on my app.. Can you help me with this binary file?

thanks!