nano pi neo2 上Ubuntu-core自行编译ffmpeg 动态so库 使用Ubuntu 16.04
环境Ubuntu 16 .04
nano pi neo 2 linux4.11.2 BSP
工具链gcc-linaro-aarch64.tar.xz [4.9]
aarch64-linux-gnu-gcc -v
Thread model: posix
gcc version 4.9.3 20150113 (prerelease) (Linaro GCC 4.9-2015.01-3)
源文件
alsa-lib-1.1.5.tar.bz2
ffmpeg-3.4.tar.bz2
last_x264.tar.bz2
lame-3.100.tar.gz
编译好的
http://download.csdn.net/download/aexisun/10139439
一.ubuntu 16.04 编译x264
1.解压配置
sun@sun:~/nanopineo2$
sun@sun:~/nanopineo2$
sun@sun:~/nanopineo2$ tar xf last_x264.tar.bz2
sun@sun:~/nanopineo2$ cd x264-snapshot-20171128-2245/
sun@sun:~/nanopineo2/x264-snapshot-20171128-2245$ ./configure --host=aarch64-linux-gnu --prefix=/x264-h5 --enable-shared --disable-asm
2.修改文件 编译工具
sun@sun:~/nanopineo2/x264-snapshot-20171128-2245$ vim config.mak
SYS_ARCH=ARM
SYS=LINUX
CC=aarch64-linux-gnu-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-gnu-gcc -o
LDFLAGS= -lm -lpthread -ldl
LIBX264=libx264.a
AR=aarch64-linux-gnu-ar rc
RANLIB=aarch64-linux-gnu-ranlib
STRIP=strip
INSTALL=install
3.编译 install
make
make install
文件都在/x264-h5文件夹下le
二.编译liblamemp3 ffmpeg 所需的编码器
sun@sun:~/nanopineo2$
sun@sun:~/nanopineo2$
sun@sun:~/nanopineo2$
sun@sun:~/nanopineo2$
sun@sun:~/nanopineo2$ tar xf lame-3.100.tar.gz
sun@sun:~/nanopineo2$ cd lame-3.100/
sun@sun:~/nanopineo2/lame-3.100$
sun@sun:~/nanopineo2/lame-3.100$
sun@sun:~/nanopineo2/lame-3.100$
sun@sun:~/nanopineo2/lame-3.100$ ./configure --host=aarch64-linux-gnu --prefix=/lame-h5 --enable-shared --disable-static
root@sun:/home/sun/nanopineo2/lame-3.100#
make -j4
root@sun:/home/sun/nanopineo2/lame-3.100#
make install
文件都在/lame-h5文件夹下了
三.nano pi neo2 的Ubuntu core 缺少libasound.so文件
导致ffmpeg的alsa设备不能编译.
所以需要手动编译alsa-lib到工具链和板子上
root@sun:/home/sun/nanopineo2#
root@sun:/home/sun/nanopineo2#
root@sun:/home/sun/nanopineo2# tar xf alsa-lib-1.1.5.tar.bz2
root@sun:/home/sun/nanopineo2# cd alsa-lib-1.1.5
root@sun:/home/sun/nanopineo2/alsa-lib-1.1.5# ./configure --host=aarch64-linux-gnu --prefix=/alsa-h5 --enable-shared --disable-static
root@sun:/home/sun/nanopineo2/alsa-lib-1.1.5# make -j4
root@sun:/home/sun/nanopineo2/alsa-lib-1.1.5# make install
文件都在/lalsa-h5文件夹下了
root@sun:/home/sun/nanopineo2#
root@sun:/home/sun/nanopineo2#
root@sun:/home/sun/nanopineo2# cp -rf /alsa-h5/lib* gcc-linaro-4.9-2015.02-3-x86_64_aarch64-linux-gnu/lib/gcc/aarch64-linux-gnu/4.9.3/
root@sun:/home/sun/nanopineo2# cp -rf /alsa-h5/include/* gcc-linaro-4.9-2015.02-3-x86_64_aarch64-linux-gnu/lib/gcc/aarch64-linux-gnu/4.9.3/include
编译ffmpeg前 需要把lasa/lib include 下的文件考到编译工具下,否则不能识别alsa设备
四.编译ffmpeg
root@sun:/home/sun/nanopineo2#
root@sun:/home/sun/nanopineo2#
root@sun:/home/sun/nanopineo2#
root@sun:/home/sun/nanopineo2#
root@sun:/home/sun/nanopineo2# tar xf ffmpeg-3.4.tar.bz2
root@sun:/home/sun/nanopineo2# cd ffmpeg-3.4
root@sun:/home/sun/nanopineo2/ffmpeg-3.4# ./configure --cross-prefix=aarch64-linux-gnu- --enable-cross-compile --target-os=linux
--cc=aarch64-linux-gnu-gcc --arch=arm64 --prefix=/ffmpeg-h5 --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libx264
--enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-pthreads --enable-libmp3lame --disable-stripping
--extra-cflags=-I/x264-h5/include --extra-ldflags=-L/x264-h5/lib --extra-cflags=-I/lame-h5/include --extra-ldflags=-L/lame-h5/lib
然后看下配置的结果有没有alsa
Enabled bsfs:
aac_adtstoasc imx_dump_header null
chomp mjpeg2jpeg remove_extradata
dca_core mjpega_dump_header text2movsub
dump_extradata mov2textsub vp9_raw_reorder
extract_extradata mp3_header_decompress vp9_superframe
h264_mp4toannexb mpeg4_unpack_bframes vp9_superframe_split
hevc_mp4toannexb noise
Enabled indevs:alsa lavfi v4l2
fbdev oss
Enabled outdevs:alsa oss v4l2
fbdev
License: nonfree and unredistributable
Creating configuration files ...
WARNING: aarch64-linux-gnu-pkg-config not found, library detection may fail.
WARNING: using libx264 without pkg-config
root@sun:/home/sun/nanopineo2/ffmpeg-3.4#
make -j4
make install
出现这个错误 C compiler test failed
arch=arm64折腾半天
五.复制所需的文件
把
lame-h5
x264-h5
ffmpeg-h5
alsa-h5
的lib include目录下的 都复制到nano板子/usr/lib /usr/include/
单独的复制ffmpeg-h5的bin目录下的文件 到nano板子的/usr/bin下[ffmpeg ffplay之类的]
root@NanoPi-NEO2:/home/pi# tar xf ffmpeg-h5.tar
root@NanoPi-NEO2:/home/pi# tar xf lame-h5.tar
root@NanoPi-NEO2:/home/pi# tar xf x264-h5.tar
root@NanoPi-NEO2:/home/pi# tar xf alsa-h5.tar
root@NanoPi-NEO2:/home/pi#
root@NanoPi-NEO2:/home/pi#
root@NanoPi-NEO2:/home/pi#
root@NanoPi-NEO2:/home/pi#
root@NanoPi-NEO2:/home/pi#
root@NanoPi-NEO2:/home/pi#
root@NanoPi-NEO2:/home/pi# cd /alsa-h5/
root@NanoPi-NEO2:/alsa-h5#
root@NanoPi-NEO2:/alsa-h5#
root@NanoPi-NEO2:/alsa-h5#
root@NanoPi-NEO2:/alsa-h5#
root@NanoPi-NEO2:/alsa-h5#
root@NanoPi-NEO2:/alsa-h5# cp -rf lib/* /usr/lib/;cp -rf include/ /usr/include/
root@NanoPi-NEO2:/alsa-h5# cd ../x264-h5/
root@NanoPi-NEO2:/x264-h5# cp -rf lib/* /usr/lib/;cp -rf include/ /usr/include/
root@NanoPi-NEO2:/x264-h5# cd ../lame-h5/
root@NanoPi-NEO2:/lame-h5# cp -rf lib/* /usr/lib/;cp -rf include/ /usr/include/
root@NanoPi-NEO2:/lame-h5# cd ../ffmpeg-h5/
root@NanoPi-NEO2:/ffmpeg-h5# cp -rf lib/* /usr/lib/;cp -rf include/ /usr/include/
root@NanoPi-NEO2:/ffmpeg-h5# cp -rf bin/* /usr/bin/
root@NanoPi-NEO2:/ffmpeg-h5#
root@NanoPi-NEO2:/ffmpeg-h5#
如果需要用ffmpeg的C库开发 还有把上面文件复制到编译工具链里面.就不需要bin目录了
gcc-linaro-4.9-2015.02-3-x86_64_aarch64-linux-gnu/lib/gcc/aarch64-linux-gnu/4.9.3/
这个目录是编译器的目录
六.测试下
root@NanoPi-NEO2:/ffmpeg-h5#
root@NanoPi-NEO2:/ffmpeg-h5#
root@NanoPi-NEO2:/ffmpeg-h5#
root@NanoPi-NEO2:/ffmpeg-h5# ffmpeg -devices
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.3 (Linaro GCC 4.9-2015.01-3) 20150113 (prerelease)
configuration: --cross-prefix=aarch64-linux-gnu- --enable-cross-compile --target-os=linux --cc=aarch64-linux-gnu-gcc
--arch=arm64 --prefix=/ffmpeg-h5 --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libx264 --enable-ffmpeg
--disable-ffplay --enable-ffserver --enable-swscale --enable-pthreads --enable-libmp3lame --disable-stripping --extra-cflags=-I/x264-h5/include
--extra-ldflags=-L/x264-h5/lib --extra-cflags=-I/lame-h5/include --extra-ldflags=-L/lame-h5/lib
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Devices:
D. = Demuxing supported
.E = Muxing supported
--
DE alsa ALSA audio output
DE fbdev Linux framebuffer
D lavfi Libavfilter virtual input device
DE oss OSS (Open Sound System) playback
E v4l2 Video4Linux2 output device
D video4linux2,v4l2 Video4Linux2 device grab
root@NanoPi-NEO2:/ffmpeg-h5#
Ubuntu 16.04 交叉工具链的路径 lib/gcc include
各种报错undefined 缺少连接库
aarch64-linux-gnu-gcc ff.c -o ff -lavformat -lavdevice -lavcodec -lavutil -lavfilter -lswscale -lswresample -lpostproc -lx264
ff.c
#include
#define __STDC_CONSTANT_MACROS
#ifdef __cplusplus
extern "C"
{
#endif
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavfilter/avfilter.h"
#ifdef __cplusplus
};
#endif
// arm-linux-gcc ff.c -o ff -lavcodec -lavdevice -lavfilter -lavformat -lavutil
/**
* AVFormat Support Information
*/
char * avformatinfo(){
char *info=(char *)malloc(40000);
memset(info,0,40000);
av_register_all();
AVInputFormat *if_temp = av_iformat_next(NULL);
AVOutputFormat *of_temp = av_oformat_next(NULL);
//Input
while(if_temp!=NULL){
sprintf(info, "%s[In ] %10s\n", info, if_temp->name);
if_temp=if_temp->next;
}
//Output
while (of_temp != NULL){
sprintf(info, "%s[Out] %10s\n", info, of_temp->name);
of_temp = of_temp->next;
}
return info;
}
/**
* AVCodec Support Information
*/
char * avcodecinfo()
{
char *info=(char *)malloc(40000);
memset(info,0,40000);
av_register_all();
AVCodec *c_temp = av_codec_next(NULL);
while(c_temp!=NULL){
if (c_temp->decode!=NULL){
sprintf(info, "%s[Dec]", info);
}
else{
sprintf(info, "%s[Enc]", info);
}
switch (c_temp->type){
case AVMEDIA_TYPE_VIDEO:
sprintf(info, "%s[Video]", info);
break;
case AVMEDIA_TYPE_AUDIO:
sprintf(info, "%s[Audio]", info);
break;
default:
sprintf(info, "%s[Other]", info);
break;
}
sprintf(info, "%s %10s\n", info, c_temp->name);
c_temp=c_temp->next;
}
return info;
}
/**
* AVFilter Support Information
*/
char * avfilterinfo()
{
char *info=(char *)malloc(40000);
memset(info,0,40000);
avfilter_register_all();
AVFilter *f_temp = (AVFilter *)avfilter_next(NULL);
while (f_temp != NULL){
sprintf(info, "%s[%15s]\n", info, f_temp->name);
f_temp=f_temp->next;
}
return info;
}
/**
* Configuration Information
*/
char * configurationinfo()
{
char *info=(char *)malloc(40000);
memset(info,0,40000);
av_register_all();
sprintf(info, "%s\n", avcodec_configuration());
return info;
}
int main(int argc, char* argv[])
{
char *infostr=NULL;
infostr=configurationinfo();
printf("\n<
free(infostr);
infostr=avformatinfo();
printf("\n<
free(infostr);
infostr=avcodecinfo();
printf("\n<
free(infostr);
infostr=avfilterinfo();
printf("\n<
free(infostr);
return 0;
}
SYS_ARCH=ARM
SYS=LINUX CC=aarch64-linux-gnu-gccCFLAGS=-Wno-maybe-uninitialized -Wshadow -O3 -ffast-math -Wall -I. -I$(SRCPATH) -std=gnu99 -D_GNU_SOURCE -fPIC -fomit-frame-pointer -fno-tree-vectorizeCOMPILER=GNUCOMPILER_STYLE=GNUDEPMM=-MM -g0DEPMT=-MT LD=aarch64-linux-gnu-gcc -oLDFLAGS= -lm -lpthread -ldlLIBX264=libx264.a AR=aarch64-linux-gnu-ar rc RANLIB=aarch64-linux-gnu-ranlibSTRIP=stripINSTALL=install