Reputation: 67
I want to capture a image through webcam in linux. So i searched on internet and found out it's can be done using mplayer or vlc.
Following is the command for capturing image by mplayer and its corresponding error.
[root@localhost ~]# mplayer -vo png -frames 1 tv://
MPlayer SVN-r31628-4.4.4 (C) 2000-2010 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing tv://.
TV file format detected.
Selected driver: v4l2
name: Video 4 Linux 2 input
author: Martin Olschewski <[email protected]>
comment: first try, more to come ;-)
v4l2: unable to open '/dev/video0': No such file or directory
v4l2: ioctl set mute failed: Bad file descriptor
v4l2: 0 frames successfully processed, 0 frames dropped.
Exiting... (End of file)
[root@localhost ~]#
Please Help me in solving this error. I searched on net and found out about v4l2, but still can't solve the problem.
Upvotes: 4
Views: 5040
Reputation: 1729
First, start the capture in mpv
:
> mpv av://v4l2:/dev/videoN
where /dev/videoN is your video device.
Then, do screenshots using the s
key.
This will save the images to ./mpv-shotNNNN.jpg
, where NNNN
starts from 0000
, and increases once per capture.
Upvotes: 0
Reputation: 64
I made it by doing this:
mplayer tv:// -tv driver=v4l2:device=/dev/video0 -fps 1 -frames 2 -sstep 100 -vo jpeg; rm 00000001.jpg ; mv 00000002.jpg capture.$(date +%F_%R).jpg
.
"tv:// -tv driver=v4l2:device=/dev/video0
" specifies the necessary driver and video device. You need to check if that device is the one you want to capture and or exists by doing ls /dev/video*
.
-fps 1 -frames 2 -sstep 100
specifies the framerate and it's set to only one per second to ensure you will have enough time to wake up properly the camera, captures 2 frames and in between frames you had 100 fps from the output dropped to help with the camera focus.
-vo jpeg
stands for jpg output format images, on my computer png doesn't work with all this configuration.
rm 00000001.jpg
deletes the first frame capture, because always it's ging to be obscure, green or no focused, this is caused by the small amount of time neede by the camera to wake up.
mv 00000002.jpg capture.$(date +%F_%R).jpg
makes the second frame image switch name from 00000002.jpg for "capture." plus the current date time.
Upvotes: 0
Reputation: 1296
You can also try using fswebcam which has a useful feauture of skipping the first few frames -some webcam show corrupt (or green) images for the first frame or two:
fswebcam --skip 2
It can be set to capture an image every second:
fswebcam --skip 2 --loop 1
Upvotes: 0
Reputation: 5211
Your error is pretty clear. The webcam apparently is not registering at /dev/video0. In some instances, I've found that encoders or other video devices register under /dev/videoX, where X can be any integer. Try modifying your statement to try different video devices.
Upvotes: 2