Linux下ffmpeg交叉编译

1 获取源代码

git clone -b "branch" https://git.ffmpeg.org/ffmpeg.git

“branch” 可以是以下的masterrelease/3.1等等,具体看需要使用哪个分支。

5 hours agomastershortlog | log | tree
4 days agorelease/3.1shortlog | log | tree
4 days agorelease/3.2shortlog | log | tree
4 days agorelease/3.3shortlog | log | tree
3 weeks agorelease/3.0shortlog | log | tree
2 months agorelease/2.8shortlog | log | tree
12 months agorelease/2.7shortlog | log | tree
12 months agorelease/2.6shortlog | log | tree
12 months agorelease/2.5shortlog | log | tree

2 Configure配置

在源码的目录下调用configure脚本,通过 -h 查看相应的帮助,这里写了一个简单的脚本build-ffmpeg.sh;

#!/bin/bash

PREFIX=out
TOOLCHAINS=/mnt/diska/X3399/source/buildroot/output/host/opt/ext-toolchain/bin
CROSS_COMPILE=${TOOLCHAINS}/aarch64-linux-gnu-
LOCAL_PATH=`pwd`
CFLAGS="-Wall -pipe -fpic \
   -finline-limit=300 -ffast-math \
   -fstrict-aliasing -Werror=strict-aliasing \
   -fmodulo-sched -fmodulo-sched-allow-regmoves \
   -Wno-psabi -Wa,--noexecstack"
EXTRA_CFLAGS=
EXTRA_LDFLAGS=
CPU_NAME=cortex-a72
FFMPEG_FLAGS="--prefix=${PREFIX} \
   --target-os=linux \
   --arch=arm \
   --cpu=$CPU_NAME \
   --enable-cross-compile \
   --cross-prefix=${CROSS_COMPILE} \
   --enable-shared \
   --disable-symver \
   --disable-doc \
   --disable-ffplay \
   --disable-ffmpeg \
   --disable-ffprobe \
   --disable-ffserver \
   --disable-avdevice \
   --disable-avfilter \
   --disable-muxers \
   --disable-filters \
   --disable-devices \
   --disable-everything \
   --enable-protocols  \
   --enable-parsers \
   --enable-demuxers \
   --disable-demuxer=sbg \
   --enable-decoders \
   --enable-bsfs \
   --enable-network \
   --enable-swscale  \
   --enable-neon \
   --enable-version3 \
   --disable-yasm \
   --disable-asm"

 #--enable-debug \
 #--disable-stripping \
 #--disable-optimizations \

 ./configure $FFMPEG_FLAGS --extra-cflags="$CFLAGS $EXTRA_CFLAGS" --extra-ldflags="$LDFLAGS $EXTRA_LDFLAGS"

 #make && make install

3 报错处理

如果在根目录下直接执行build-ffmpeg.sh脚本是无法成功安装ffmpeg的,首先这里会出现以下几个问题。

报错1:

错误内容:

{your path to toolchians}/aarch64-linux-gnu-gcc is unable to create an executable file. C compiler test failed.

解决方案:

  1. 打开configure文件;

  2. 搜索报错内容“C compiler test failed”,定位到以下内容,注释掉 die “C compiler test failed.” 或者修改 if 条件使得条件一直成立也是可以的。

    if test "$?" != 0; then
    echo "$cc is unable to create an executable file."
    if test -z "$cross_prefix" && ! enabled cross_compile ; then
        echo "If $cc is a cross-compiler, use the --enable-cross-compile option."
        echo "Only do this if you know what cross compiling means."
    fi
    
    #   die "C compiler test failed."
    
    fi  

报错2

错误内容:

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “config.log” produced by configure as this will help
solve the problem.

解决方案:

和报错1的解决方案类似,需要定位configure文件中的错误信息提示内容,

 die(){
     echolog "$@"
     cat <<EOF

 If you think configure made a mistake, make sure you are using the latest
 version from Git.  If the latest version fails, report the problem to the
 ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
 EOF
     if disabled logging; then
         cat <<EOF
 Rerun configure with logging enabled (do not use --disable-logging), and
 include the log this produces with your report.
 EOF
     else
         cat <<EOF
 Include the log file "$logfile" produced by configure as this will help
 solve the problem.
 EOF
     fi
 #    exit 1
 }

简单粗暴一点将exit 1直接注释掉,这样就不会退出了,但是会遇到什么问题不得而知,至少目前可以成功安装了。

报错3

错误内容:

aarch64-linux-gnu-gcc: error: missing argument to ‘-mcpu=’

解决方案:

configure 参数中加入 –cpu=$CPU_NAME 选项

4 At last

最后将out文件夹下的 文件copy到目标板上即可

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Linux 下使用 FFmpeg 交叉编译 Android 需要以下步骤: 1. 安装 Android NDK:可以从 Android 官网下载最新版本的 NDK,解压后将其路径添加到环境变量中。 2. 下载 FFmpeg 源码:可以从 FFmpeg 官网下载最新版本的源码包,解压后进入源码目录。 3. 配置交叉编译工具链:在 FFmpeg 源码目录下执行以下命令: ``` ./configure --target-os=android --arch=arm --enable-cross-compile --cross-prefix=$NDK/bin/arm-linux-androideabi- --sysroot=$NDK/platforms/android-21/arch-arm/ ``` 其中,$NDK 是你安装 Android NDK 的路径。 4. 编译 FFmpeg:执行以下命令进行编译: ``` make -j4 ``` 其中,-j4 表示使用 4 个线程编译。 5. 生成动态库:执行以下命令将编译好的动态库生成到指定目录: ``` make install PREFIX=/path/to/output/directory ``` 其中,/path/to/output/directory 是指生成的动态库要存放的目录路径。 完成上述步骤后,你就可以在 Android 项目中使用 FFmpeg 了。在 Android.mk 文件中添加以下代码: ``` LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := ffmpeg LOCAL_SRC_FILES := /path/to/output/directory/lib/libavformat.so /path/to/output/directory/lib/libavcodec.so /path/to/output/directory/lib/libswscale.so /path/to/output/directory/lib/libavutil.so include $(PREBUILT_SHARED_LIBRARY) ``` 其中,/path/to/output/directory 是指生成的动态库存放的目录路径。在 Android.mk 文件中添加以上代码后,就可以在 Android 项目中使用 FFmpeg 了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小麦大叔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值