赞
踩
在jetson nano上尝试用python调用.so文件,但是报错,报错信息显示是opencv出现问题,遂决定重装opencv。先是编译opencv 3.4.10,报错,后面又重装之前的opencv 4.1.1,居然依旧报错。遂记录。
无论是opencv的3.4.10还是4.1.1,均报同样的错,所以肯定不是opencv的问题。
报错如下
/opt/opencv4/opencv-4.1.1/modules/videoio/src/cap_ffmpeg_impl.hpp:585:34: error: ‘AVStream {aka struct AVStream}’ has no member named ‘codec’ avcodec_close( video_st->codec ); ^~~~~ /opt/opencv4/opencv-4.1.1/modules/videoio/src/cap_ffmpeg_impl.hpp: At global scope: /opt/opencv4/opencv-4.1.1/modules/videoio/src/cap_ffmpeg_impl.hpp:775:39: error: ‘AVLockOp’ has not been declared static int LockCallBack(void **mutex, AVLockOp op) ^~~~~~~~ /opt/opencv4/opencv-4.1.1/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘int LockCallBack(void**, int)’: /opt/opencv4/opencv-4.1.1/modules/videoio/src/cap_ffmpeg_impl.hpp:780:14: error: ‘AV_LOCK_CREATE’ was not declared in this scope case AV_LOCK_CREATE: ^~~~~~~~~~~~~~ /opt/opencv4/opencv-4.1.1/modules/videoio/src/cap_ffmpeg_impl.hpp:780:14: note: suggested alternative: ‘AV_LOG_TRACE’ case AV_LOCK_CREATE: ^~~~~~~~~~~~~~ AV_LOG_TRACE /opt/opencv4/opencv-4.1.1/modules/videoio/src/cap_ffmpeg_impl.hpp:789:14: error: ‘AV_LOCK_OBTAIN’ was not declared in this scope case AV_LOCK_OBTAIN: ^~~~~~~~~~~~~~ /opt/opencv4/opencv-4.1.1/modules/videoio/src/cap_ffmpeg_impl.hpp:789:14: note: suggested alternative: ‘CLOCK_TAI’ case AV_LOCK_OBTAIN: ^~~~~~~~~~~~~~ CLOCK_TAI ...
报错信息还有很多,但是均指向同一个文件modules/videoio/src/cap_ffmpeg_impl.hpp
,考虑ffmpeg
出现问题。
参考opencv官方论坛上的回答
报错原因为ffmpeg版本过高,解决方法为安装ffmpeg 4.4及以前版本。
参考博客《Ubuntu16.04卸载旧的ffmpeg安装新的ffmpeg》
如果用apt-get install ffmpeg
安装的,使用以下命令卸载
sudo apt-get --purge remove ffmpeg
sudo apt-get --purge autoremove
以ffmpeg-4.1为例,进入ffmpeg安装目录,如下
cd ffmpeg-4.1
make uninstall ##删除由make install命令安装的文件
make clean ##只删除make时产生的临时文件
make distclean ##同时删除configure和make产生的临时文件
参考博客《Jetson 环境安装(三):jetson nano配置ffmpeg和nginx(亲测)》
这里,我把安装包下载在~/Downloads/
路径下,并解压
wget http://www.ffmpeg.org/releases/ffmpeg-4.3.tar.gz
tar -zxvf ffmpeg-4.3.tar.gz
如下
sudo apt-get install -y nasm yasm cmake mercurial
sudo apt-get install -y libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev
sudo apt-get install -y libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev
sudo apt-get install -y libfreetype6-dev libsdl2-dev libtheora-dev
sudo apt-get install -y autoconf automake build-essential git libass-dev
sudo apt-get install libx264-dev
sudo apt-get install libx265-dev libnuma-dev
sudo apt-get install libvpx-dev
注意,如果安装报错,考虑更换源,我的源如下
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic main restricted universe multiverse # deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-updates main restricted universe multiverse # deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-updates main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-backports main restricted universe multiverse # deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-backports main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-security main restricted universe multiverse # deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-security main restricted universe multiverse # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.aliyun.com/ubuntu-ports/ bionic main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-updates main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-updates main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-backports main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu-ports/s bionic-backports main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-security main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
这里,我们把~/Downloads/中已经解压的ffmpeg-4.3
文件夹移入到/opt/路径下
cd ~/Downloads
sudo mv -f ffmpeg-4.3 /opt/
然后进入ffmpeg-4.3,编译
cd /opt/ffmpeg-4.3
sudo ./configure --enable-shared --enable-libx264 --enable-gpl --enable-libx265 --prefix=/usr/local/ffmpeg
sudo make && sudo make install
然后配置全局环境变量
sudo vim /etc/profile
在最后加入
export FFMPEG_HOME=/usr/local/ffmpeg
export PATH=$FFMPEG_HOME/bin:$PATH
保存,退出,并输入
source /etc/profile
将ffmpeg添加进动态库目录,如下
sudo vim /etc/ld.so.conf.d/ffmpeg.conf
添加如下内容
/usr/local/ffmpeg/lib
配置生效
ldconfig
ffmpeg -version
输出如下内容即可
参考博客《jetson nano和jetson nx 重装opencv(opencv4.1.1+opencv-contrib安装)》
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。