android 虚拟机开摄像头 虚拟机如何开启摄像头_ffmpeg

android 虚拟机开摄像头 虚拟机如何开启摄像头_Time_02

android 虚拟机开摄像头 虚拟机如何开启摄像头_Time_03

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
 

同时一个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等。