ubuntu安装opencv c++ with ffmpeg(支持视频编解码)

1.描述

需要使用opencv c++来处理一些视频文件,安装(编译)opencv时需要开启ffmpeg支持,此文章记录ubuntu下的安装过程,opencv版本以3.4.5为例,其他版本类似。

2.步骤总览

1.安装ffmpeg

2.安装其他相关库文件

3.编译并安装opencv

3.安装ffmpeg

  • 先更新源列表
apt-get update
  • 安装ffmpeg
apt-get install ffmpeg

如果出现下载问题(E: Failed to fetch xx.deb  Connection failed [IP: 91.189.91.39 80])可以尝试更改/etc/apt/sources.list为以下列表:

deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
deb http://archive.ubuntu.com/ubuntu/ bionic main restricted

  • 验证ffmpeg
ffmpeg -version

ubuntu安装opencv c++ with ffmpeg(支持视频编解码)_第1张图片

4.安装其他依赖库

  • 更新源列表
apt-get update
  • 安装
apt-get install pkg-config libavcodec-dev libavformat-dev libswscale-dev libavutil-dev

5.编译并安装opencv

  • github上下载对应版本的opencv源码(link

ubuntu安装opencv c++ with ffmpeg(支持视频编解码)_第2张图片

  • 解压并进行编译
//解压

unzip opencv-3.4.5.zip


//cmake编译

cd opencv-3.4.5

mkdir build && cd build

cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -D WITH_FFMPEG=ON ..

注意:要保证cmake后输出中如下选项为YES,否则证明ffmpeg未成功安装或者未被成功找到

ubuntu安装opencv c++ with ffmpeg(支持视频编解码)_第3张图片

// make编译安装(32为cpu的核数,根据自己机器的情况选择)

make -j32

make install //opencv库将被安装在/usr/local路径下

6.参考链接

linux下opencv with ffmpeg安装_街道口扛把子的博客-CSDN博客_opencv_ffmpeg

你可能感兴趣的:(linux,工具,opencv,音视频,ubuntu)