Home  >  Article  >  System Tutorial  >  How to solve the problem that OpenCV cannot read video files on CentOS

How to solve the problem that OpenCV cannot read video files on CentOS

PHPz
PHPzforward
2024-01-04 11:43:11694browse

Under CentOS, follow the tutorial steps to install OpenCV, but in the end the video file cannot be read because ffmpeg is missing. So I installed ffmqeg through the software management in CentOS, but it still had no effect. Then I compiled ffmpeg, but it still had no effect. In fact, a key step is missed, which is to associate ffmpeg with OpenCV. details as follows:

1. Obtain ffmpeg:

Download ffmpeg through cvs, command line input: svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg

2. Configure ffmpeg:

Enter the ffmpeg directory and execute ./configure --enable-shared --prefix=/usr (I guess everyone knows the meaning of enabled-shared, but why do you need prefix=/usr? This depends on opencv's CMakeLists.txt and heighgui Speaking of the cvcap_ffmpeg.cpp under, the problems involved here should not cause path problems, but this problem caused me to go all morning. When checking whether ffmpeg is installed in cMakeLists.txt, the default is to /usr Go ahead and check whether the corresponding header files exist, but the default installation of ffmpeg is under /usr/local, and the problem arises, so if you change the installation path, opencv will not be able to detect whether you have already installed it in cmake. ffmpeg installed);

3. make; su -c "make install";

4. The next work to be done is related to whether opencv can successfully compile the related header files of ffmpeg:

4.1) First execute the following command (root) under /usr/include:

mkdir ffmpeg;

cp libav* libsw* ffmpeg; //The reason for this is because opencv configure checks whether ffmpeg is installed here

Checked

4.2) cmake .; //Note that there is a space between cmake and ., if

In the configure result, ffmpeg is 1, not the previous 0, which means we succeeded.

4.3) make install;

5. cp opencv.pc under /usr/local/lib/pkgconfig to /usr/lib/pkgconfig. This step can also be done. It is just a configuration file. At worst, you need to specify the header file yourself when compiling. Heku, in fact, you will know what it is when you open opencv.pc.

6. Under root, vim /etc/ld.so.conf, add a line, /usr/local/lib (because the library file of opencv is in local, by default the library file in local/lib is Not loaded when the system starts)

7. ldconfig.

The above is the detailed content of How to solve the problem that OpenCV cannot read video files on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete