hi3516a之ffmpeg x264交叉编译

环境:centos_6.5_x86

交叉工具链:arm-hisiv300-linux-

步骤:

1.下载x264:

 

# git clone git://git.videolan.org/x264.git

linux 下编译x264; ./configure --prefix=/root/work/code/ffmpeg/x264-stable/linux --disable-asm --enable-static --enable-shared

2.下载ffmpeg

 

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

 

3.交叉编译

  1) [root@demo x264]# ./configure --enable-pthread --enable-static --disable-shared --host=arm-linux --disable-asm

  2)修改config.mak

注意:AR=arm-hisiv300-linux-ar rc  rc后面一定要有空格

     SRCPATH=.
prefix=/usr/local
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib
includedir=${prefix}/include
SYS_ARCH=ARM
SYS=LINUX
CC=arm-hisiv300-linux-gcc

CFLAGS=-Wshadow -O3 -ffast-math  -Wall -I. -I$(SRCPATH) -std=gnu99 -fomit-frame-pointer -fno-tree-vectorize
COMPILER=GNU
COMPILER_STYLE=GNU
DEPMM=-MM -g0
DEPMT=-MT
LD=arm-hisiv300-linux-gcc -o
LDFLAGS=-L/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/lib -lm -L/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/lib -lpthread -L/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/lib -ldl
LIBX264=libx264.a
AR=arm-hisiv300-linux-ar rc 
RANLIB=arm-hisiv300-linux-ranlib

STRIP=arm-hisiv300-linux-strip

。。。。

HOSTCC=arm-hisiv300-linux-gcc
HOSTLD=arm-hisiv300-linux-gcc

HOSTCFLAGS=  -std=c99 -Wall -O3
HOSTCPPFLAGS= -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
HOSTEXESUF=
HOSTLDFLAGS=
HOSTEXTRALIBS=-lm
DEPHOSTCC=arm-hisiv300-linux-gcc

 

   3) [root@demo x264]#make 

 [root@demo x264]#make install

        安装路径

install -d /usr/local/bin
install x264 /usr/local/bin
install -d /usr/local/include
install -d /usr/local/lib
install -d /usr/local/lib/pkgconfig
install -m 644 ./x264.h /usr/local/include
install -m 644 x264_config.h /usr/local/include
install -m 644 x264.pc /usr/local/lib/pkgconfig
install -m 644 libx264.a /usr/local/lib
arm-hisiv300-linux-ranlib /usr/local/lib/libx264.a

  4.ffmpeg交叉编译

./configure --enable-cross-compile --arch=arm --target-os=linux --enable-static --enable-shared --disable-yasm --enable-gpl --cc=arm-hisiv300-linux-gcc --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --prefix=/root/work/code/BaseCore/src/ffmpeg/ffmpeg-3.4.2/lib_arm --extra-libs=-ldl    

     修改config.mak,在目录ffbuild下

     # Automatically generated by configure - do not modify!
ifndef FFMPEG_CONFIG_MAK
FFMPEG_CONFIG_MAK=1
FFMPEG_CONFIGURATION=--enable-cross-compile --arch=arm --target-os=linux --enable-static --disable-shared --disable-yasm --enable-memalign-hack --enable-gpl --cc=arm-hisiv300-linux-gcc --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --prefix=/usr/local --extra-libs=-ldl
prefix=/usr/local
LIBDIR=$(DESTDIR)${prefix}/lib
SHLIBDIR=$(DESTDIR)${prefix}/lib
INCDIR=$(DESTDIR)${prefix}/include
BINDIR=$(DESTDIR)${prefix}/bin
DATADIR=$(DESTDIR)${prefix}/share/ffmpeg
DOCDIR=$(DESTDIR)${prefix}/share/doc/ffmpeg
MANDIR=$(DESTDIR)${prefix}/share/man
PKGCONFIGDIR=$(DESTDIR)${prefix}/lib/pkgconfig
SRC_PATH=.
ifndef MAIN_MAKEFILE
SRC_PATH:=$(SRC_PATH:.%=..%)
endif
CC_IDENT=gcc 4.8.3 (Hisilicon_v300) 20131202 (prerelease)
ARCH=arm
INTRINSICS=none
CC=arm-hisiv300-linux-gcc
CXX=arm-hisiv300-linux-g++
AS=arm-hisiv300-linux-gcc
LD=arm-hisiv300-linux-gcc
DEPCC=arm-hisiv300-linux-gcc

DEPCCFLAGS= $(CPPFLAGS)
DEPAS=arm-hisiv300-linux-gcc
DEPASFLAGS= $(CPPFLAGS)
YASM=yasm
DEPYASM=yasm
AR=arm-hisiv300-linux-ar

STRIP=arm-hisiv300-linux-strip

      [root@demo ffmpeg]#make
问题总结:

1)ffmpeg undefined reference to symbol 'dlclose'

 configure选项里面加上 --extra-libs=-ldl就可以了

2)报出错误:

x264.c:50:34: error: libavformat/avformat.h: No such file or directory
x264.c:51:30: error: libavutil/pixfmt.h: No such file or directory

  修改config.mak文件的第十行,加上 -I//home/ffmpeg/ffmpeg/ffmpeg 就可以找到了

3)运行make命令后,编译通过,但链接时出错。编译libx264.a库时,显示的命令为:

 

arm-linux-arlibx264.a ....

    make文件将链接命令和库名字间没有空格,导致系统无法识别此命令 

 

   手动执行下面的命令:

   arm-hisiv300-linux-ar rc libx264.a common/mc.o common/predict.o common/pixel.o common/macroblock.o common/frame.o common/dct.o common/cpu.o common/cabac.o common/common.o common/osdep.o common/rectangle.o common/set.o common/quant.o common/deblock.o common/vlc.o common/mvpred.o common/bitstream.o encoder/analyse.o encoder/me.o encoder/ratecontrol.o encoder/set.o encoder/macroblock.o encoder/cabac.o encoder/cavlc.o encoder/encoder.o encoder/lookahead.o common/threadpool.o

4)arm-linux-ranlib libx264.a (用于产生x264-config.h文件)

 

 

问题总结:

http://blog.csdn.net/sunxiaopengsun/article/details/79351915

 

 

调用ffmpeg demo:

 

makefile编写:

INCLUDE_PATH = ../ffmpeg/include/
INCLUDE = -I$(INCLUDE_PATH)libavutil/ -I$(INCLUDE_PATH)libavdevice/ \
                  -I$(INCLUDE_PATH)libavcodec/ -I$(INCLUDE_PATH)libswresample \
                  -I$(INCLUDE_PATH)libavfilter/ -I$(INCLUDE_PATH)libavformat \
                  -I$(INCLUDE_PATH)libswscale/ -I$(INCLUDE_PATH)
LIBPATH = -L../ffmpeg/lib -L/usr/local/lib
LIBFLAGS = -march=armv5te -Wl,--as-needed -Wl,-z,noexecstack -Wl,--warn-common -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample -lx264 -lm -pthread -ldl
CC=arm-hisiv300-linux-g++

FFMPEG_LIBS =  -lavformat -lavutil -lavdevice -lavcodec -lswresample -lavfilter -lswscale -lm -pthread -ldl
SDL_LIBS    =
LIBS        = $(FFMPEG_LIBS)$(SDL_LIBS)


a.out:main.o
        $(CC) $(LIBPATH) $(LIBFLAGS) -o main.out main.o $(FFMPEG_LIBS)


main.o:main.cpp
        $(CC) -c  main.cpp  $(INCLUDE)

.PHONY:clean
clean:
        -rm -rf *.o *.out

 

main.cpp

#include
#include
using namespace std;

extern "C"{
#ifdef __cplusplus
 #define __STDC_CONSTANT_MACROS
 #ifdef _STDINT_H
  #undef _STDINT_H
 #endif
 # include 
#endif
}



/* Unsigned. */
//#define UINT8_C(c)     c ## U
//#define UINT16_C(c)    c ## U
//#define UINT32_C(c)    c ## U
//#define UINT64_C(c) c ## ui64


extern "C"
{
#include
#include
#include
#include
#include
#include 
#include 

};


int main()
{
        av_register_all();
        avformat_network_init();
        cout << "hello ffmpeg" << endl;
        return 1;
}

 

 

 

你可能感兴趣的:(ffmpeg,嵌入式)