Ubuntu 16.04下安装ffmpeg和opencv的安装与简介

ffmpeg简介

关于音视频解码的学习内容:推荐雷神的音频视频编解码的学习地址

ffmpeg一种完整的跨平台解决方案,用于录制,转换和流式传输音频和视频

编译好的windows可用版本的下载地址(官网中可以连接到这个网站,和官方网站保持同步): http://ffmpeg.zeranoe.com/builds/
该网站中的FFMPEG分为3个版本:Static,Shared,Dev。

缩略语全称中文名字
ffmpegfast forward mpeg音频转换器
ffplayfast forward play用ffmpeg实现的播放器
ffserverfast forward server用ffmpeg实现的rstp服务器

资料准备

名称描述
gccgcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0c编译器
linuxUbuntu 6.04操作系统
yasmyasm 1.3.0汇编编译器
源码git clone https://github.com/FFmpeg/FFmpeg.git(Github)源码
源码http://ffmpeg.org/download.html#build-linux(官网)源码
二进制文件(win)http://ffmpeg.zeranoe.com/builds/二进制程序

注: 18.04 直接执行命令: sudo apt install ffmpeg 就可以了;
但是!默认安装的ffmpeg是3.7版本,对ffmpeg版本有要求的不建议使用此方法。

0. 检查依赖yasm与gcc,以及pkg-config

linux默认安装了gcc,如果你确实没有安装gcc,那么你需要安装一下gcc;
FFmpeg中有部分汇编代码,因此需要编译该部分代码,安装yasm即可,你可以认为yasm就是一个汇编编译器,安装 yasm 的目的在于提高 ffmpeg 的编译速度。


root@test-2288H-V5:~# yasm --version
yasm 1.3.0
Compiled on May  6 2015.
Copyright (c) 2001-2014 Peter Johnson and other Yasm developers.
Run yasm --license for licensing overview and summary.

root@test-2288H-V5:~# gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

如果没有就安装


# apt-get install yasm
# apt-get install gcc


检查pkg-config
如果显示以下信息,请参考我另一篇博文《Ubuntu 16.04 下pkg-config的安装与简介
注: 18.04 直接执行命令: sudo apt-get install pkg-config 就可以了


root@test-2288H-V5:/home/wang/ffmpeg-4.2# pkg_config
bash: pkg_config: command not found

1. 下载ffmpeg

下载地址1:https://ffmpeg.org/download.html#releases
下载地址2:https://pkgs.org/download/ffmpeg
下载地址3以及安装说明:http://www.linuxfromscratch.org/blfs/view/svn/multimedia/ffmpeg.html

2. 解压进入解压目录

注: 建议下载这个tar -jxvf ffmpeg-4.2.tar.bz2;我这 tar.gz不能编译。。。


tar -jxvf ffmpeg-4.2.tar.bz2
cd ffmpeg-4.2

详细信息


root@test-2288H-V5:/home/wang# cd ffmpeg-4.2
root@test-2288H-V5:/home/wang/ffmpeg-4.2# ll
total 640
drwx------ 18 test test   4096 8月   6 05:11 ./
drwxr-x---  3 wang wang   4096 8月  16 23:51 ../
-rw-r-----  1 test test  61453 8月   6 04:52 Changelog
drwxr-xr-x 12 test test   4096 8月   6 04:52 compat/
-rwxr-xr-x  1 test test 251982 8月   6 05:11 configure*
-rw-r--r--  1 test test    418 11月  2  2018 CONTRIBUTING.md
-rw-r--r--  1 test test  18092 3月  29  2016 COPYING.GPLv2
-rw-r--r--  1 test test  35147 3月  29  2016 COPYING.GPLv3
-rw-r--r--  1 test test  26526 3月  29  2016 COPYING.LGPLv2.1
-rw-r--r--  1 test test   7651 3月  29  2016 COPYING.LGPLv3
-rw-r--r--  1 test test    274 3月  29  2016 CREDITS
drwxr-xr-x  4 test test   4096 8月   6 04:52 doc/
drwxr-xr-x  2 test test   4096 8月   6 04:52 ffbuild/
drwxr-xr-x  2 test test   4096 8月   6 04:52 fftools/
-rw-r--r--  1 test test     50 7月   9 01:45 .gitattributes
-rw-r-----  1 test test    596 8月   6 04:52 INSTALL.md
drwxr-xr-x 14 test test  45056 8月   6 04:52 libavcodec/
drwxr-xr-x  3 test test   4096 8月   6 04:52 libavdevice/
drwxr-xr-x  6 test test  20480 8月   6 04:52 libavfilter/
drwxr-xr-x  3 test test  20480 8月   6 04:52 libavformat/
drwxr-xr-x  6 test test   4096 7月   9 01:45 libavresample/
drwxr-xr-x 12 test test  12288 8月   6 04:52 libavutil/
drwxr-xr-x  2 test test   4096 8月   6 04:52 libpostproc/
drwxr-xr-x  6 test test   4096 8月   6 04:52 libswresample/
drwxr-xr-x  7 test test   4096 8月   6 04:52 libswscale/
-rw-r-----  1 test test   3825 8月   6 04:52 LICENSE.md
-rw-r-----  1 test test  29540 8月   6 04:52 MAINTAINERS
-rw-r-----  1 test test   5633 8月   6 04:52 Makefile
drwxr-xr-x  2 test test   4096 3月  29  2016 presets/
-rw-r--r--  1 test test   1790 7月   9 01:45 README.md
-rw-r-----  1 test test      4 8月   6 04:52 RELEASE
-rw-r-----  1 test test    830 8月   6 04:52 RELEASE_NOTES
drwxr-xr-x  7 test test   4096 8月   6 04:52 tests/
drwxr-xr-x  3 test test   4096 8月   6 04:52 tools/
-rw-r-----  1 test test    531 8月   6 04:52 .travis.yml
-rw-r-----  1 test test      4 8月   6 05:11 VERSION


3. 准备执行编译配置操作,执行如下操作

注: 如果是要装多个ffmpeg, 把这个配置修改为:
./configure --prefix=/home/xxx/tools/ffmpegxxx --enable-shared --enable-pic install

./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-pic install


root@test-2288H-V5:/home/wang/ffmpeg-4.2# ./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-pic
install 
source path               .
C compiler                gcc
C library                 glibc
ARCH                      x86 (generic)
big-endian                no
runtime cpu detection     yes
standalone assembly       yes
x86 assembler             yasm
MMX enabled               yes
MMXEXT enabled            yes
3DNow! enabled            yes
3DNow! extended enabled   yes
SSE enabled               yes
SSSE3 enabled             yes
AESNI enabled             yes
AVX enabled               yes
AVX2 enabled              yes


4. 编译与安装


make
sudo make install

细节如下:


License: LGPL version 2.1 or later
root@test-2288H-V5:/home/wang/ffmpeg-4.2# make
GEN     libavutil/libavutil.version
GEN     libswscale/libswscale.version
GEN     libswresample/libswresample.version
GEN     libavcodec/libavcodec.version
GEN     libavformat/libavformat.version
GEN     libavfilter/libavfilter.version
GEN     libavdevice/libavdevice.version
CC      libavdevice/alldevices.o
CC      libavdevice/avdevice.o
libavdevice/avdevice.c: In function ‘device_next’:
libavdevice/avdevice.c:88:13: warning: ‘av_oformat_next’ is deprecated [-Wdeprecated-declarations]
             if (!(prev = av_oformat_next(prev)))
             ^
In file included from libavdevice/avdevice.h:51:0,
                 from libavdevice/avdevice.c:23:
./libavformat/avformat.h:2095:17: note: declared here
 AVOutputFormat *av_oformat_next(const AVOutputFormat *f);
                 ^
libavdevice/avdevice.c:92:13: warning: ‘av_iformat_next’ is deprecated [-Wdeprecated-declarations]
             if (!(prev = av_iformat_next(prev)))


root@test-2288H-V5:/home/wang/ffmpeg-4.2# sudo make install
INSTALL libavdevice/libavdevice.a
INSTALL libavdevice/libavdevice.so
STRIP   install-libavdevice-shared
INSTALL libavfilter/libavfilter.a
INSTALL libavfilter/libavfilter.so
STRIP   install-libavfilter-shared
INSTALL libavformat/libavformat.a
INSTALL libavformat/libavformat.so
STRIP   install-libavformat-shared
INSTALL libavcodec/libavcodec.a
INSTALL libavcodec/libavcodec.so
STRIP   install-libavcodec-shared
INSTALL libswresample/libswresample.a
INSTALL libswresample/libswresample.so
STRIP   install-libswresample-shared
INSTALL libswscale/libswscale.a
INSTALL libswscale/libswscale.so
STRIP   install-libswscale-shared
INSTALL libavutil/libavutil.a
INSTALL libavutil/libavutil.so
STRIP   install-libavutil-shared
INSTALL doc/ffmpeg.1


这里有warning,查了一些资料emmm不好不好,有大佬知道如何解决,可以附在评论,我学习一下,完善资料。

5. 检查安装情况

5.1 这里有两个问题:

资料说必须到安装所在的文件夹查看版本信息,当我执行 :ffmpeg --version
报错:


Unrecognized option '-version'.
Error splitting the argument list: Option not found

当我执行 :ffmpeg -version
不会报错。。。



root@test-2288H-V5:/home/wang/ffmpeg-4.2# /usr/local/ffmpeg/bin/ffmpeg -version
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
configuration: --prefix=/usr/local/ffmpeg --enable-shared --enable-pic
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100


5.2 执行细节如下:


root@test-2288H-V5:/home/wang/ffmpeg-4.2# /usr/local/ffmpeg/bin/ffmpeg --version
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
  configuration: --prefix=/usr/local/ffmpeg --enable-shared --enable-pic
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
Unrecognized option '-version'.
Error splitting the argument list: Option not found
root@test-2288H-V5:/home/wang/ffmpeg-4.2# /usr/local/ffmpeg/bin/ffmpeg -version
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
configuration: --prefix=/usr/local/ffmpeg --enable-shared --enable-pic
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
root@test-2288H-V5:/home/wang/ffmpeg-4.2# /usr/local/ffmpeg/bin/ffmpeg -help
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
  configuration: --prefix=/usr/local/ffmpeg --enable-shared --enable-pic
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Getting help:
    -h      -- print basic options
    -h long -- print more options
    -h full -- print all options (including all format and codec specific options, very long)
    -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf
    See man ffmpeg for detailed description of the options.

6. ffmpeg -version出现 ffmpeg command not found解决办法

如果显示以下信息,请参考我另一篇博文《ffmpeg 检查版本:ffmpeg -version出现 ffmpeg command not found解决办法

7. 安装opencv

这里就简单了

依赖:opencv2.4版本以上
为达到减少验证工作量的目的,这里样例在ubuntu16.04上验证基本功能,安装opencv使用apt工具,安装步骤如下:

$ sudo apt update 
$ sudo apt install libopencv-dev python-opencv

安装结束。检查一下是否安装成功:

$ pkg-config --modversion opencv

结果输出:

2.4.9.1

最后检测版本如果报错,记得在~/.bashrc 添加环境变量。
或者直接export PKG_CONFIG_PATH=/path/of/opencv.pc

不太懂的,可以参考这个地址


参考链接

  1. 下载地址1:https://ffmpeg.org/download.html#releases
  2. 下载地址3:https://pkgs.org/download/ffmpeg
  3. 下载地址2,以及安装说明:http://www.linuxfromscratch.org/blfs/view/svn/multimedia/ffmpeg.html
  4. ffmpeg使用博客:https://blog.csdn.net/leixiaohua1020
  5. https://www.it399.com/blog/ffmpeg/201807011604
  6. https://blog.csdn.net/openswc/article/details/52575742
  7. https://www.jianshu.com/p/ec941193ac79?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation
  8. https://blog.csdn.net/zhangwu1241/article/details/52354604
  9. https://prateekvjoshi.com/2013/10/18/package-opencv-not-found-lets-find-it/
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值