当前位置:   article > 正文

opencv 编译安装时出现报错 modules/videoio/src/cap_ffmpeg_impl.hpp:585:34: error: ‘AVStream {aka struct AVStre_error: no member named 'codec' in 'avstream

error: no member named 'codec' in 'avstream

jetson nano上尝试用python调用.so文件,但是报错,报错信息显示是opencv出现问题,遂决定重装opencv。先是编译opencv 3.4.10,报错,后面又重装之前的opencv 4.1.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
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

报错信息还有很多,但是均指向同一个文件modules/videoio/src/cap_ffmpeg_impl.hpp,考虑ffmpeg出现问题。

2. 报错原因

参考opencv官方论坛上的回答
在这里插入图片描述
在这里插入图片描述
报错原因为ffmpeg版本过高,解决方法为安装ffmpeg 4.4及以前版本。

3. 卸载当前ffmpeg

参考博客《Ubuntu16.04卸载旧的ffmpeg安装新的ffmpeg》

3.1. 卸载apt安装的ffmpeg

如果用apt-get install ffmpeg安装的,使用以下命令卸载

sudo apt-get --purge remove ffmpeg
sudo apt-get --purge autoremove
  • 1
  • 2
3.2. 卸载编译安装的ffmpeg

以ffmpeg-4.1为例,进入ffmpeg安装目录,如下

cd ffmpeg-4.1
make uninstall  ##删除由make install命令安装的文件
make clean  ##只删除make时产生的临时文件
make distclean  ##同时删除configure和make产生的临时文件
  • 1
  • 2
  • 3
  • 4
4. 编译安装ffmpeg 4.3

参考博客《Jetson 环境安装(三):jetson nano配置ffmpeg和nginx(亲测)》

4.1. 下载安装包

这里,我把安装包下载在~/Downloads/路径下,并解压

wget http://www.ffmpeg.org/releases/ffmpeg-4.3.tar.gz
tar -zxvf ffmpeg-4.3.tar.gz
  • 1
  • 2
4.2. 安装依赖

如下

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

注意,如果安装报错,考虑更换源,我的源如下

# 默认注释了源码镜像以提高 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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
4.3. 编译安装

这里,我们把~/Downloads/中已经解压的ffmpeg-4.3文件夹移入到/opt/路径下

cd ~/Downloads
sudo mv -f ffmpeg-4.3 /opt/
  • 1
  • 2

然后进入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
  • 1
  • 2
  • 3

然后配置全局环境变量

sudo vim /etc/profile
  • 1

在最后加入

export FFMPEG_HOME=/usr/local/ffmpeg
export PATH=$FFMPEG_HOME/bin:$PATH
  • 1
  • 2

保存,退出,并输入

source /etc/profile
  • 1

将ffmpeg添加进动态库目录,如下

sudo vim /etc/ld.so.conf.d/ffmpeg.conf 
  • 1

添加如下内容

/usr/local/ffmpeg/lib
  • 1

配置生效

ldconfig
  • 1
4.4. 测试ffmpeg
ffmpeg -version
  • 1

输出如下内容即可
在这里插入图片描述

5. 编译安装opencv 4.1.1

参考博客《jetson nano和jetson nx 重装opencv(opencv4.1.1+opencv-contrib安装)》

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/539505
推荐阅读
相关标签
  

闽ICP备14008679号