如何使用 FFMPEG 驱动程序使 opencv 工作

2024-02-27

我的 linuxbox 上有一个摄像头,它运行良好:

# $ ls -al /dev/video*
# crw-rw----+ 1 root video 81, 0 janv.  8 16:13 /dev/video0
# crw-rw----+ 1 root video 81, 1 janv.  8 16:13 /dev/video1
# $ groups
# adm cdrom sudo dip video plugdev lpadmin lxd sambashare docker libvirt

来自带有 cv2 的 python,它可以与默认驱动程序很好地配合CAP_V4L2

>>> from pathlib import Path
>>> import cv2
>>> print(cv2.VideoCapture(0, apiPreference=cv2.cv2.CAP_V4L2).isOpened())
True
>>>

我想用 FFMPEG 驱动程序访问它(没有成功):

>>> print(cv2.VideoCapture(0, apiPreference=cv2.CAP_FFMPEG).isOpened())
False
>>>

从Python方面来看,opencv看起来有FFMPEG驱动程序:

  >>> cv2.__version__
  '4.4.0'
  >>> info = cv2.getBuildInformation()
  >>> video, parallel = info.index('Video'), info.index('Parallel')
  >>> print(info[video:parallel])
  Video I/O:
       DC1394:                      NO
       FFMPEG:                      YES
         avcodec:                   YES (58.109.100)
         avformat:                  YES (58.61.100)
         avutil:                    YES (56.60.100)
         swscale:                   YES (5.8.100)
         avresample:                NO
       GStreamer:                   NO
       v4l/v4l2:                    YES (linux/videodev2.h)
  >>>

从 Linux 方面看也不错:

$ dpkg -l |grep -i opencv
ii  libopencv-core4.2:amd64                    4.2.0+dfsg-5                          amd64        computer vision core library
ii  libopencv-imgcodecs4.2:amd64               4.2.0+dfsg-5                          amd64        computer vision Image Codecs library
ii  libopencv-imgproc4.2:amd64                 4.2.0+dfsg-5                          amd64        computer vision Image Processing library
ii  libopencv-videoio4.2:amd64                 4.2.0+dfsg-5                          amd64        computer vision Video I/O library

$ dpkg -l |grep -i ffm
ii  ffmpeg                                     7:4.2.4-1ubuntu0.1                    amd64        Tools for transcoding, streaming and playing of multimedia files
ii  gstreamer1.0-libav:amd64                   1.16.2-2                              amd64        ffmpeg plugin for GStreamer
ii  libavcodec-extra:amd64                     7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library with extra codecs (metapackage)
ii  libavcodec-extra58:amd64                   7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library with additional de/encoders for audio/video codecs
ii  libavdevice58:amd64                        7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library for handling input and output devices - runtime files
ii  libavfilter7:amd64                         7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library containing media filters - runtime files
ii  libavformat58:amd64                        7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library with (de)muxers for multimedia containers - runtime files
ii  libavresample4:amd64                       7:4.2.4-1ubuntu0.1                    amd64        FFmpeg compatibility library for resampling - runtime files
ii  libavutil56:amd64                          7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library with functions for simplifying programming - runtime files
ii  libffmpegthumbnailer4v5                    2.1.1-0.2build2                       amd64        shared library for ffmpegthumbnailer
ii  libpostproc55:amd64                        7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library for post processing - runtime files
ii  libswresample3:amd64                       7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library for audio resampling, rematrixing etc. - runtime files
ii  libswscale5:amd64                          7:4.2.4-1ubuntu0.1                    amd64        FFmpeg library for image scaling and various conversions - runtime files
$

OpenCV 是否使用 FFMPEG 从相机进行捕获?我认为它适用于文件(或流),因为 VideoCapture 既用于相机又用于文件/流。

在我的 Windows 设置中,用作从相机捕获的接口的 FFMPEG 也不起作用(但例如 CAP_DSHOW 有效),而作为文件的编解码器,它会读取帧:

cap = cv2.VideoCapture("..\\ooo.mp4", apiPreference=cv2.CAP_FFMPEG) # OK


>>> print(cv2.VideoCapture(0, apiPreference=cv2.CAP_FFMPEG).isOpened())
False
>>> print(cv2.VideoCapture(0, apiPreference=cv2.CAP_DSHOW).isOpened())
True


import cv2
# cap = cv2.VideoCapture(0, apiPreference=cv2.CAP_FFMPEG) # prints "ERROR"
cap = cv2.VideoCapture(0, apiPreference=cv2.CAP_DSHOW)  # OK, shows an image
ret, fr = cap.read()
if ret: cv2.imshow("FR", fr)
else: print("ERROR")
cv2.waitKey(0)

也可以看看:https://trac.ffmpeg.org/wiki/Capture/Webcam https://trac.ffmpeg.org/wiki/Capture/Webcam

"Linux

使用 video4linux2(或简称 v4l2)输入设备捕获实时视频 输入,例如来自网络摄像头的输入。请参阅 v4l2 输入设备文档 了解更多信息。 ”

对于 Windows,FFMPEG 被提到使用 DirectShow,如我的测试所示:

>Windows
>dshow
>
>Uses the dshow (DirectShow) input device which is the preferred option for
>Windows users. 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 FFMPEG 驱动程序使 opencv 工作 的相关文章

随机推荐

  • MSBuild BuildInParallel,自定义任务生成进程无法运行

    我使用 MSBuild 任务的 BuildInParallel 属性来并行运行生成项目 根项目正在构建四个子项目 子项目使用自定义 MSBuild 任务 该任务使用 System Diagnostics Process 启动新进程 由于某种
  • 在不违反约束的情况下交换两个数据库行

    我有一张桌子regionkey areaid primary key int region char 4 locale char 4 数据库的整个其余部分都是areaid 的外键 在此表中 有一个关于 region locale 的索引 具
  • Textview - 最大长度不适用于椭圆

    我正在尝试创建一个文本视图 以便如果字符数超过 22 则显示省略号 会出现 然而 这不适用于 maxLength
  • 避免在未像素对齐的平铺 SVG 矩形之间出现线条

    我附近有几个rect就像在这个问题 https stackoverflow com questions 13049336 avoid line between tiled svg shapes 但未与像素对齐 我无法更改元素位置 例如 ht
  • 使用带有 Locust 的多 CPU 平台

    I am running htop on the same machine where locust is running during the tests I have been running this morning I see on
  • Xamarin.Forms.WebView 初始加载指示器

    对我来说 采用 Xamarin 表单 WebView 并为第一次加载添加加载进度条的最简单方法是什么 我的应用程序只是包装了一个网站 但在带宽较差的情况下 当启动屏幕消失并且 WebView 正在加载其内容时 我当然会看到白屏 我想看到一个
  • 如何首先在 Entity Framework 5 代码中使用两个外键创建主键?

    我有一个实体 其中主键由另外两个表的两个外键组成 我的配置使用以下内容 但该表是使用两个 FK 引用生成的 桌子 domain Entity1 MorePK PK FK int not null Entity2 Id PK FK int n
  • 禁用 AngularJS 中不需要的验证(条件验证)

    我有一份需要验证的表格 该表单包含许多部分 其中一些部分默认情况下处于禁用状态 每个字段中的值都是正确的 但它违反了我的验证指令 例如 当它被禁用时 它应该包含 0 但是当它可编辑时 它应该包含其他内容 不管怎样 我给它们附加了一个禁用指令
  • C/C++ 中的鲁棒人脸检测?

    我正在寻找一个强大的人脸检测算法 库 最好是 C 语言 C 也可以 如果需要 我可以移植其他语言 我用过OpenCV http opencv willowgarage com 过去的实现 但我不认为它对于轮换是不变的 不需要是实时的 但也不
  • 将 c# 正则表达式转换为 javascript 正则表达式

    使用 C 正则表达式可以使用以下正则表达式
  • 无法从 Cherrypy 将日期时间序列化为 JSON

    我正在尝试发送记录列表以响应 Ajax 查询 这很有效 除非当我的进程因错误而失败时结果包含日期时间字段datetime date 2011 11 1 is not JSON serializable 我试图将我找到的答案结合起来类似的问题
  • 关闭 Google 地图本地点

    我目前有一个网络应用程序 它使用地图 API 绘制兴趣点 但是我注意到一个小烦恼 如果可能的话我想将其关闭 现在 当谷歌地图加载时 它将显示兴趣点和当地商业 市政厅 必胜客等 我不介意标记它们的措辞 但我不希望这些点可点击 就好像使用触摸屏
  • CSS 动画延迟不起作用

    尝试淡入一个 div 7 秒后 淡入另一个 div 我一生都无法弄清楚为什么它不起作用 动画本身可以工作 淡入 淡出动画 但我需要 正在进行的 div 在设定的秒数后淡入 有人知道如何正确执行此操作吗 coming width 320px
  • Android:使用 onClick 更改 ListView 行中的按钮背景

    我的行包含一个按钮 该按钮在我的适配器的 getView 中设置了自己的单击侦听器 我可以使用行父级中的 android descendantFocusability blocksDescendants 来区分按钮点击和实际行项目点击 当我
  • 如何从 pandas 的第一个元素开始重新采样?

    我正在对下表 数据进行重新采样 Timestamp L x L y L a R x R y R a 2403950 621 3 461 3 313 623 3 461 8 260 2403954 622 5 461 3 312 623 3
  • Python 文档字符串中的字符串操作

    我一直在尝试做以下事情 def history dependent simulate self node iterations 1 args kwargs For history dependent simulations only sel
  • Windows 版 Git 不执行我的 .bashrc 文件

    我刚刚在 Windows 7 上安装了 Git for Windows 2 5 0 看来我的 bashrc当我运行 Git Bash 时 文件没有被执行 我像这样创建了文件 Administrator HintTech Dev MINGW6
  • 如何在 Visual Studio 2010 中查看二维数组的所有元素?

    我正在 Visual Studio 2010 中调试我的 C 代码 并希望查看数组的内容 例如 Q 它的大小为 17x17 当我插入断点并尝试调试时 我只看到变量 Q 当我将其带到 观看 屏幕并将其重命名为 Q 17 时 我看到下一级 但我
  • 从解析中删除类/列时出现问题

    我试图从解析中删除一些不需要的列 我不断收到以下错误 错误 类名 Session 必须以字母解析开头 不确定为什么会发生这种情况 或者这是否是一个错误 当我删除一个类时 我也会收到此错误 有没有解决的办法 UPDATE 我刚刚尝试过 我能够
  • 如何使用 FFMPEG 驱动程序使 opencv 工作

    我的 linuxbox 上有一个摄像头 它运行良好 ls al dev video crw rw 1 root video 81 0 janv 8 16 13 dev video0 crw rw 1 root video 81 1 janv