ubuntu下opencv+ffmpeg安装 以及错误处理

ubuntu 下读取视频失败:Error opening video stream or file
发现原因在与opencv编译过程中没有ffmpeg
所以重装opencv

由于anaconda和系统自带python的冲突,会有很多问题,详见我的下一篇博文https://blog.csdn.net/zhulinmanbu114/article/details/90512221

参考:
https://blog.csdn.net/miss_ju/article/details/60325868

(必须先装ffmpeg再安装opencv)

安装ffmpeg

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd source_directory
./configure --enable-shared --disable-static --prefix=/usr/local/ffmpeg //自己想要存放的地方
make
sudo make install

检查是否安装成功

ffmpeg -version

安装过程中出现问题:

  1. Inspiron-3670:~/ffmpeg$ ./configure --enable-shared --disable-static

nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “ffbuild/config.log” produced by configure as this will help
solve the problem.

解决办法: ./configure --enable-shared --disable-static --disable-x86asm

  1. ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory

解决办法参考:https://blog.csdn.net/zhouxj0818/article/details/52679741

sudo vi /etc/ld.so.conf

修改如下

include ld.so.conf.d/*.conf
/usr/local/ffmpeg/lib ///usr/local/ffmpeg 目录是ffmpeg安装目录

然后

sudo ldconfig

为 Ffmpeg 加入环境变量

vi /etc/profile

加入以下内容:

export PATH="/usr/local/ffmpeg/bin:$PATH"

然后保存并运行

source /etc/profile

安装opencv

安装之前要先装好一堆依赖包,参考官网 http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html

install essential packages
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

安装:

git clone https://github.com/opencv/opencv.git
cd source_directory
mkdir release
cd release
sudo cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_FFMPEG=ON
make
sudo make install

另:过程中download ippicv_linux_20151201失败,则需要手动下载ippicv_linux_20151201
参考 http://blog.csdn.net/huangkangying/article/details/53406370

opencv make过程中出现错误:

/usr/bin/ld: warning: libpng16.so.16, needed by /home/andrei/anaconda/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_create_read_struct@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_interlace_handling@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_IHDR@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_get_io_ptr@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_longjmp_fn@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_gray_to_rgb@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_compression_level@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_bgr@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_filter@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_rgb_to_gray@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_init_io@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_destroy_read_struct@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_swap@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_get_IHDR@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to png_set_palette_to_rgb@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to png_set_compression_strategy@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to png_get_tRNS@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_write_info@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_packing@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_read_fn@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_create_info_struct@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_read_end@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_read_update_info@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_write_image@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_write_end@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_expand_gray_1_2_4_to_8@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_create_write_struct@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_read_image@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_read_info@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_strip_alpha@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_write_fn@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_destroy_write_struct@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_error@PNG16_0’
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to ‘png_set_strip_16@PNG16_0’

解决办法:

  1. cd /usr/lib/x86_64-linux-gnu
  2. sudo ln -s ~/anaconda/lib/libpng16.so.16 libpng16.so.16
  3. sudo ldconfig
  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值