Compile opencv3.1 + ffmpeg in CentOS 7.1

Source: Internet
Author: User

Compile opencv3.1 + ffmpeg in CentOS 7.1

The project needs to compile opencv 3.1 with ffmpeg on the server. Previously, opencv was used only on windows, and compiling once was very painful. Therefore, this time we were fully prepared.

Compile ffmpeg

1. First download the source code and put it in the/ffmpeg directory.

2. Modify the config. Because there is no sudo permission, the default installation path should be changed. Compile opencv to call the dynamic library, so shared items should be added (very pitfall, for the first time not to increase the new version)

./Configure -- enable-shared -- prefix =./install

3. make

Then an error occurs.

  1. /Usr/bin/ld: libavcodec/mqc. o: relocation R_X86_64_32 against '. rodata' cannotbe used when making a shared object; recompile with-fPIC
  2. Libavcodec/mqc. o: erroradding symbols: Bad value
  3. Collect2: error: ld returned 1 exitstatus
Solution:

  1. Add config. mak L75 to-fPIC and re-compile
  2. HOSTCFLAGS =-O3-g-std = c99-Wall-fPIC (order may be different)

This time

Make install

Complete.

Compile opencv

1. Source Code

2. cd./opencv/

Mkdir build

Cd build

Cmake-D CMAKE_BUILD_TYPE = RELEASE-DCMAKE_INSTALL_PREFIX =./install ..

The configuration options are displayed. The default value of ffmpeg is yes.

3. make

Error

/usr/local/lib/libavcodec.a(avpacket.o):> relocation R_X86_64_32 against> `.rodata.str1.1' can not be used when> making a shared object; recompile with> -fPIC /usr/local/lib/libavcodec.a: could not read symbols: Bad value
It is said that the bug of opencv lies in the process of connecting libavcodec. a to the dynamic library. Here are three solutions (you will know how long I am stuck here ):

(1) Add the shared option when compiling ffmpeg as described above.

(2) Set CMAKE_CXX_FLAGS "$ {CMAKE_CXX_FLAGS}-fPIC", but it is not easy for me to try.

(3) Delete libavformat. a libavutil. a libavcodec. a libswscale. a from/usr/local/lib (the Library directory of ffmpeg), compile opencv, and put it back.

The final solution to my problem is (1) (3)

Then make & make install

Complete

For more information, see

Http://blog.csdn.net/jinatom/article/details/7982612

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.