Ubuntu18.4下交叉编译X264和FFMPEG到ARM平台(aarch64-linux-gcc)

简介: Ubuntu18.4下交叉编译X264和FFMPEG到ARM平台(aarch64-linux-gcc)

一、环境介绍

ubuntu桌面版本:  18.04

ffmpeg版本: 4.4.2

x264版本: x264-snapshot-20181217-2245

ARM目标开发板:  RK3399

x264-snapshot-20181217-2245源码下载地址: https://download.csdn.net/download/xiaolong1126626497/12234153

ffmpeg4.4.2源码下载地址: https://download.csdn.net/download/xiaolong1126626497/12234197

编译好的库,可以直接使用,下载地址:https://download.csdn.net/download/xiaolong1126626497/12291634

二、需求介绍

需要编译x264与ffmpeg库到arm平台,完成音频视频开发。

交叉编译器采用: aarch64-linux-gcc

交叉编译器下载地址:  https://download.csdn.net/download/xiaolong1126626497/12203205

三、编译X264库

下载源码解压,进入到解压目录执行下面命令。

wbyq@wbyq:~/work/rk3399/x264-snapshot-20181217-2245$make clean
wbyq@wbyq:~/work/rk3399/x264-snapshot-20181217-2245$./configure --prefix=$PWD/_install --disable-asm --enable-shared --enable-static --host=arm-none-linux-gnueabi
wbyq@wbyq:~/work/rk3399/x264-snapshot-20181217-2245$ gedit config.mak 

修改config.mak配置。修改其中的工具链,具体看下面的代码,我的编译器是aarch64-linux-

SRCPATH=.
prefix=/home/wbyq/work/rk3399/x264-snapshot-20181217-2245/_install
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib
includedir=${prefix}/include
SYS_ARCH=ARM
SYS=LINUX
CC=aarch64-linux-gcc
CFLAGS=-Wno-maybe-uninitialized -Wshadow -O3 -ffast-math  -Wall -I. -I$(SRCPATH) -std=gnu99 -D_GNU_SOURCE -fPIC -fomit-frame-pointer -fno-tree-vectorize
COMPILER=GNU
COMPILER_STYLE=GNU
DEPMM=-MM -g0
DEPMT=-MT
LD=aarch64-linux-gcc -o 
LDFLAGS= -lm -lpthread -ldl
LIBX264=libx264.a
AR=aarch64-linux-ar rc 
RANLIB=aarch64-linux-ranlib
STRIP=aarch64-linux-strip
INSTALL=install
AS=
ASFLAGS= -I. -I$(SRCPATH) -DSTACK_ALIGNMENT=4 -DPIC
RC=
RCFLAGS=
EXE=
HAVE_GETOPT_LONG=1
DEVNULL=/dev/null
PROF_GEN_CC=-fprofile-generate
PROF_GEN_LD=-fprofile-generate
PROF_USE_CC=-fprofile-use
PROF_USE_LD=-fprofile-use
HAVE_OPENCL=yes
CC_O=-o $@
default: cli
install: install-cli
SOSUFFIX=so
SONAME=libx264.so.157
SOFLAGS=-shared -Wl,-soname,$(SONAME)  -Wl,-Bsymbolic
default: lib-shared
install: install-lib-shared
default: lib-static
install: install-lib-static
LDFLAGSCLI = -ldl 
CLI_LIBX264 = $(LIBX264)

修改之后:

make && make install

成功生成的文件如下:

wbyq@wbyq:~/work/rk3399/x264-snapshot-20181217-2245$ ls
android           common        config.log  configure  encoder    filters   libx264.a       output      x264       x264_config.h  x264.o
AUTHORS           config.guess  config.mak  COPYING    example.c  input     libx264.so.157  tools       x264.c     x264dll.c      x264.pc
build_android.sh  config.h      config.sub  doc        extras     _install  Makefile        version.sh  x264cli.h  x264.h         x264res.rc
wbyq@wbyq:~/work/rk3399/x264-snapshot-20181217-2245$ clear
wbyq@wbyq:~/work/rk3399/x264-snapshot-20181217-2245$ tree _install/
_install/
├── bin
│   └── x264
├── include
│   ├── x264_config.h
│   └── x264.h
└── lib
    ├── libx264.a
    ├── libx264.so -> libx264.so.157
    ├── libx264.so.157
    └── pkgconfig
        └── x264.pc
4 directories, 7 files
wbyq@wbyq:~/work/rk3399/x264-snapshot-20181217-2245$ 

四、编译FFMPEG

下载源码解压,进入到解压目录执行下面命令。

wbyq@wbyq:~/work/rk3399/ffmpeg-4.2.2$ make clean
wbyq@wbyq:~/work/rk3399/ffmpeg-4.2.2$ ./configure --enable-shared --enable-static --prefix=$PWD/_install --cross-prefix=aarch64-linux- --arch=arm64 --target-os=linux --enable-gpl --enable-ffmpeg --enable-libx264 --extra-cflags=-I/home/wbyq/work/rk3399/x264-snapshot-20181217-2245/_install/include --extra-ldflags=-L/home/wbyq/work/rk3399/x264-snapshot-20181217-2245/_install/lib
wbyq@wbyq:~/work/rk3399/ffmpeg-4.2.2$ make && make install

说明: 里面涉及到的X264路径,根据自己路径情况修改。

编译完成生成的文件如下:

wbyq@wbyq:~/work/rk3399/ffmpeg-4.2.2$ ls
Changelog  configure        COPYING.GPLv3     CREDITS  ffmpeg    ffprobe_g  INSTALL.md   libavfilter    libavutil      libswscale   Makefile   RELEASE        tools
compat     CONTRIBUTING.md  COPYING.LGPLv2.1  doc      ffmpeg_g  fftools    libavcodec   libavformat    libpostproc    LICENSE.md   presets    RELEASE_NOTES  VERSION
config.h   COPYING.GPLv2    COPYING.LGPLv3    ffbuild  ffprobe   _install   libavdevice  libavresample  libswresample  MAINTAINERS  README.md  tests
wbyq@wbyq:~/work/rk3399/ffmpeg-4.2.2$ tree _install/
_install/
├── bin
│   ├── ffmpeg
│   └── ffprobe
├── include
│   ├── libavcodec
│   │   ├── ac3_parser.h
│   │   ├── adts_parser.h
│   │   ├── avcodec.h
│   │   ├── avdct.h
│   │   ├── avfft.h
│   │   ├── d3d11va.h
│   │   ├── dirac.h
│   │   ├── dv_profile.h
│   │   ├── dxva2.h
│   │   ├── jni.h
│   │   ├── mediacodec.h
│   │   ├── qsv.h
│   │   ├── vaapi.h
│   │   ├── vdpau.h
│   │   ├── version.h
│   │   ├── videotoolbox.h
│   │   ├── vorbis_parser.h
│   │   └── xvmc.h
│   ├── libavdevice
│   │   ├── avdevice.h
│   │   └── version.h
│   ├── libavfilter
│   │   ├── avfilter.h
│   │   ├── buffersink.h
│   │   ├── buffersrc.h
│   │   └── version.h
│   ├── libavformat
│   │   ├── avformat.h
│   │   ├── avio.h
│   │   └── version.h
│   ├── libavutil
│   │   ├── adler32.h
│   │   ├── aes_ctr.h
│   │   ├── aes.h
│   │   ├── attributes.h
│   │   ├── audio_fifo.h
│   │   ├── avassert.h
│   │   ├── avconfig.h
│   │   ├── avstring.h
│   │   ├── avutil.h
│   │   ├── base64.h
│   │   ├── blowfish.h
│   │   ├── bprint.h
│   │   ├── bswap.h
│   │   ├── buffer.h
│   │   ├── camellia.h
│   │   ├── cast5.h
│   │   ├── channel_layout.h
│   │   ├── common.h
│   │   ├── cpu.h
│   │   ├── crc.h
│   │   ├── des.h
│   │   ├── dict.h
│   │   ├── display.h
│   │   ├── downmix_info.h
│   │   ├── encryption_info.h
│   │   ├── error.h
│   │   ├── eval.h
│   │   ├── ffversion.h
│   │   ├── fifo.h
│   │   ├── file.h
│   │   ├── frame.h
│   │   ├── hash.h
│   │   ├── hdr_dynamic_metadata.h
│   │   ├── hmac.h
│   │   ├── hwcontext_cuda.h
│   │   ├── hwcontext_d3d11va.h
│   │   ├── hwcontext_drm.h
│   │   ├── hwcontext_dxva2.h
│   │   ├── hwcontext.h
│   │   ├── hwcontext_mediacodec.h
│   │   ├── hwcontext_qsv.h
│   │   ├── hwcontext_vaapi.h
│   │   ├── hwcontext_vdpau.h
│   │   ├── hwcontext_videotoolbox.h
│   │   ├── imgutils.h
│   │   ├── intfloat.h
│   │   ├── intreadwrite.h
│   │   ├── lfg.h
│   │   ├── log.h
│   │   ├── lzo.h
│   │   ├── macros.h
│   │   ├── mastering_display_metadata.h
│   │   ├── mathematics.h
│   │   ├── md5.h
│   │   ├── mem.h
│   │   ├── motion_vector.h
│   │   ├── murmur3.h
│   │   ├── opt.h
│   │   ├── parseutils.h
│   │   ├── pixdesc.h
│   │   ├── pixelutils.h
│   │   ├── pixfmt.h
│   │   ├── random_seed.h
│   │   ├── rational.h
│   │   ├── rc4.h
│   │   ├── replaygain.h
│   │   ├── ripemd.h
│   │   ├── samplefmt.h
│   │   ├── sha512.h
│   │   ├── sha.h
│   │   ├── spherical.h
│   │   ├── stereo3d.h
│   │   ├── tea.h
│   │   ├── threadmessage.h
│   │   ├── timecode.h
│   │   ├── time.h
│   │   ├── timestamp.h
│   │   ├── tree.h
│   │   ├── twofish.h
│   │   ├── tx.h
│   │   ├── version.h
│   │   └── xtea.h
│   ├── libpostproc
│   │   ├── postprocess.h
│   │   └── version.h
│   ├── libswresample
│   │   ├── swresample.h
│   │   └── version.h
│   └── libswscale
│       ├── swscale.h
│       └── version.h
├── lib
│   ├── libavcodec.a
│   ├── libavcodec.so -> libavcodec.so.58.54.100
│   ├── libavcodec.so.58 -> libavcodec.so.58.54.100
│   ├── libavcodec.so.58.54.100
│   ├── libavdevice.a
│   ├── libavdevice.so -> libavdevice.so.58.8.100
│   ├── libavdevice.so.58 -> libavdevice.so.58.8.100
│   ├── libavdevice.so.58.8.100
│   ├── libavfilter.a
│   ├── libavfilter.so -> libavfilter.so.7.57.100
│   ├── libavfilter.so.7 -> libavfilter.so.7.57.100
│   ├── libavfilter.so.7.57.100
│   ├── libavformat.a
│   ├── libavformat.so -> libavformat.so.58.29.100
│   ├── libavformat.so.58 -> libavformat.so.58.29.100
│   ├── libavformat.so.58.29.100
│   ├── libavutil.a
│   ├── libavutil.so -> libavutil.so.56.31.100
│   ├── libavutil.so.56 -> libavutil.so.56.31.100
│   ├── libavutil.so.56.31.100
│   ├── libpostproc.a
│   ├── libpostproc.so -> libpostproc.so.55.5.100
│   ├── libpostproc.so.55 -> libpostproc.so.55.5.100
│   ├── libpostproc.so.55.5.100
│   ├── libswresample.a
│   ├── libswresample.so -> libswresample.so.3.5.100
│   ├── libswresample.so.3 -> libswresample.so.3.5.100
│   ├── libswresample.so.3.5.100
│   ├── libswscale.a
│   ├── libswscale.so -> libswscale.so.5.5.100
│   ├── libswscale.so.5 -> libswscale.so.5.5.100
│   ├── libswscale.so.5.5.100
│   └── pkgconfig
│       ├── libavcodec.pc
│       ├── libavdevice.pc
│       ├── libavfilter.pc
│       ├── libavformat.pc
│       ├── libavutil.pc
│       ├── libpostproc.pc
│       ├── libswresample.pc
│       └── libswscale.pc
└── share
    ├── ffmpeg
    │   ├── examples
    │   │   ├── avio_dir_cmd.c
    │   │   ├── avio_reading.c
    │   │   ├── decode_audio.c
    │   │   ├── decode_video.c
    │   │   ├── demuxing_decoding.c
    │   │   ├── encode_audio.c
    │   │   ├── encode_video.c
    │   │   ├── extract_mvs.c
    │   │   ├── filter_audio.c
    │   │   ├── filtering_audio.c
    │   │   ├── filtering_video.c
    │   │   ├── http_multiclient.c
    │   │   ├── hw_decode.c
    │   │   ├── Makefile
    │   │   ├── metadata.c
    │   │   ├── muxing.c
    │   │   ├── qsvdec.c
    │   │   ├── README
    │   │   ├── remuxing.c
    │   │   ├── resampling_audio.c
    │   │   ├── scaling_video.c
    │   │   ├── transcode_aac.c
    │   │   ├── transcoding.c
    │   │   ├── vaapi_encode.c
    │   │   └── vaapi_transcode.c
    │   ├── ffprobe.xsd
    │   ├── libvpx-1080p50_60.ffpreset
    │   ├── libvpx-1080p.ffpreset
    │   ├── libvpx-360p.ffpreset
    │   ├── libvpx-720p50_60.ffpreset
    │   └── libvpx-720p.ffpreset
    └── man
        ├── man1
        │   ├── ffmpeg.1
        │   ├── ffmpeg-all.1
        │   ├── ffmpeg-bitstream-filters.1
        │   ├── ffmpeg-codecs.1
        │   ├── ffmpeg-devices.1
        │   ├── ffmpeg-filters.1
        │   ├── ffmpeg-formats.1
        │   ├── ffmpeg-protocols.1
        │   ├── ffmpeg-resampler.1
        │   ├── ffmpeg-scaler.1
        │   ├── ffmpeg-utils.1
        │   ├── ffprobe.1
        │   └── ffprobe-all.1
        └── man3
            ├── libavcodec.3
            ├── libavdevice.3
            ├── libavfilter.3
            ├── libavformat.3
            ├── libavutil.3
            ├── libswresample.3
            └── libswscale.3
18 directories, 208 files
wbyq@wbyq:~/work/rk3399/ffmpeg-4.2.2$ 

五、库的运行方式

编译ffmpeg代码的Makefile示例:

all:
  aarch64-linux-gnu-gcc app.c -I /home/wbyq/work/rk3399/ffmpeg-4.2.2/_install/include -L /home/wbyq/work/rk3399/ffmpeg-4.2.2/_install/lib -I/home/wbyq/work/rk3399/x264-snapshot-20181217-2245/_install/include  -L/home/wbyq/work/rk3399/x264-snapshot-20181217-2245/_install/lib -lavcodec -lavfilter -lavutil -lswresample -lavdevice -lavformat -lpostproc -lswscale -lm -lpthread -lasound -lx264 

目录
相关文章
|
12月前
|
Ubuntu Linux UED
Ubuntu和Debian系统与Hat Linux系列的使用比较
所以,如果你想搞一个家用服务器,或者是个人使用,喜欢新鲜事物,那Ubuntu可能是你的最好选择。如果你需要一个在商业环境中经受住考验的系统,那Fedora或CentOS可能更符合你的口味。不过记住,CentOS现在是CentOS Stream,中途换马了,所以如果你是稳定性的极端追求者,可能得考虑一下这一变化。而Debian,则适合那些对稳定性需求极高,不太追求软件版本新旧的用户。
398 26
|
Ubuntu 搜索推荐 Linux
Ubuntu/Debian Hat系Linux的便捷操作指南
总的来说,虽然Ubuntu/Debian和Red Hat系列在操作方法上有所不同,但基本概念类似。掌握了包管理和服务管理,可以应对大多数常见的系统管理任务。同时,这两个系统都有丰富的在线资源可以查询,不管你在任务中遇到什么困难,搜索引擎都能帮你找到答案。这些基本技能能让你在Linux的世界里更加自如。
334 26
|
12月前
|
Ubuntu Linux Shell
Linux环境下VSCode快速安装终极指南:debian/ubuntu/linux平台通用
以上就是在Linux环境下安装VSCode的终极指南,抛开繁复的专业词汇,以平易近人的文字、形象生动的比喻让你轻松学会这一过程。别忘了,你的小伙伴VSCode已经在应用菜单里等你了!
3279 23
|
Ubuntu 安全 Linux
Linux错误排查:解决Ubuntu 20.4执行sudo apt-get update时出现的libnettle.so.6错误。
很有可能在你得到解决方案时,你也学到了不少Linux修复技巧。祝你处理计算机问题时顺利如麻!永远记得,各种问题总是像老鼠一样从意想不到的地方冒出来。但记住,不管它们跑到哪里,最终都逃不过你的捕鼠器。盖起你的计算机,拾起你的代码,大步向前!
469 28
|
Ubuntu 安全 Linux
Linux错误排查:解决Ubuntu 20.4执行sudo apt-get update时出现的libnettle.so.6错误。
很有可能在你得到解决方案时,你也学到了不少Linux修复技巧。祝你处理计算机问题时顺利如麻!永远记得,各种问题总是像老鼠一样从意想不到的地方冒出来。但记住,不管它们跑到哪里,最终都逃不过你的捕鼠器。盖起你的计算机,拾起你的代码,大步向前!
438 18
|
10月前
|
Ubuntu Linux
任何Ubuntu用户都应安装的四大Linux应用程序
当然,这款程序不需要太多介绍。我们面对的是网上最庞大最完整的多媒体中心,由于丰富的插件,我们能够高度细化地定制其每一项功能。这是我们的Linux发行版不可或缺的必备软件。 我们可以通过运行以下命令来轻松安装Kodi:sudo apt install kodi。
|
8月前
|
Ubuntu 安全 iOS开发
Nessus Professional 10.10 Auto Installer for Ubuntu 24.04 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for Ubuntu 24.04 - Nessus 自动化安装程序
1065 5
|
8月前
|
NoSQL Ubuntu MongoDB
在Ubuntu 22.04上安装MongoDB 6.0的步骤
这些步骤应该可以在Ubuntu 22.04系统上安装MongoDB 6.0。安装过程中,如果遇到任何问题,可以查阅MongoDB的官方文档或者Ubuntu的相关帮助文档,这些资源通常提供了解决特定问题的详细指导。
843 18
|
9月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
464 18
|
9月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
619 15