Porting OpenCV ffmpeg to ARM platform

Publisher:创客1992Latest update time:2016-07-06 Source: eefocusKeywords:OpenCV Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The previous article described how to port the OpenCV library to the ARM platform. Originally, I only used OpenCV to open the USB camera to obtain the image into the IplImage structure, which used the underlying functions of V4L2. Then I processed the video image frame.

So how to use OpenCV to read and write video files on the ARM board and perform video processing? How to port it?

This requires the installation of x264, xvid and ffmpeg, which is a bit different from the previous article's discussion of obtaining camera video through V4L2 underlying functions.

Here is a method.

Test environment: Ubuntu 12.04 LTS

OpenCV version: 1.0

Cross compiler: arm-none-linux-gnueabi-4.3.2

Proceed as follows:

1. Cross-compile libjpeg
In order to enable OpenCV to process jpeg images, we must cross-compile libjpeg in advance.
The version used here is jpegsrc.v6b
1 Download libjpeg source code: ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
2 Unzip and enter the directory
3 Configure
#./configure --prefix=/root/libjpeg-arm --exec-prefix=/root/libjpeg-arm --enable-shared
--enable-static
The following are the functions of these parameters:
--prefix=/root/libjpeg-arm: After executing make install, the system-independent files will be copied to this directory, as
follows:
/root/libjpeg-arm.....................................
|
+---include........................................
|
---jconfig.h
|
---jerror.h
|
---jmorecfg.h
|
---jpeglib.h
+---man............................................
|
+---man1.......................................
|
---cjeg.1
|
---djpeg.1
|
---jpegtran.1
|
---rdjpgcom.1
|
---wrjpgcom.1
--exec-prefix=/root/libjpeg-arm : After executing make install, system-independent files will be copied to this directory
, that is, some executable programs, dynamic link libraries and static link libraries will be copied to the corresponding directories of this directory, as follows:

/root/libjpeg-arm........................................
|
+---bin............................................
|
---cjeg
|
---djpeg
|
---jpegtran
|
---rdjpgcom
|
---wrjpgcom
+---lib...........................................
|
---libjpeg.la
|
---libjpeg.so
|
---libjpeg.so.62
|
---libjpeg.so.62.0.0
--enable-shared : Use GNU libtool to compile into a dynamic link library.
4 Modify the generated Makefile:
# The name of your C compiler:
CC= gcc should become CC= /root/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-gcc
(modify according to the location of your own cross compiler)
# library (.a) file creation command
AR= ar rc should become AR= /root/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-ar rc
(same as above)
# second step in .a creation (use "touch" if not needed)
AR2= ranlib should become AR2= /root/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabiranlib
(same as above)
5 Create four directories in the /root/libjpeg-arm directory: man/man1, include, lib, bin6
# make
# make install
7 Copy the files in /root/libjpeg-arm/include/ (jconfig.h, jerror.h, Copy the four header files (jmorecfg.h, jpeglib.h)
to /root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/include.
Copy the four library files (libjpeg.la, libjpeg.so, libjpeg.so.62, libjpeg.so.62.0.0) in /root/libjpeg-arm/lib
to /root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/lib.
Note: Execute the following command to check whether the generated libjpeg.so is the ARM version:

# file libjpeg.so
The following is the correct output, otherwise check the cross compiler path and Makefile and recompile.
Note: After executing the above operations, execute the following command to check whether the library file has been correctly installed:
# arm-linux-gcc -print-file-name=libjpeg.so
If the output is "libjpeg.so", it means it is not installed correctly, repeat step 7.
If the output is "DIR/libjpeg.so", it means it is installed correctly.
At this point, libjpeg cross compilation is completed.
2. Cross compile x264, xvid, ffmpeg
In order to enable OpenCV to process videos, we must cross compile ffmpeg in advance, and ffmpeg depends on x264 and
xvid.
1 Download yasm:
Go to http://www.tortall.net/projects/yasm/wiki/Download Download yasm0.7.2 (x264 requires
the assembly compiler)
# ./configure --enable-shared --prefix=/root/arm-none-linux-gnueabi/arm-none-linuxgnueabi/
--host=arm-linux
# make
# make install
2 Cross-compile x264
to ftp://ftp.videolan.org/pub/videolan/x264/snapshots/ Download x264-snapshot-20060805-
2245.tar.bz2, unzip and enter the directory
(1). Configure
# ./configure --prefix=/root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/ --enableshared
(2). Modify the configuration parameters
Modify config.mak:
prefix=/root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib
includedir=${prefix}/include
# Change to ARM here
ARCH=ARM
SYS=LINUX
# Change to arm-linux-gcc here
CC=arm-linux-gcc
# Remove -DHAVE_MMXEXT -DHAVE_SSE2 -DARCH_X86
CFLAGS=-Wall -I. -O4 -ffast-math -D__X264__ -DHAVE_MALLOC_H -DSYS_LINUX
-DHAVE_PTHREAD -s -fomit-frame-pointer
LDFLAGS= -lm -lpthread -s
AS=nasm

ASFLAGS=-O2 -f elf
VFW=no
GTK=no
EXE=
VIS=no
HAVE_GETOPT_LONG=1
DEVNULL=/dev/null
CONFIGURE_ARGS= '--enable-shared' '--prefix=/root/arm-none-linux-gnueabi/armnone-
linux-gnueabi/'
SONAME=libx264.so.49
default: $(SONAME)
Modify the Makefile and change the ar and ranlib in lines 66~68 to those under arm:
libx264.a: .depend $(OBJS) $(OBJASM)
arm-linux-ar rc libx264.a $(OBJS) $(OBJASM)
arm-linux-ranlib libx264.a
(3). Compile and install
# make
# make install Here you can generate libx264.so
in the cross-compilation chain directory /root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/ lib 3 Cross-compile xvid to http://downloads.xvid.org/downloads/xvidcore-1.1.3.tar.gz Download xvid Download xvid Unzip and enter build/generic configuration # ./configure --prefix=/root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/ --disableassembly [Explanation] --disable-assembly: Because xvid does not have assembly optimization for ARM, assembly must be turned off during compilation Edit Modify the platform.inc file referenced by Makefile, change CC=gcc to CC=arm-linux-gcc # make # make After install is successful, enter the example folder Test, enter arm-linux-gcc -o xvid_encraw xvid_encraw.c -lc -lm -I../src/ -L../build/generic/=build













-lxvidcore
can generate xvid_encraw. Here you can generate the corresponding header files and library files under include,lib
in the cross-compilation chain directory /root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/ 4 Cross-compile ffmpeg to http://download.chinaunix.net/download.php?id=5532&ResourceID=2990 Download ffmpeg-0.4.9-p20051120.tar.bz2 from this website , and then decompress it. Modify the configure file. The following should be modified. Since cc, ar, ranlib, and strip are all executable files in the cross-compilation environment, you can configure it like this prefix="/root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/" cross_prefix="root/arm-none-linux-gnueabi/bin/arm-linux-" cpu="arm" configuration # ./configure --cpu=arm --cc=arm-linux-gcc --enable-shared --disable-ffserver --enablexvid --enable-x264 --enable-gpl --enable-pthreads --disable-strip # make # make install Here you can generate the corresponding header files and library files under include,lib in the cross-compilation chain directory /root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/ So far, all the libraries that OpenCV depends on have been cross-compiled, and there are corresponding files under include,bin,share,lib in the cross-compilation chain 3. Cross-compile OpenCV Download OpenCV-1.0.0 source code http://www.opencv.org.cn/download/opencv-1.0.0.tar.gz Unzip and enter the directory configuration # ./configure --host=arm-none-linux-gnueabi --without-gtk --without-carbon --withoutquicktime --without-1394libs --with-ffmpeg --without-python --without-swig --enable-static --enable-shared --disable-apps CXX=arm-none-linux-gnueabi-g++ CPPFLAGS=- I/root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/include LDFLAGS=-L/root/arm-
























none-linux-gnueabi/arm-none-linux-gnueabi/lib --with-v4l --prefix=/root/opencv-arm
--libdir=/root/opencv-arm/lib --includedir=/root/opencv-arm/include
Description:
--host=arm-none-linux-gnueabi: indicates cross-compile arm platform
--without-gtk: ignore gtk+2.0 windows
--without-carbon: do not use X library on Mac OS
--without-quicktime
--without-1394libs
--without-ffmpeg
--without-python
--without-swig
--enable-static: generate static library
--enable-shared: generate dynamic library
CXX=arm-none-linux-gnueabi-g++: specify compilation tool
CPPFLAGS=-I/root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/include:
OpenCV will use some dev packages, such as png.h, jpeglib.h, most header files are in /usr/include
--prefix=/root/opencv-arm: specify the installation directory
-libdir=/root/opencv-arm/lib: specify the library file installation location
--includedir=/root/opencv-arm/include: specify the include file installation location
If the configuration is correct, there will be the following informationGeneral
configuration ====================================================
Compiler: arm-none-linux-gnueabi-g++
CXXFLAGS: -Wall -fno-rtti -pipe -O3 -fomit-frame-pointer
Install path: /root/opencv-arm
HighGUI configuration ================================================
Windowing system --------------
Use Carbon / Mac OS X: no
Use gtk+ 2.x: no
Use gthread: no
Image I/O --------------------------

Use libjpeg: yes

Use zlib: yes
Use libpng: yes
Use libtiff: no
Use libjasper: no
Use libIlmImf: no
Video I/O --------------------------
Use QuickTime / Mac OS X: no
Use xine: no
Use ffmpeg: yes
Use dc1394 & raw1394: no
Use v4l: yes
Use v4l2: yes
Wrappers for other languages ​​===================== ====================
SWIG
Python no
Additional build settings ======================== ====================
Build demo apps no
Now run make...
================================================== ==================
===
# make
# make install
The libraries required to run OpenCV on arm:
1. Copy the library file
libcvaux. so.1.0.0
libcv.so.1.0.0
libcxcore.so.1.0.0
libhighgui.so.1.0.0
libml.so.1.0.0
Copy them and rename them to
*.so.1
2 Add the previous library files and
copy the libjpeg, xvid, x264, and ffmpeg libraries under /root/arm-none-linux-gnueabi/arm-none-linux-gnueabi/lib to the board's /usr/lib or /lib, or you can go to a
folder on the board, and then #export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/YOUR/lib/DIR
3 List of libraries required by OpenCV:

Porting OpenCV ffmpeg to ARM platform
 

Compile the source file method
arm-none-linux-gnueabi-g++ demo.c -o demo -I/root/opencv-arm/include/opencv
-L/root/opencv-arm/lib -lcv -lcxcore -lpthread -lrt -lcvaux -lm -lpng -ljpeg -lz -lml -lhighgui
-ldlFinally
, copy the generated binary file to the board and run it

Keywords:OpenCV Reference address:Porting OpenCV ffmpeg to ARM platform

Previous article:Porting strace debugging tool to arm platform
Next article:How to port lua to the linux kernel of the arm platform

Recommended ReadingLatest update time:2024-11-17 15:59

Opencv porting in arm and x86
1. Development environment Operating system: fedora14 Opencv version number: 2.0 Qt version number: 4.7 arm:mini6410 Cross-compilation tool: arm-linux-gcc-4.5.1   2. Installation and Configuration Linux系统的安装,交叉Qt-creator的安装还有交叉编译工具的安装,网上说的基本都没什么问题,測试后都能够用。 这里安装Qt-Creator遇到了一点小问题,依照网上的和mini6410开发手冊上的安装方法太复杂了。用QtSdk-off
[Microcontroller]
Opencv porting in arm and x86
arm-Linux-opencv debugging summary
        Initially, I ported opencv to Ubuntu, and its installation directory is /usr/local. After debugging for several days, the porting was finally successful, and the program under window was also successfully ported to Ubuntu. Next, I considered porting opencv to arm (OpenCV porting on ARM http://www.cnblogs.com/em
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号