How to capture a webcam input Up-vote

130 篇文章 2 订阅
127 篇文章 4 订阅

转自:https://trac.ffmpeg.org/wiki/How%20to%20capture%20a%20webcam%20input

Windows

dshow

For windows you should probably use the "dshow" (DirectShow)FFmpeg input source. See DirectShow.

vfwcap

Windows users that can't use DirectShow can possibly use the (now out dated) vfwcap input device, like this:

To list the supported capture devices, connected to the machine:

ffmpeg -y -f vfwcap -i list

That will give us the list like this:

...
libavutil     50.36. 0 / 50.36. 0
libavcore      0.16. 1 /  0.16. 1
libavcodec    52.108. 0 / 52.108. 0
libavformat   52.93. 0 / 52.93. 0
libavdevice   52. 2. 3 / 52. 2. 3
libavfilter    1.74. 0 /  1.74. 0
libswscale     0.12. 0 /  0.12. 0
[vfwcap @ 01c6d150] Driver 0
[vfwcap @ 01c6d150]  Microsoft WDM Image Capture (Win32)
[vfwcap @ 01c6d150]  Version:  5.1.2600.5512
list: Input/output error

So, we can try to grab something from our camera:

ffmpeg -y -f vfwcap -r 25 -i 0 out.mp4

Where "-i 0" is the index (zero based) in the list of present capture devices ("Driver 0" in this instance).

Linux

On Linux, we can use video4linux2 (or shortly "v4l2") input device to capture live input (such as web camera), like this:

ffmpeg -f video4linux2 -r 25 -s 640x480 -i /dev/video0 out.avi

or

ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi

If you need to set some specific parameters of your camera, you can do that usingv4l2-ctl tool.

http://linuxtv.org/downloads/v4l-utils/这里可以下载源码

You can find it in the fedora/ubuntu/debian package named v4l-utils.

Most probably you'll want to know what frame sizes / frame rates your camera supports and you can do that using:v4l2-ctl --list-formats-ext

Also, you might want to correct brightness, zoom, focus, etc. with:

v4l2-ctl -L

and

v4l2-ctl -c <option>=<value>



# v4l2-ctl -d /dev/video0 -D
Driver Info (not using libv4l2):
Driver name : LINUXV4L2
Card type : SA7160:RAW 00.00
Bus info : PCI Bus 0000:04
Driver version: 1.0.0
Capabilities : 0x04000001
Video Capture
Streaming

# v4l2-ctl -d /dev/video0 -I
Video input : 0

# v4l2-ctl -d /dev/video0 -N
ioctl: VIDIOC_ENUMOUTPUT

# v4l2-ctl -d /dev/video0 -n
ioctl: VIDIOC_ENUMINPUT

# v4l2-ctl -d /dev/video0 -S
Video Standard = 0x00000001
PAL-B

# v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUYV 4:2:2

# v4l2-ctl -d /dev/video0 -V
Format Video Capture:
Width/Height : 0/0
Pixel Format : 'YUYV'
Field : Interlaced
Bytes per Line: 1440
Size Image : 829440
Colorspace : Broadcast NTSC/PAL (SMPTE170M/ITU601)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值