虚拟机使用pc摄像头

2023-05-16

ffmpeg是音视频必备,笔者VX:YQW1163720468,ffmpeg群讨论。注:ffmpeg爱好者

1.win+r打开运行。
2.在运行中键入services.msc回车,打开服务。
3.右边下拉找到VMware Authorization Service。
4.双击打开属性,启动类型->自动,点击驱动,点击应用,点击确定。这个时候已经授权虚拟机能访问到摄像头了。
5.打开虚拟机,点击"虚拟机"->可移动设备,找到摄像头camera,点击链接。此时虚拟机完成对摄像头的接管。
6.查看在/dev/下有video的文件。

安装cheese,打开摄像头:

sudo apt-get install cheese

在终端输入cheese回车->此时可以看到打开的摄像头。

查看设备类型

ffmpeg  -devices

可以看到有video4linux2,v4l2这个选项
“ v4l2”可以用作“ video4linux2”的别名。
alsa是音频类型,见另一篇:虚拟机使用pc麦克风声卡

根据设备类型查看具体设备名

ffmpeg -sources video4linux2

ffmpeg -sources v4l2

可以看到有这两个设备,这两个设备对应pc的摄像头

 /dev/video1 [Integrated Camera: Integrated I]
 /dev/video0 [Integrated Camera: Integrated C]

用命令打开摄像头,另一个不能用来打开

ffplay -f video4linux2 -video_size 640x480 -pixel_format yuyv422 -framerate 30 -i /dev/video0

查看设备输入输出参数

ffmpeg -h demuxer=v4l2 

如查看都支持哪些像素格式

ffplay -f video4linux2 -list_formats all  /dev/video0

这些选项也可以用代码设置,"video_size"等名称与ffmpeg -h demuxer=v4l2 命令列举的名称一样。
AVDictionary *options = NULL;
av_dict_set(&options, “video_size”, “1920x1080”, 0);
av_dict_set(&options, “framerate”, “30”, 0);
//以上参数如果不设置的话,ffmpeg就会用默认值,但默认值摄像头不一定支持
int re = avformat_open_input(&ic, “/dev/video0”, ifmt, &options);

其次对于显示在/dev/video中的摄像头其实都是支持UVC协议的摄像头,一般说摄像头免驱动也是基于UVC开发的,我们可以用luvcview这款软件查看所有基于UVC的摄像头的信息,对于ubuntu12,可以直接执行下列命令安装,因为当时是为ubuntu12设计的:
sudo apt-get install luvcview
对于其他版本,可以到官网下载deb包安装,连接:
luvcview_0.2.6-5_amd64.deb (52.3 KiB)
安装好后
打开摄像头

luvcview -l

打开摄像头

luvcview -d /dev/video1 -f yuv -s 640x480

查看设备支持的像素格式和帧率

luvcview -d /dev/video0 -L

可以看到支持的像素格式:MJPG YUYV RGB3 BGR3 YU12 YV12
Time interval between frame: 1/30 也就是帧间的时间间隔,也就是帧率了。

luvcview 0.2.6

SDL information:
  Video driver: x11
  A window manager is available
Device information:
  Device path:  /dev/video0
{ pixelformat = 'MJPG', description = 'Motion-JPEG' }
{ discrete: width = 1280, height = 720 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 180 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 352, height = 288 }
	Time interval between frame: 1/30, 
{ discrete: width = 424, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 360 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 480 }
	Time interval between frame: 1/30, 
{ discrete: width = 848, height = 480 }
	Time interval between frame: 1/30, 
{ discrete: width = 960, height = 540 }
	Time interval between frame: 1/30, 
{ pixelformat = 'YUYV', description = 'YUYV 4:2:2' }
{ discrete: width = 640, height = 480 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 180 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 352, height = 288 }
	Time interval between frame: 1/30, 
{ discrete: width = 424, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 360 }
	Time interval between frame: 1/30, 
{ discrete: width = 848, height = 480 }
	Time interval between frame: 1/20, 
{ discrete: width = 960, height = 540 }
	Time interval between frame: 1/15, 
{ discrete: width = 1280, height = 720 }
	Time interval between frame: 1/10, 
{ pixelformat = 'RGB3', description = 'RGB3' }
{ discrete: width = 1280, height = 720 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 180 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 352, height = 288 }
	Time interval between frame: 1/30, 
{ discrete: width = 424, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 360 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 480 }
	Time interval between frame: 1/30, 
{ discrete: width = 848, height = 480 }
	Time interval between frame: 1/20, 
{ discrete: width = 960, height = 540 }
	Time interval between frame: 1/30, 
{ pixelformat = 'BGR3', description = 'BGR3' }
{ discrete: width = 1280, height = 720 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 180 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 352, height = 288 }
	Time interval between frame: 1/30, 
{ discrete: width = 424, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 360 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 480 }
	Time interval between frame: 1/30, 
{ discrete: width = 848, height = 480 }
	Time interval between frame: 1/20, 
{ discrete: width = 960, height = 540 }
	Time interval between frame: 1/30, 
{ pixelformat = 'YU12', description = 'YU12' }
{ discrete: width = 1280, height = 720 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 180 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 352, height = 288 }
	Time interval between frame: 1/30, 
{ discrete: width = 424, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 360 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 480 }
	Time interval between frame: 1/30, 
{ discrete: width = 848, height = 480 }
	Time interval between frame: 1/20, 
{ discrete: width = 960, height = 540 }
	Time interval between frame: 1/30, 
{ pixelformat = 'YV12', description = 'YV12' }
{ discrete: width = 1280, height = 720 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 180 }
	Time interval between frame: 1/30, 
{ discrete: width = 320, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 352, height = 288 }
	Time interval between frame: 1/30, 
{ discrete: width = 424, height = 240 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 360 }
	Time interval between frame: 1/30, 
{ discrete: width = 640, height = 480 }
	Time interval between frame: 1/30, 
{ discrete: width = 848, height = 480 }
	Time interval between frame: 1/20, 
{ discrete: width = 960, height = 540 }
	Time interval between frame: 1/30,
ffplay -f video4linux2 -framerate 60 -video_size 1920x1080 -pixel_format mjpeg  -i /dev/video4

用mjpeg的方式播放,并设置帧率。

如果你想把其他的raw流放入/dev/video设备中,也是可以用ffmpeg推流的:

ffmpeg -f x11grab -r 15 -s 1280x720 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0

以上把屏幕推流到/dev/video0上,但video0是必须是虚拟设备,不对应实际device
如何设置虚拟/dev/video参考:https://www.cnblogs.com/xl2432/p/13501145.html

同时一个device可以对应多个输入源,比如/dev/video0可以对应两个输入源通道,也就是它在硬件上可以对应两个usb输入口,用下面代码切换通道,-d 2代表指定/dev/video2

v4l2-ctl -d 2 -i 4

查看驱动各种信息,如色域等,色域一般为Rec. 709,这个在笔者其他博客有介绍,-d 2指定usb设备
v4l2-ctl -DVI --get-parm -d 2

Driver Info:
	Driver name      : uvcvideo
	Card type        : USB Video: USB Video
	Bus info         : usb-0000:00:14.0-3.1
	Driver version   : 5.19.0
	Capabilities     : 0x84a00001
		Video Capture
		Metadata Capture
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps      : 0x04200001
		Video Capture
		Streaming
		Extended Pix Format
Media Driver Info:
	Driver name      : uvcvideo
	Model            : USB Video: USB Video
	Serial           : 
	Bus info         : usb-0000:00:14.0-3.1
	Media version    : 5.19.0
	Hardware revision: 0x00002100 (8448)
	Driver version   : 5.19.0
Interface Info:
	ID               : 0x03000002
	Type             : V4L Video
Entity Info:
	ID               : 0x00000001 (1)
	Name             : USB Video: USB Video
	Function         : V4L2 I/O
	Flags            : default
	Pad 0x01000007   : 0: Sink
	  Link 0x0200000d: from remote pad 0x100000a of entity 'Processing 2' (Video Pixel Formatter): Data, Enabled, Immutable
Video input : 0 (Camera 1: ok)
Format Video Capture:
	Width/Height      : 1920/1080
	Pixel Format      : 'MJPG' (Motion-JPEG)
	Field             : None
	Bytes per Line    : 0
	Size Image        : 4147200
	Colorspace        : sRGB
	Transfer Function : Rec. 709
	YCbCr/HSV Encoding: ITU-R 601
	Quantization      : Default (maps to Full Range)
	Flags             : 
Streaming Parameters Video Capture:
	Capabilities     : timeperframe
	Frames per second: 30.000 (30/1)
	Read buffers     : 0

补充:
ffmpeg的libavdevice模块支持的计算机中常用的音视频捕获或输出设备:ALSA、AUDIO_BEOS 、JACK、OSS、1394、VFW等。

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

虚拟机使用pc摄像头 的相关文章

  • OpenCV计算机视觉库,Tensorflow深度学习框架

    OpenCV是计算机视觉库 xff0c 包含了大量的图像处理和计算机视觉的算法 xff0c 但是在机器学习方面明显不足 xff0c ML模块只有SVM xff0c MLP xff0c kNN等有限的几种算法 dnn模块也是调用别的框架 Te
  • 动态库和静态库

    概念 什么是库 库是写好的 xff0c 现有的 xff0c 成熟的 xff0c 可以复用的代码 现实中每个程序都要依赖很多基础的底层库 xff0c 不可能每个人的代码都从零开始 xff0c 因此库的存在意义非同寻常 本质上来说 xff0c
  • Linux 内核设计与实现 —— 1.内核简介

    文章目录 操作系统和内核简介内核包括 xff1a 内核与应用程序 xff1a 内核与硬件设备 xff1a 内核的运行模式 xff1a Linux内核与Unix内核比较单内核与微内核设计之比较Linux内核与Unix内核差异 操作系统和内核简
  • VIM基础操作

    方向键 xff1a hjkl输入 向后输入 xff1a a shift最前向前输入 xff1a i shift最后向下新生成一行输入 xff1a o shift上一行删掉当前字符并写入 xff1a s 撤销 xff1a u键盘重映设 vim
  • Git基础操作

    Git基础操作 仓库配置初始化仓库查看当前所在仓库修改远端仓库 代码提交基础操作tag操作删除最后N次提交储藏 代码管理分支操作patch操作查看指定文件的修改历史统计代码量 仓库配置 初始化仓库 1 xff0c 安装 sudo apt g
  • Google SRE 自我评分——《Google SRE: How Google runs production systems》

    Google SRE How Google runs production systems 0 xff1a you are unfamiliar with the subject area 0 xff1a 不熟悉的领域 也就是说对相关的领域
  • java基础之byte转换工具类

    1 Byte 转 byte public static byte toPrimitives Byte oBytes byte bytes 61 new byte oBytes length for int i 61 0 i lt oByte
  • VLAN技术

    大家好呀 xff0c 我是请假君 xff0c 今天又来和大家一起学习数通了 xff0c 今天要分享的知识是VLAN技术 介绍VLAN之前先来了解一下广播风暴 xff1a 在交换式以太网出现后 xff0c 同一个交换机下不同的端口处于不同的冲
  • shell基础操作

    shell基础操作 有待补充基础操作基础素养 使用需要转译的字符休眠账户密码权限管道清屏让命令在后台运行黑洞 硬件查看显示分辨率 软件删除软件和配置文件 文件操作复制 目录返回上一次目录 查找findgrep 文件夹大小对比文件类型删除文件
  • makefile基础

    makefile基础 编译和链接makefile基础格式clean的写法makefile构成使用其他的makefile引用其他的makefile引用方式makefile 查找方式 make 的工作方式添加define警告编译不过 编译和链接
  • DHCP协议

    DHCP协议 动态主机设置协议 xff0c 使用UDP协议工作用途 自动分配IP管理 服务器端使用67 udp xff0c 客户端使用68 udp基本过程 请求IP租约 xff08 discover xff09 客户端广播 xff0c 服务
  • Linux驱动程序概述

    怎么写驱动 看原理图写驱动写测试程序 流程 分配file operations结构体设置结构体成员 open 61 led open 配置为输出引脚 wirte 61 led write 设置引脚状态 注册 xff08 告诉内核 xff09
  • Linux boot API

    Linux boot API 代码主控头文件U BOOT CMD 终端命令sf nand xff08 nor nand flash xff09 具体用法使用范例 setenv 命令 代码 主控头文件 boot主逻辑在此 xff0c 以Ing
  • dash与bash

    dash与bash 背景dash与bash的区别shell配置错误的可能特征坑 xff01 xff01 xff01 查看shell真实配置切换 背景 平台Linux编译 xff0c 可能会遇到脚本设置类型不同 xff08 如 xff1a 芯
  • Linux 基础概念

    文章目录 POSIX动态库和静态库ioctl MCU架构RISC与CISCx86 ARM MIPS架构 U bootBootloader 两种模式主机和板子的传输方式启动顺序bootloader两个阶段U Boot 移植 分区Linux s
  • rosdep update遇到ERROR: error loading sources list: The read operation timed out问题

    链接 xff1a https blog csdn net DDonggggg article details 115798335
  • C++ HTTP实现

    文章目录 一 HTTP基础知识1 什么是Http协议 xff1a 2 常见HTTP头3 HTTP请求头概述 xff08 HttpServletRequest xff09 4 URL格式详解 xff1a 二 WinHttp入门及实战1 介绍2
  • ros+ Optitrack控制bebop2无人机

    准备工作 xff1a Motive的安装及使用 xff1a https blog csdn net weixin 41536025 article details 89913961 ros订阅 OptiTrack 的消息通过vrpn cli

随机推荐

  • stm32中typedef的用法

    C语言允许用户使用 typedef 关键字来定义自己习惯的数据类型名称 xff0c 来替代系统默认的基本类型名称 数组类型名称 指针类型名称与用户自定义的结构型名称 共用型名称 枚举型名称等 一旦用户在程序中定义了自己的数据类型名称 xff
  • Python系列 49 内置模块:subprocess

    subprocess简介 subprocess模块最早在Python2 4中引入 xff0c 它会生成一个子进程 xff0c 该子进程可以执行shell命令 xff0c 并且会监听系统的标准输入管道 标准输出管道 标准错误管道 xff0c
  • python使用serial模块,通过串口控制云台(基于PELCO-D协议)

    一 需求描述 通过python实现对云台的控制 xff0c 使用到的相关模块 xff1a 1 pyserial xff0c 串口模块 xff0c 用于连接串口 xff0c 并通过串口发送指令 2 bytes xff0c 内置模块 xff0c
  • TP-LINK路由器如何设置上网

    1 登陆 xff0c 网址192 168 1 1 xff0c 登陆 xff0c 一般在路由器背后 xff0c 没有或者忘记就重置 2 设置导向 3 输入拨号 xff08 以太网 xff09 的账号密码 4 设置wifi账号密码 xff0c
  • (1+x)^(1/x)的导数

  • 电脑待机久了没有声音,需要重启才行

    这种原因一般是唤醒电脑后 xff0c 声卡驱动没有跟着苏醒导致 xff1b 方法一 xff1a 重启电脑 xff0c 简单粗暴 xff1b 方法二 xff1a 在设备器里面重启声音设备 xff0c 先禁用 xff0c 再重新 xff1b 也
  • Pycharm 中安装pywin32报错

    1 在pycharm的寻找并安装插件pywin32时报错 xff1b 大致意思是安装失败 xff0c 建议的解决方案 xff1a 尝试从系统终端运行此命令 确保使用正确的 pip 版本 xff0c 该版本已为位于如下地址 xff1a F p
  • win10下关闭笔记本自带键盘以及解锁

    win10下关闭笔记本自带键盘 管理员运行cmd sc config i8042prt start 61 disabled 重启 解除自带键盘锁定 1 sc config i8042prt start 61 auto xff0c 重启 xf
  • chatra无法注册

    chatra用QQ邮箱注册显示邮箱无法访问 xff0c 不知道是不是邮箱设置了还是这个网站不支持 xff1b 用163邮箱注册就成功了
  • 打开回收站提示“回收站已损坏是否清空该驱动器上的回收站“解决方法

    我们一般需要删除的文件或者文件夹都是删除在电脑系统中的回收站中的 xff0c 但是最近有一个网友在打开Win10系统的回收站的时候 xff0c 忽然弹出了提示 D xff1a 上的回收站已损坏 是否清空该驱动上的回收站 xff0c 一般遇到
  • C++之迭代器(Iterator)篇

    迭代器 xff08 Iterator xff09 的介绍 背景 xff1a 指针可以用来遍历存储空间连续的数据结构 xff0c 但是对于存储空间费连续的 xff0c 就需要寻找一个行为类似指针的类 xff0c 来对非数组的数据结构进行遍历
  • Sublime Text运行C和C++程序

    Sublime Text 是一款当下非常流行的文本编辑器 xff0c 其功能强大 xff08 提供有众多的插件 xff09 界面简洁 还支持跨平台使用 xff08 包括 Mac OS X Linux 和 Windows xff09 在程序员
  • c++ string find(), rfind(), find_first_of(),find_last_of()

    find rfind 函数原型 xff1a span class token keyword int span span class token function find span span class token punctuation
  • 1233. 删除子文件夹

    难度 xff1a 中等 你是一位系统管理员 xff0c 手里有一份文件夹列表 folder xff0c 你的任务是要删除该列表中的所有 子文件夹 xff0c 并以 任意顺序 返回剩下的文件夹 如果文件夹 folder i 位于另一个文件夹
  • 【ROS入门篇·一】ROS文件系统 & catkin编译系统

    快速链接 xff1a ROS入门篇 ROS学习简介 一 ROS工作空间创建 amp 编译 1 xff09 创建工作空间 mkdir p catkin ws src cd catkin ws src 2 xff09 创建功能包 catkin
  • 【ROS入门篇·五】launch文件使用 & 向节点传递参数

    快速链接 xff1a ROS入门篇 ROS学习简介 一 launch文件使用 1 1 launch文件简介 launch文件能够同时启动一个ROS Master和多个Node launch文件的标签 lt launch gt lt 根标签
  • 【ROS小车仿真·一】rviz中显示urdf模型

    快速链接 xff1a ROS小车仿真 从零实现gezebo小车仿真 一 urdf简介 URDF Unified Robot Description Format 统一机器人描述格式 xff0c URDF是使用XML格式描述机器人的文件 参考
  • 2.为什么要内存对齐?

    一 什么是内存对齐 xff08 Memory alignment xff09 xff0c 也叫字节对齐 在计算机中 xff0c 内存是按 字节 byte 1byte 61 8bit 划分的 xff0c 而cpu在读取内存数据时 xff0c
  • 问题笔记:STM32串口数据位与校验位

    问题 xff1a STM32移植freemodbus 后测试时 xff0c 只能使用无校验 xff0c 设置奇偶校验时无法与上位机通讯解决方法 如果串口助手使用串口配置为 xff1a 数据位8 停止位1 有奇偶校验 STM32需设置为 xf
  • 虚拟机使用pc摄像头

    1 win 43 r打开运行 2 在运行中键入services msc回车 xff0c 打开服务 3 右边下拉找到VMware Authorization Service 4 双击打开属性 xff0c 启动类型 gt 自动 xff0c 点击