当 --sysroot 指向另一个目录时,如何让 FFmpeg 找到已安装的库?

发布于 2025-01-01 13:54:45 字数 3017 浏览 1 评论 0原文

我已经研究这个问题好几天了。我正在尝试使用 libmp3lame 构建 FFmpeg 以在 Android 应用程序中使用。构建脚本设置一个 --sysroot 标志,该标志指向以 Android 可以使用它们的方式构建这些库所需的 Android NDK 目录。

当我将标志添加到 --enable-libmp3lame 时,问题就出现了;在构建启动期间,我收到 ERROR: libmp3lame >= 3.98.3 not found 。我知道 LAME 及其库已安装,因为我可以手动运行 ./configure --enable-libmp3lame 并且配置会顺利启动,并显示为此构建启用了 libmp3lame。然而,这样的构建根本无法满足我的需要,因为我需要 Android NDK 来完成一些工作。

我已经将问题归结为这个构建脚本声明了 sysroot,并且通过一些研究,我尝试添加 -Luser/include-L/user/include到额外的 cflags 和 ldflags (我读过的是 gcc 的默认搜索位置)。我还尝试了其他一些方法,但我相信这里有人可以帮助解决这个特定问题。整个构建脚本如下:

额外信息:

  • 构建操作系统:Ubuntu 11.10
  • FFmpeg Ver:来自 git
  • LAME 的最新版本:3.9.x
  • Android NDK:r7

build.sh

#!/bin/bash

if [ "$NDK" = "" ]; then
    echo NDK variable not set, assuming ${HOME}/android-ndk
    export NDK=${HOME}/android-ndk
fi

SYSROOT=$NDK/platforms/android-3/arch-arm
# Expand the prebuilt/* path into the correct one
TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86`
export PATH=$TOOLCHAIN/bin:$PATH

rm -rf build/ffmpeg
mkdir -p build/ffmpeg
cd ffmpeg

# Don't build any neon version for now
for version in armv5te armv7a; do

        DEST=../build/ffmpeg
        FLAGS="--target-os=linux --cross-prefix=arm-linux-androideabi- --arch=arm"
        FLAGS="$FLAGS --sysroot=$SYSROOT"
        FLAGS="$FLAGS --soname-prefix=/data/data/net.smartnotes/lib/"
        FLAGS="$FLAGS --enable-shared --disable-symver"
        FLAGS="$FLAGS --enable-small --optimization-flags=-O2"
        FLAGS="$FLAGS --disable-everything --enable-protocol=file"
        FLAGS="$FLAGS --enable-libmp3lame --enable-encoder=nellymoser"

        case "$version" in
                neon)
                    EXTRA_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon"
                    EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
                    # Runtime choosing neon vs non-neon requires
                    # renamed files
                    ABI="armeabi-v7a"
                    ;;
                armv7a)
                    # I have tried many things here.
                    EXTRA_CFLAGS="-march=armv7-a -mfloat-abi=softfp"
                    EXTRA_LDFLAGS=""
                    ABI="armeabi-v7a"
                    ;;
                *)
                    # I have tried many things here.
                    EXTRA_CFLAGS="-Luser/include"
                    EXTRA_LDFLAGS=""
                    ABI="armeabi"
                    ;;
        esac
        DEST="$DEST/$ABI"
        FLAGS="$FLAGS --prefix=$DEST"

        mkdir -p $DEST
        echo $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" > $DEST/info.txt
        ./configure $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" | tee $DEST/configuration.txt
        [ $PIPESTATUS == 0 ] || exit 1
        make clean
        make -j4 || exit 1
        make install || exit 1

done

I've been going at this, literally for days. I'm trying to build FFmpeg with libmp3lame for use in an Android application. The build script sets a --sysroot flag that points to the Android NDK directory necessary to build these libraries in a way that Android can use them.

The problem comes when I add the flag to --enable-libmp3lame; I get ERROR: libmp3lame >= 3.98.3 not found during the build start up. I know that LAME, and it's libraries are installed, because I can just run ./configure --enable-libmp3lame manually and the configuration launches without a hitch, and shows that libmp3lame is enabled for this build. However, building like this will simply not work for what I need it for, since I need the Android NDK to do some work.

I've tracked the problem down to the fact that this build script is declaring the sysroot, and through some research, I've tried adding -Luser/include, -L/user/includeto the extra cflags, and ldflags (which I've read is the default search location for gcc). I've tried several other things as well, but I'm confident that someone out here can help with this specific problem. This entire build script is as follows:

Extra info:

  • Build OS: Ubuntu 11.10
  • FFmpeg Ver: Latest from git
  • LAME Ver: 3.9.x
  • Android NDK: r7

build.sh

#!/bin/bash

if [ "$NDK" = "" ]; then
    echo NDK variable not set, assuming ${HOME}/android-ndk
    export NDK=${HOME}/android-ndk
fi

SYSROOT=$NDK/platforms/android-3/arch-arm
# Expand the prebuilt/* path into the correct one
TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86`
export PATH=$TOOLCHAIN/bin:$PATH

rm -rf build/ffmpeg
mkdir -p build/ffmpeg
cd ffmpeg

# Don't build any neon version for now
for version in armv5te armv7a; do

        DEST=../build/ffmpeg
        FLAGS="--target-os=linux --cross-prefix=arm-linux-androideabi- --arch=arm"
        FLAGS="$FLAGS --sysroot=$SYSROOT"
        FLAGS="$FLAGS --soname-prefix=/data/data/net.smartnotes/lib/"
        FLAGS="$FLAGS --enable-shared --disable-symver"
        FLAGS="$FLAGS --enable-small --optimization-flags=-O2"
        FLAGS="$FLAGS --disable-everything --enable-protocol=file"
        FLAGS="$FLAGS --enable-libmp3lame --enable-encoder=nellymoser"

        case "$version" in
                neon)
                    EXTRA_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon"
                    EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
                    # Runtime choosing neon vs non-neon requires
                    # renamed files
                    ABI="armeabi-v7a"
                    ;;
                armv7a)
                    # I have tried many things here.
                    EXTRA_CFLAGS="-march=armv7-a -mfloat-abi=softfp"
                    EXTRA_LDFLAGS=""
                    ABI="armeabi-v7a"
                    ;;
                *)
                    # I have tried many things here.
                    EXTRA_CFLAGS="-Luser/include"
                    EXTRA_LDFLAGS=""
                    ABI="armeabi"
                    ;;
        esac
        DEST="$DEST/$ABI"
        FLAGS="$FLAGS --prefix=$DEST"

        mkdir -p $DEST
        echo $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" > $DEST/info.txt
        ./configure $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" | tee $DEST/configuration.txt
        [ $PIPESTATUS == 0 ] || exit 1
        make clean
        make -j4 || exit 1
        make install || exit 1

done

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心奴独伤 2025-01-08 13:54:45

与其更改包含路径,不如尝试将“make install”创建的所有 libmp3lame 文件复制到脚本将查找它们的相关目录。插入 ECHO 语句以找出出现错误时的 PATH/CFLAGS/LDFLAGS 到底是什么,然后将文件复制到那里,以便它找到它们。

Instead of changing the include paths, why don't you try copying all the libmp3lame files that were created by 'make install' to the relevant directory where the script will look for them. Insert ECHO statements to find out what exactly the PATH/CFLAGS/LDFLAGS are at the point where you get the error, and copy the files there so it does find them.

我们只是彼此的过ke 2025-01-08 13:54:45

我看到你正在使用位于
http://bambuser.com/opensource

我遇到了同样的问题并像这样解决:

  1. 使用<编译lame for android a href="https://github.com/intervigilium/liblame" rel="nofollow">https://github.com/intervigilium/liblame
  2. 这是一个小的差异 原来之间来自“bambuser.com”的 build.sh 和我使用的:

    <前><代码>3c3,6
    <导出 NDK=${HOME}/downloads/android-ndk # r8d
    ---
    >如果[“$NDK”=“”];然后
    > echo NDK 变量未设置,假设 ${HOME}/android-ndk
    >导出 NDK=${HOME}/android-ndk
    >菲
    15,16c18
    < #适用于armv5te armv7a版本;做
    <对于armv7a版本;做
    ---
    >对于armv5te armv7a版本;做
    24c26
    < FLAGS =“$ FLAGS --disable-everything --enable-libmp3lame”
    ---
    > FLAGS="$FLAGS --禁用一切"

  3. 来自“ intervigilium”项目将文件夹 liblame/jni/lame

  4. 从“intervigilium”项目复制 liblame/libs/armeabi- v7a/liblame.so 到 PATH_TO_NDK/platforms/android-3/arch-arm/usr/libs重命名 libmp3lame.so
  5. 最后运行build.sh
  6. 你应该没问题:

    安装前缀../build/ffmpeg/armeabi-v7a
    源路径 /home/samuele/downloads/ffmpeg/ffmpeg-android/ffmpeg
    C编译器arm-linux-androideabi-gcc
    ARCH 臂(通用)
    大尾数 否
    运行时cpu检测否
    启用 ARMv5TE 是
    启用 ARMv6 是
    启用 ARMv6T2 是
    ARM VFP 启用 是
    IWMMXT 启用 否
    NEON 启用 否
    调试符号 是
    剥离符号 是
    优化小
    静态 是
    共享 是的
    后处理支持 否
    新过滤器支持 是
    网络支持 是
    线程支持 pthreads
    SDL 支持 否
    Sun medialib 支持 否
    AVISynth 已启用 否
    frei0r 启用 否
    libdc1394 支持 否
    libdirac 启用 否
    libfaac 启用 否
    libgsm 启用 否
    **libmp3lame 启用是**
    libnut 启用 否
    libopencore-amrnb 支持 否
    libopencore-amrwb 支持 否
    libopencv 支持 否
    libopenjpeg 启用 否
    librtmp 启用 否
    libschroedinger 启用 否
    libspeex 启用 否
    libtheora 启用 否
    libvorbis 启用 否
    libvpx 已启用 否
    libx264 启用 否
    libxavs 启用 否
    libxvid 启用 否
    zlib 启用 否
    bzlib 启用 否
    
    启用的解码器:
    
    启用的编码器:
    mpeg2video 内利莫瑟
    
    启用 hwaccels:
    
    启用解析器:
    
    启用的解复用器:
    
    启用的复用器:
    
    启用的协议:
    
    启用过滤器:
    缓冲
    
    启用bsfs:
    
    启用的 indevs:
    
    启用 outdevs:
    
    许可证:LGPL 2.1 版或更高版本
    创建 config.mak 和 config.h...
    libavutil/avconfig.h 未更改
    

请注意,我仍然需要测试生成的 FFmpeg 版本。
说实话,现在我必须学习如何在我的应用程序中使用它......;)

编辑:我尝试删除 --disable-everything 并且构建正常同样,有很多编码器、解码器等,但 build 目录增加到约 40MB。

I saw you were using the project located at
http://bambuser.com/opensource

I had the same problem and resolved like this:

  1. compile lame for android using https://github.com/intervigilium/liblame
  2. this is a small diff between the original build.sh from "bambuser.com" and the one I used:

    3c3,6
    <  export NDK=${HOME}/downloads/android-ndk # r8d
    ---
    > if [ "$NDK" = "" ]; then
    >     echo NDK variable not set, assuming ${HOME}/android-ndk
    >     export NDK=${HOME}/android-ndk
    > fi
    15,16c18
    < #for version in armv5te armv7a; do
    <  for version in         armv7a; do
    ---
    > for version in armv5te armv7a; do
    24c26
    <     FLAGS="$FLAGS --disable-everything --enable-libmp3lame"
    ---
    >     FLAGS="$FLAGS --disable-everything"
    
  3. from "intervigilium" project copy the folder liblame/jni/lame to PATH_TO_NDK/platforms/android-3/arch-arm/usr/include

  4. from "intervigilium" project copy liblame/libs/armeabi-v7a/liblame.so to PATH_TO_NDK/platforms/android-3/arch-arm/usr/libs and RENAME it in libmp3lame.so.
  5. finally run build.sh.
  6. you should be fine:

    install prefix            ../build/ffmpeg/armeabi-v7a
    source path               /home/samuele/downloads/ffmpeg/ffmpeg-android/ffmpeg
    C compiler                arm-linux-androideabi-gcc
    ARCH                      arm (generic)
    big-endian                no
    runtime cpu detection     no
    ARMv5TE enabled           yes
    ARMv6 enabled             yes
    ARMv6T2 enabled           yes
    ARM VFP enabled           yes
    IWMMXT enabled            no
    NEON enabled              no
    debug symbols             yes
    strip symbols             yes
    optimizations             small
    static                    yes
    shared                    yes
    postprocessing support    no
    new filter support        yes
    network support           yes
    threading support         pthreads
    SDL support               no
    Sun medialib support      no
    AVISynth enabled          no
    frei0r enabled            no
    libdc1394 support         no
    libdirac enabled          no
    libfaac enabled           no
    libgsm enabled            no
    **libmp3lame enabled        yes**
    libnut enabled            no
    libopencore-amrnb support no
    libopencore-amrwb support no
    libopencv support         no
    libopenjpeg enabled       no
    librtmp enabled           no
    libschroedinger enabled   no
    libspeex enabled          no
    libtheora enabled         no
    libvorbis enabled         no
    libvpx enabled            no
    libx264 enabled           no
    libxavs enabled           no
    libxvid enabled           no
    zlib enabled              no
    bzlib enabled             no
    
    Enabled decoders:
    
    Enabled encoders:
    mpeg2video      nellymoser
    
    Enabled hwaccels:
    
    Enabled parsers:
    
    Enabled demuxers:
    
    Enabled muxers:
    
    Enabled protocols:
    
    Enabled filters:
    buffer
    
    Enabled bsfs:
    
    Enabled indevs:
    
    Enabled outdevs:
    
    License: LGPL version 2.1 or later
    Creating config.mak and config.h...
    libavutil/avconfig.h is unchanged
    

Be aware, I still need to test the resulting FFmpeg build.
To say the truth, now I have to learn how to use it in my App... ;)

EDIT: I tried removing --disable-everything and it builds OK the same, with a lot of encoders, decoders etc, but increasing to ~40MB for the build dir.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文