CAPTURE VIDEO AND AUDIO FROM WEBCAM USING AVCONV (FFMPEG)
1- Find video device
$ ls /dev/video*
An example of video device would be: /dev/video0
2- Find audio device
$ arecord -l
Imagine that the output of the command is as follows.
: U0x46d0x8ad [USB Device 0x46d:0x8ad], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
Then the audio device would be:
3- Capture video and audio using ffmpeg:
avconv -f video4linux2 -r 25 -i /dev/video0 -f alsa -i plughw:U0x46d0x8ad,0 -ar 22050 -ab 64k -strict experimental -acodec aac -vcodec mpeg4 -y webcam.mp4
note video4linux2 is more commonly shortened to v4l2
PS: To capture the same thing using VLC try:
vlc v4l2:///dev/video0 :input-slave="alsa://hw:1,0"
List device capabilities To list available formats (supported pixel formats, video formats, and frame sizes) for a particular input device:
$ ffmpeg -f v4l2 -list_formats all -i /dev/video0
…
[video4linux2,v4l2 @ 0xf07d80] Raw : yuyv422 : YUV 4:2:2 (YUYV) : 640x480 160x120 176x144 320x176 320x240 352x288 432x240 544x288 640x360
[video4linux2,v4l2 @ 0xf07d80] Compressed: mjpeg : MJPEG : 640x480 160x120 176x144 320x176 320x240 352x288 432x240 544x288 640x360
Alternatively you could use v4l2-ctl --list-formats-ext to list available formats.
Example to encode video from /dev/video0:
ffmpeg -f v4l2 -r 25 -video_size 640x480 -i /dev/video0 output.mkv
Adjusting the streaming you can configure resolution with -s, framerate with -r and codec with -codec:v.
Just make sure to keep those parameters AFTER -f v4l2 and BEFORE -i.
If you put them after the -i input specifier they will apply as encoding settings
Adjusting camera functions
Brightness, zoom, focus, etc, can be adjusted with v4l2-ctl.
Display all controls and their menus:
v4l2-ctl -L>
Then adjust the value:
v4l2-ctl -c <option>=<value>