Skip to content

Instantly share code, notes, and snippets.

@KivApple
Last active September 28, 2023 15:19
Show Gist options
  • Select an option

  • Save KivApple/a29bf5d49cbbbedef1aacb3e14b850f2 to your computer and use it in GitHub Desktop.

Select an option

Save KivApple/a29bf5d49cbbbedef1aacb3e14b850f2 to your computer and use it in GitHub Desktop.

Revisions

  1. KivApple revised this gist Dec 12, 2018. 1 changed file with 29 additions and 46 deletions.
    75 changes: 29 additions & 46 deletions openh264-android-build.sh
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,16 @@
    #!/bin/sh
    export NDK=~/Apps/AndroidSDK/ndk-bundle # Change me
    export JNILIBS_DIR=../../app/src/main/jniLibs # Change me
    export INCLUDE_DIR=../../app/src/main/cpp/libopenh264 # Change me
    export DOWNLOAD_URL=https://github.com/cisco/openh264/archive/master.zip

    mkdir -p tmp
    ln -sf $NDK/prebuilt/linux-x86_64/bin/yasm tmp/nasm
    export PATH=$(pwd)/tmp:$PATH

    if [ ! -f src.zip ]; then
    curl -L $DOWNLOAD_URL --output src.zip || exit 1
    fi
    unzip src.zip || exit 1
    rm -rf src
    mv openh264-master src

    patch --forward src/build/platform-linux.mk << 'EOF'
    --- ../../../openh264/build/platform-linux.mk 2018-11-29 05:16:39.000000000 +0400
    +++ src/build/platform-linux.mk 2018-12-10 23:35:07.307475814 +0400
    @@ -4,8 +4,8 @@
    SHAREDLIBSUFFIXMAJORVER=$(SHAREDLIBSUFFIX).$(SHAREDLIB_MAJORVERSION)
    SHLDFLAGS = -Wl,-soname,$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXMAJORVER)
    CFLAGS += -Wall -fno-strict-aliasing -fPIC -MMD -MP
    -LDFLAGS += -lpthread
    -STATIC_LDFLAGS += -lpthread -lm
    +LDFLAGS +=
    +STATIC_LDFLAGS += -lm
    AR_OPTS = crD $@
    ifeq ($(ASM_ARCH), x86)
    ifeq ($(ARCH), x86_64)
    EOF

    declare -A arch_eabis=(
    ["arm"]="arm-linux-androideabi"
    ["arm64"]="aarch64-linux-android"
    ["x86"]="i686-linux-android"
    ["x86_64"]="x86_64-linux-android"
    )

    declare -A arch_abis=(
    ["arm"]="armeabi-v7a"
    @@ -39,26 +19,29 @@ declare -A arch_abis=(
    ["x86_64"]="x86_64"
    )

    declare -A ndk_levels=(
    ["arm"]="16"
    ["arm64"]="21"
    ["x86"]="16"
    ["x86_64"]="21"
    )

    for arch in arm arm64 x86 x86_64; do
    target_host=${arch_eabis[$arch]}
    echo "Building for $arch ($target_host)"
    $NDK/build/tools/make_standalone_toolchain.py --arch $arch --api 28 --install-dir toolchain/$arch
    ln -sf `pwd`/toolchain/$arch/bin/yasm toolchain/$arch/bin/nasm
    export OLD_PATH=$PATH
    export PATH=`pwd`/toolchain/$arch/bin:$PATH
    export AR=$target_host-ar
    export AS=$target_host-clang
    export CC=$target_host-clang
    export CXX=$target_host-clang++
    export LD=$target_host-ld
    export STRIP=$target_host-strip
    export ASM=yasm
    make ARCH=$arch -C src clean libraries || exit 1
    export PATH=$OLD_PATH
    mkdir -p output/${arch_abis[${arch}]}
    cp -v src/libopenh264.{a,so} output/${arch_abis[${arch}]} || exit 1
    patchelf --set-soname libopenh264.so output/${arch_abis[${arch}]}/libopenh264.so || exit 1
    echo "Building for $arch (${arch_abis[$arch]})"
    unzip src.zip || exit 1
    rm -rf src
    mv openh264-master src
    if [ "$arch" == "x86" ]; then
    export ASMFLAGS=-DX86_32_PICASM
    else
    export ASMFLAGS=
    fi
    make OS=android NDKROOT=$NDK TARGET=android-${ndk_levels[$arch]} NDKLEVEL=${ndk_levels[$arch]} ARCH=$arch -C src NDK_TOOLCHAIN_VERSION=clang libraries || exit 1
    mkdir -p "$JNILIBS_DIR/${arch_abis[$arch]}"
    cp -v src/libopenh264.{so,a} "$JNILIBS_DIR/${arch_abis[$arch]}"
    done

    mkdir -p output/include/wels
    cp -v src/codec/api/svc/*.h output/include/wels
    mkdir -p "$INCLUDE_DIR/wels"
    cp -v src/codec/api/svc/*.h "$INCLUDE_DIR/wels"

    rm -rf tmp src
  2. KivApple revised this gist Dec 10, 2018. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions openh264-android-build.sh
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,9 @@ export NDK=~/Apps/AndroidSDK/ndk-bundle # Change me
    export DOWNLOAD_URL=https://github.com/cisco/openh264/archive/master.zip

    if [ ! -f src.zip ]; then
    curl -L $DOWNLOAD_URL --output src.zip
    curl -L $DOWNLOAD_URL --output src.zip || exit 1
    fi
    unzip src.zip
    unzip src.zip || exit 1
    rm -rf src
    mv openh264-master src

    @@ -32,6 +32,13 @@ declare -A arch_eabis=(
    ["x86_64"]="x86_64-linux-android"
    )

    declare -A arch_abis=(
    ["arm"]="armeabi-v7a"
    ["arm64"]="arm64-v8a"
    ["x86"]="x86"
    ["x86_64"]="x86_64"
    )

    for arch in arm arm64 x86 x86_64; do
    target_host=${arch_eabis[$arch]}
    echo "Building for $arch ($target_host)"
    @@ -48,8 +55,9 @@ for arch in arm arm64 x86 x86_64; do
    export ASM=yasm
    make ARCH=$arch -C src clean libraries || exit 1
    export PATH=$OLD_PATH
    mkdir -p output/$arch
    cp -v src/libopenh264.{a,so} output/$arch
    mkdir -p output/${arch_abis[${arch}]}
    cp -v src/libopenh264.{a,so} output/${arch_abis[${arch}]} || exit 1
    patchelf --set-soname libopenh264.so output/${arch_abis[${arch}]}/libopenh264.so || exit 1
    done

    mkdir -p output/include/wels
  3. KivApple created this gist Dec 10, 2018.
    56 changes: 56 additions & 0 deletions openh264-android-build.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #!/bin/sh
    export NDK=~/Apps/AndroidSDK/ndk-bundle # Change me
    export DOWNLOAD_URL=https://github.com/cisco/openh264/archive/master.zip

    if [ ! -f src.zip ]; then
    curl -L $DOWNLOAD_URL --output src.zip
    fi
    unzip src.zip
    rm -rf src
    mv openh264-master src

    patch --forward src/build/platform-linux.mk << 'EOF'
    --- ../../../openh264/build/platform-linux.mk 2018-11-29 05:16:39.000000000 +0400
    +++ src/build/platform-linux.mk 2018-12-10 23:35:07.307475814 +0400
    @@ -4,8 +4,8 @@
    SHAREDLIBSUFFIXMAJORVER=$(SHAREDLIBSUFFIX).$(SHAREDLIB_MAJORVERSION)
    SHLDFLAGS = -Wl,-soname,$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXMAJORVER)
    CFLAGS += -Wall -fno-strict-aliasing -fPIC -MMD -MP
    -LDFLAGS += -lpthread
    -STATIC_LDFLAGS += -lpthread -lm
    +LDFLAGS +=
    +STATIC_LDFLAGS += -lm
    AR_OPTS = crD $@
    ifeq ($(ASM_ARCH), x86)
    ifeq ($(ARCH), x86_64)
    EOF

    declare -A arch_eabis=(
    ["arm"]="arm-linux-androideabi"
    ["arm64"]="aarch64-linux-android"
    ["x86"]="i686-linux-android"
    ["x86_64"]="x86_64-linux-android"
    )

    for arch in arm arm64 x86 x86_64; do
    target_host=${arch_eabis[$arch]}
    echo "Building for $arch ($target_host)"
    $NDK/build/tools/make_standalone_toolchain.py --arch $arch --api 28 --install-dir toolchain/$arch
    ln -sf `pwd`/toolchain/$arch/bin/yasm toolchain/$arch/bin/nasm
    export OLD_PATH=$PATH
    export PATH=`pwd`/toolchain/$arch/bin:$PATH
    export AR=$target_host-ar
    export AS=$target_host-clang
    export CC=$target_host-clang
    export CXX=$target_host-clang++
    export LD=$target_host-ld
    export STRIP=$target_host-strip
    export ASM=yasm
    make ARCH=$arch -C src clean libraries || exit 1
    export PATH=$OLD_PATH
    mkdir -p output/$arch
    cp -v src/libopenh264.{a,so} output/$arch
    done

    mkdir -p output/include/wels
    cp -v src/codec/api/svc/*.h output/include/wels