Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce compiled ffmpeg library size based on what I need

I finally managed to build ffmpeg as detailed in here: https://enoent.fr/blog/2014/06/20/compile-ffmpeg-for-android/ and in the end, I have a ffmpeg library which accepts command arguments.

I am ONLY applying a watermark image over the video so for it I am using this ffmpeg command:

ffmpeg -i input.avi -i logo.png -filter_complex 'overlay=10:main_h-overlay_h-10' output.avi

Basic config:

  ./configure \
    --prefix=$PREFIX \
    --disable-shared \
    --enable-static \
    --disable-doc \
    --disable-ffmpeg \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-ffserver \
    --disable-doc \
    --disable-symver \
    --enable-protocol=concat \
    --enable-protocol=file \
    --enable-muxer=mp4 \
    --enable-demuxer=mpegts \
    --enable-memalign-hack \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --target-os=linux \
    --arch=arm \
    --enable-cross-compile \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic -marm $ADDI_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS"

No other commands needed from ffmpeg.

When compiling ffmpeg I get these files:

enter image description here

I want to reduce the size of the library to as small as possible, so given the above command, are there any files that I can remove from final build ?

ALSO which is the most common CPU found in current devices ? arm v7vfpv3, arm v7vfp, arm v7n ? I want to cover as many devices as possible.

#arm v6
#CPU=armv6
#OPTIMIZE_CFLAGS="-marm -march=$CPU"
#PREFIX=./android/$CPU 
#ADDITIONAL_CONFIGURE_FLAG=
#build_one

#arm v7vfpv3
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
PREFIX=./android/$CPU
ADDITIONAL_CONFIGURE_FLAG=
build_one

#arm v7vfp
#CPU=armv7-a
#OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
#PREFIX=./android/$CPU-vfp
#ADDITIONAL_CONFIGURE_FLAG=
#build_one

#arm v7n
#CPU=armv7-a
#OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"
#PREFIX=./android/$CPU 
#ADDITIONAL_CONFIGURE_FLAG=--enable-neon
#build_one

#arm v6+vfp
#CPU=armv6
#OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
#PREFIX=./android/${CPU}_vfp 
#ADDITIONAL_CONFIGURE_FLAG=
#build_one
like image 386
Alin Avatar asked Sep 18 '14 19:09

Alin


People also ask

How to compress large videos with ffmpeg?

You can’t directly reduce the video size through FFmpeg, but you should change the video format, resolution, and bitrate to compress large videos with FFmpeg. Because this software is very complicated and troublesome from the installation to the use, the detailed steps of the whole process are introduced below:

How to get the duration of a FFmpeg output file?

2) Use the -fs parameter and let ffmpeg figure it out. Show activity on this post. The fs parameter will stop the encode once it hits its value. So, if the output hits the 10MB mark while encoding the 15th second, then that's the duration of your output file.

How is pixel size calculated in FFmpeg?

See the ffmpeg docs on scaling for more info. In these examples, the size is divided by twice the value and multiplied by two to ensure the pixel size is a multiple of two, which is required for some codecs including H265.

How to compress videos in large sizes?

When you want to compress videos in large sizes, you will find many people recommend you to compress videos through FFmpeg. It provides a complete and cross-platform solution to record, compress, convert, and stream audio and video files.


1 Answers

You could use link-time optimization (LTO) if your compiler supports it. I have had very good results with GCC and LTO optimizing out stuff that is never called. I would start with what LordNeckbeard suggest and configure only the sections you need and then use LTO with your static linking.

Other options to reduce code size include things like the size optimization (-Os) that most compilers support in one form or another. You can also strip unneeded symbols using something like strip --strip-all ./your_binary.

If all of that isn't enough to get you to your target size, look into executable packers like UPX. These programs will make a cpu/memory trade-off to decompress binary files on the fly. On some architectures this can be a significant space saver.

like image 157
Alex Barker Avatar answered Oct 27 '22 13:10

Alex Barker