reduce binary size for embedded devices

Added by Robert N 8 months ago

Hey guys,

I'm using tvheadend 4.1 on some linksys routers running openwrt.
Up to v4.1 I was able to reduce the size of the binary to ~2M removing the docs/docresources from BUNDLE and the ext-all-debug.js.

in v4.3 the docs/docresources is not in BUNDLE anymore, but the resulting binary take up ~8M.

Is there anything I could remove, like debug info or so, to reduce size without affecting tvh functionality?

thanks in advance.

cheers,
Robert


Replies (15)

RE: reduce binary size for embedded devices - Added by saen acro 8 months ago

What are you removed for now?
dvb-scan tables can be removed.
Themes can be removed also.

RE: reduce binary size for embedded devices - Added by Robert N 8 months ago

dvb-scan is already disabled.

how would I be able to remove themes?

RE: reduce binary size for embedded devices - Added by Em Smith 7 months ago

Unfortunately size vary depending on platform. If you have "ncdu", it is a console program that shows disk usage per directory and allows you to navigate so you can see where the space is used.

If you:

./configure | grep disable

And see how many options you can use. Maybe you don't need satip server? Or imagecache? If you're really low on space, perhaps you could delete all the png and gif files? It will make the (webserver) UI ugly but maybe you can just use tvh4kodi to configure tvheadend.

I'd probably also delete all the intl files other than probably en_US and it would probably still work.

The compiler flag "-Os" optimizes the binary for size (instead of speed). You can probably pass it with the "--cflags=-Os" (after doing a make clean).

RE: reduce binary size for embedded devices - Added by Robert N 7 months ago

Hey Em,

thanks for the tipps. I've actually removed src/webui/static/img/doc which saves like ~3Mb and realised that the binary segfaults on the target, so added back to see if it works, but unfortunately still segfaults. I'll open another thread for the segfault.

RE: reduce binary size for embedded devices - Added by saen acro 7 months ago

Disabling all EPG and Transcoding connected modules, will save maximum space.

./configure $(CONFIGURE_SILENT) \
            --build=$(build) \
            --host=$(target) \
            --disable-hdhomerun_static \
            --disable-avahi \
            --disable-tvhcsa \
            --disable-libav \
            --disable-ffmpeg_static \
            --disable-libx264 \
            --disable-libx264-static \
            --disable-libx265 \
            --disable-libx265-static \
            --disable-libx264 \
            --disable-libx264-static \
            --disable-libvpx \
            --disable-libvpx-static \
            --disable-libtheora \
            --disable-libtheora-static \
            --disable-libvorbis \
            --disable-libvorbis-static \
            --disable-libfdkaac \
            --disable-libfdkaac-static \
            --disable-uriparser \
            --disable-dvben50221 \
            --disable-dbus_1 \

RE: reduce binary size for embedded devices - Added by saen acro 7 months ago

Internationalization, Timeshift, SATIP Server/Client, Bonjour, linuxdvb git tree (useless and outdated in general)
see more in https://github.com/tvheadend/tvheadend/blob/master/Makefile

RE: reduce binary size for embedded devices - Added by kun xiang 7 months ago

Hi,Robert.Did you compile successfully? How many M? And Could you share the 4.3 version of ar71xx platform, thank you.

RE: reduce binary size for embedded devices - Added by Robert N 7 months ago

with following flags and patch, I'm down to ~4MB

- I couldn't find what tvhcsa is.
- I understood dvben50221 is required for ca. I have a tuner with ci slot and may try to get it working..., not sure if it's possible.
- I assume I need uriparser, because I'm using over http, not htsp.
- not sure how to disable bonjour
- isn't linuxdvb required if you run tvheadend on linux?

        --disable-dvbscan \
        --disable-avahi \
        --disable-dbus_1 \
        --disable-libav \
        --enable-bundle \
        --disable-hdhomerun_static \
        --disable-pie \
        --disable-satip_server \
        --disable-satip_client \
        --disable-imagecache \
        --disable-libav \
        --disable-ffmpeg_static \
        --disable-libx264 \
        --disable-libx264_static \
        --disable-libx265 \
        --disable-libx265_static \
        --disable-libvpx \
        --disable-libvpx_static \
        --disable-libtheora \
        --disable-libtheora_static \
        --disable-libvorbis \
        --disable-libvorbis_static \
        --disable-libfdkaac \
        --disable-libfdkaac_static \
        --disable-nvenc \
        --disable-libmfx_static \
        --disable-timeshift
 make LANGUAGES='de en_US hu ro'
Index: tvheadend/Makefile
===================================================================
--- tvheadend.orig/Makefile
+++ tvheadend/Makefile
@@ -739,6 +739,7 @@ $(BUILDDIR)/bundle.o: $(BUILDDIR)/bundle
        $(pCC) -I${ROOTDIR}/src -c -o [email protected] $<

 $(BUILDDIR)/bundle.c: check_dvb_scan make_webui
+       find src/webui/static/img/doc/ -delete
        @mkdir -p $(dir [email protected])
        $(pMKBUNDLE) -o [email protected] -d ${BUILDDIR}/bundle.d $(BUNDLE_FLAGS) $(BUNDLES:%=$(ROOTDIR)/%)

openwrt build environment automatically adds -Os to cflags.

PS. ncdu is a great tool, thanks for the tipp.

RE: reduce binary size for embedded devices - Added by Robert N 6 months ago

back again. figured that tvh compiled with the above configure args segfaults on lede ( openwrt ) compiled with musl but works on lede compiled with glibc. tried different options and seems that the --enable-bundle causes the segfault. any clues what could be the problem? tried to gdb it but it doesn't get to main, so don't see anything, or a workaround maybe?

RE: reduce binary size for embedded devices - Added by Robert Cameron 6 months ago

Robert N wrote:

back again. figured that tvh compiled with the above configure args segfaults on lede ( openwrt ) compiled with musl but works on lede compiled with glibc. tried different options and seems that the --enable-bundle causes the segfault. any clues what could be the problem? tried to gdb it but it doesn't get to main, so don't see anything, or a workaround maybe?

Musl has no internationalization/locale support. Everything that may be exposed is simply not there or just a stub; I imagine that building for multiple languages is exposing this limitation in musl and may be the root of your problem.

RE: reduce binary size for embedded devices - Added by Robert N 6 months ago

thanks for the quick reply. did this change from 4.1 to 4.2? because 4.1 is working fine. only 4.2 and 4.3 are segfaulting...

1. as far as I can see from configure, it finds libiconv.
I tried to compile for only en_US passing LANGUAGES=en_US to make. apparently the bundle.d contains only one lang:

src/webui/static/intl/tvh.en_US.js.gz\

not sure though if this confirms that int is not the cause of the segfault.

2. on the other hand I see the liburiparser is not found, could that be the problem?

here's the output of configure:

Checking support/features
  checking for cc execinfo.h ...                    fail
  checking for cc -mmmx ...                         fail
  checking for cc -msse2 ...                        fail
  checking for cc -Wunused-result ...               ok
  checking for cc getloadavg ...                    ok
  checking for cc atomic32 ...                      ok
  checking for cc atomic64 ...                      ok
  checking for cc atomic_time_t ...                 ok
  checking for cc bitops64 ...                      ok
  checking for cc lockowner ...                     fail
  checking for cc qsort_r ...                       fail
  checking for cc stime ...                         ok
  checking for cc gmtoff ...                        ok
  checking for cc recvmmsg ...                      ok
  checking for cc sendmmsg ...                      ok
  checking for cc libiconv ...                      ok
    ^ using external iconv library
  checking for cc libdvben50221 ...                 ok
  checking for cc ifnames ...                       ok
  checking for py module gzip ...                   ok
  checking for /opt/lede/staging_dir/host/bin/pkg-config ...ok
  checking for xgettext ...                         ok
  checking for msgmerge ...                         ok
  checking for gzip ...                             ok
  checking for bzip2 ...                            ok
  checking for pkg openssl  ...                     ok (detected 1.0.2k)
  checking for cc linux/dvb/version.h ...           ok
  checking for pkg zlib  ...                        ok (detected 1.2.11)
  checking for pkg liburiparser  ...                fail (detected <none>)
  checking for cc sys/inotify.h ...                 ok
  checking for cc inotify_init1 ...                 ok
  checking for cc epoll_create1 ...                 ok

RE: reduce binary size for embedded devices - Added by Robert N 6 months ago

I just tried to ldd the binary, but it doesn't seem to be linked against libiconv:

# ldd /usr/bin/tvheadend 
    /lib/ld-musl-armhf.so.1 (0x7f5f3000)
    libdvben50221.so => /usr/lib/libdvben50221.so (0xb6b43000)
    libdvbapi.so => /usr/lib/libdvbapi.so (0xb6b30000)
    libucsi.so => /usr/lib/libucsi.so (0xb6b0c000)
    libssl.so.1.0.0 => /usr/lib/libssl.so.1.0.0 (0xb6ab8000)
    libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0xb6983000)
    libz.so.1 => /usr/lib/libz.so.1 (0xb6961000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb6947000)
    libc.so => /lib/ld-musl-armhf.so.1 (0x7f5f3000)

and seems to be the same with v4.1 ( which works fine ).

RE: reduce binary size for embedded devices - Added by Robert N 6 months ago

just learned that lede ( openwrt ) links by default libiconv-stub, that satisfies the requirements of the iconv api but does not actually add any code or runtime deps!
to have a fully-featured libiconv, have to link against libiconv-full library. recompiled accordingly, now the binary is linked against libiconv, but still segfaults :(,

# ldd /usr/bin/tvheadend 
    /lib/ld-musl-armhf.so.1 (0x7f64a000)
    libdvben50221.so => /usr/lib/libdvben50221.so (0xb6c01000)
    libdvbapi.so => /usr/lib/libdvbapi.so (0xb6bee000)
    libucsi.so => /usr/lib/libucsi.so (0xb6bca000)
    libssl.so.1.0.0 => /usr/lib/libssl.so.1.0.0 (0xb6b76000)
    libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0xb6a41000)
    libz.so.1 => /usr/lib/libz.so.1 (0xb6a1f000)
    libiconv.so.2 => /usr/lib/libiconv.so.2 (0xb6a09000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb69ef000)
    libc.so => /lib/ld-musl-armhf.so.1 (0x7f64a000)
# ldd /usr/lib/libiconv.so
    ldd (0x7f596000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb6f28000)
    libc.so => ldd (0x7f596000)

RE: reduce binary size for embedded devices - Added by Robert N 6 months ago

thanks to a very dedicated musl maintainer, here's the solution:
https://tvheadend.org/issues/4870

RE: reduce binary size for embedded devices - Added by erotavlas erotavlas 1 day ago

Hi,
this is an useful thread. I'm looking for to install tvheadend 4.3 on openWRT. Did you manage to have a working package?
Thank you

(1-15/15)