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
安装过程中出现问题:
- 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
- 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’
解决办法:
- cd /usr/lib/x86_64-linux-gnu
- sudo ln -s ~/anaconda/lib/libpng16.so.16 libpng16.so.16
- sudo ldconfig