RK3399编译x264/FFMPEG/OPENCV支持MP4视频格式

opencv保存MP4视频格式,需要FFMPEG链接x264.so库,实现H264视频格式。

一、环境介绍

宿主机环境: ubuntu18.04 64位 PC平台

目标环境: RK3399(ubuntu18.04 64位 ARM平台)

编译器: aarch64-linux-gcc

二、准备工作

2.1 先下载好ffmpeg和x264源码。

不会下载的参考这里:Linux下交叉编译FFMPEG与X264库:目标板友善之臂Tiny4412开发板_EXYNOS4412(ARMV7_32位)_DS小龙哥的博客-CSDN博客

2.2 下载安装aarch64-linux-gcc编译器

编译器在这里:FriendlyARM_64_ARMGCC.7z_交叉编译ffmpeg-C工具类资源-CSDN下载

三、开始交叉编译

3.1 交叉编译x264

wbyq@wbyq:~/rk3399$ tar xvf /mnt/hgfs/linux-share-dir/last_x264.tar.bz2 
wbyq@wbyq:~/rk3399$ cd x264-snapshot-20181217-2245/
wbyq@wbyq:~/x264-snapshot-20181217-2245$./configure --prefix=$PWD/_install --disable-asm --enable-shared --enable-static --host=arm-none-linux-gnueabi

配置之后在当前目录会生成config.mak文件,打开config.mak文件进行修改。

 

继续编译安装。

wbyq@wbyq:~/rk3399/x264-snapshot-20181217-2245$ make && make instal

最终生成的文件如下:

 

3.2 交叉编译ffmpeg

wbyq@wbyq:~/rk3399$ tar xvf /mnt/hgfs/linux-share-dir/ffmpeg-4.2.2.tar.bz2 
wbyq@wbyq:~/rk3399$ cd ffmpeg-4.2.2/
wbyq@wbyq:~/rk3399/ffmpeg-4.2.2$ ./configure --enable-shared --enable-static --prefix=$PWD/install --cross-prefix=aarch64-linux-gnu- --arch=arm64 --target-os=linux --enable-gpl --extra-cflags=-I/home/ubuntu/RK3399_OpenCV/x264/install/include --extra-ldflags=-L/home/ubuntu/RK3399_OpenCV/x264/install/lib --enable-ffmpeg --enable-libx264
wbyq@wbyq:~/rk3399/ffmpeg-4.2.2$ make && make install

注意:以上配置代码里的x264路径要修成成自己的实际路径。

编译生成的文件如下:

wbyq@wbyq:~/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:~/rk3399/ffmpeg-4.2.2$

3.3 OPENCV编译

opencv编译建议使用opencv 3.0版本,本人编译过opencv 4.5.5各种不顺,最终编译出来的opencv也无法使用;最终选择3.4.16版本,编译非常顺利。

在编译OPENCV前,需要准备好cmake工具:

sudo apt install cmake

cmake安装完成后:输入命令cmake-gui打开cmake页面 ==》选择opencv路径 ==》选择交叉编译链 ==》根据需要勾选编译内容 ==》configure ==》Generate,如下图:

 

 

完成上述步骤后,opencv编译的makefile就生成了

cd /home/ubuntu/RK3399_OpenCV/opencv-3.4.16/build
make -j8
make install

完成编译,接下来,只需要把生成的库打包拷贝到目标平台即可。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值