4

I'm trying to take snapshots with my Pi3 + USB camera. I've tried a few different things, but all with different results. I've tried:

  mplayer -vo jpeg -frames 1 tv:// 

And the output text is:


MPlayer2 2.0-728-g2c378c7-4build1 (C) 2000-2012 MPlayer Team
Cannot open file '/home/jems/.mplayer/input.conf': No such file or directory
Failed to open /home/jems/.mplayer/input.conf.

Playing tv://.
Detected file format: TV
Selected driver: v4l2
 name: Video 4 Linux 2 input
 author: Martin Olschewski 
 comment: first try, more to come ;-)
v4l2: your device driver does not support VIDIOC_G_STD ioctl, VIDIOC_G_PARM was used instead.
Selected device: UVC Camera (046d:0990)
 Capabilities:  video capture  streaming
 supported norms:
 inputs: 0 = Camera 1;
 Current input: 0
 Current format: MJPEG
tv.c: norm_from_string(pal): Bogus norm parameter, setting default.
v4l2: ioctl enum norm failed: Inappropriate ioctl for device
Error: Cannot set norm!
Selected input hasn't got a tuner!
v4l2: ioctl set mute failed: Invalid argument
v4l2: ioctl query control failed: Invalid argument
jpeg: Progressive JPEG disabled.
jpeg: Baseline JPEG enabled.
Opening video filter: [scale]
[ass] auto-open
Selected video codec: MJPEG (Motion JPEG) [libavcodec]
Audio: no sound
Starting playback...
v4l2: select timeout
[mjpeg @ 0x76186870]No JPEG data found in image
Error while decoding frame!
[mjpeg @ 0x76186870]No JPEG data found in image
Error while decoding frame!
v4l2: select timeout
[mjpeg @ 0x76186870]No JPEG data found in image
Error while decoding frame!
[mjpeg @ 0x76186870]Changeing bps to 8
VIDEO:  640x480  15.000 fps    0.0 kbps ( 0.0 kB/s)
[swscaler @ 0x7587a488]bicubic scaler, from yuv420p to rgb24 using C
[swscaler @ 0x7587a488]No accelerated colorspace conversion found from yuv420p to rgb24.
[swscaler @ 0x7587a488]using unscaled yuv420p -> rgb24 special converter
VO: [jpeg] 640x480 => 640x480 RGB 24-bit 
jpeg: . - Output directory already exists and is writable.
V:   0.0   4/  4 ??% ??% ??,?% 0 0 

v4l2: ioctl set mute failed: Invalid argument
v4l2: 3 frames successfully processed, 0 frames dropped.

Exiting... (End of file)
$

It works, and creates and image, but the image color is all blue and red:

enter image description here

Also, if I try to run the command again, I get no image and the following output:

$ mplayer -vo jpeg -frames 1 tv://
MPlayer2 2.0-728-g2c378c7-4build1 (C) 2000-2012 MPlayer Team
Cannot open file '/home/jems/.mplayer/input.conf': No such file or directory
Failed to open /home/jems/.mplayer/input.conf.

Playing tv://.
Detected file format: TV
Selected driver: v4l2
 name: Video 4 Linux 2 input
 author: Martin Olschewski 
 comment: first try, more to come ;-)
v4l2: your device driver does not support VIDIOC_G_STD ioctl, VIDIOC_G_PARM was used instead.
Selected device: UVC Camera (046d:0990)
 Capabilities:  video capture  streaming
 supported norms:
 inputs: 0 = Camera 1;
 Current input: 0
 Current format: MJPEG
v4l2: ioctl set format failed: Input/output error
v4l2: ioctl set mute failed: Invalid argument
v4l2: 0 frames successfully processed, 0 frames dropped.
Opening as detected format "TV" failed.
Failed to recognize file format.


Exiting... (End of file)

So I tried using ffmpeg, as follows:

ffmpeg -i /dev/video0 -vframes 1 output.png

Which created a smaller picture, but it worked:

enter image description here

However, I can only run either command once. If I try again, I get an error:

/dev/video0: Input/output error

And I have to reboot in order to take another picture.

Does anyone have a solution which works consistently? The first command I mentioned works well on my Linux Mint desktop every time, so I don't think there is a problem with my camera.

Thanks!

  • Not exactly ideal, but you could try just resetting the USB port after each image capture, rather than rebooting. – goobering Mar 23 '16 at 20:20
  • In regards to your "there is no problem with my camera" assumption. The drivers used on the RPi and your desktop are likely different - causing these issues. So, even if your camera (through its drivers) works on your desktop, it could be a problem related the driver you are using on the RPi – Chris Mar 24 '16 at 4:32
4

Does fswebcam could work for you ?

Install it with:

sudo apt-get install fswebcam

Basic usage:

fswebcam image.jpg

Specific resolution:

fswebcam -r 1280x720 image2.jpg

Otherwise you could use OpenCV and write a small C/C++ program which use:

 cvQueryFrame(cap);
 cvSameImage(filename, frame, params);

See OpenCV API for example.

  • Ok, this works better! But again, after 1 or 2 captures, it will fail to work. The output I get:Trying source module v4l2... /dev/video0 opened. No input was specified, using the first. But I could some code to 'reset the usb device', which works. So, I guess I kinda have a solution with a reset script. Thanks! – Jessica 6 Mar 24 '16 at 0:53
  • Maybe try a python script with OpenCV code as suggested and let us know if that works - would be interesting for me to hear. – Chris Mar 24 '16 at 4:28
  • Here is a very short intro to using fswebcam: youtube.com/watch?v=JnQh-o9aSD0 – SDsolar Jun 17 '18 at 6:57
0

Most of your examples try to make use of the Video4Linux2 driver. A USB camera should work with this API with no problem. Check that the tools for this are correctly installed:

sudo apt-get install v4l-utils

I know you are using a USB camera but just for other people's benefit, if you use the RPI camera interface you have to load the BCM driver:

sudo modprobe bcm2835-v4l2

Then you can access the camera device which is at /dev/videoN where N is normally 0 if there is only one camera.

You can check all the information about video devices using

v4l2-ctl --all

or more specific modes available using

v4l2-ctl --device=/dev/video0 --list-formats-ext

These commands should show you if there are general errors using this driver to access information about the camera. You can get the driver information by typing

v4l2-ctl -D

You can even capture a jpeg with:

v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg

You might have to set the correct width and height parameters for your camera.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.