Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Webcam-ignorant - really basic question
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3509

PostPosted: Fri May 20, 2011 6:20 pm    Post subject: Webcam-ignorant - really basic question Reply with quote

I'd like to simply and temporarily connect a webcam to my server, and occasionally grab still from it. It'll only be for less than a week, and it's for remote operation only, stills-only, so I don't really wish to install much software, preferably none. Something like "cat /dev/video0 >/tmp/file" is OK by me.

A bit over a year back I got my daughter a cheap webcam for Christmas so she could keep in touch with her boyfriend on Skype while he was studying abroad in Europe.

The webcam is now sitting in a drawer. But we've been having some water problems this spring, first time in almost 20 years, second time since we've owned this house. I think we've got the water problems on the run, but we've also got a trip planned next week. I've had OpenVPN installed and running for some time now. So I think it would be really neat to plug the webcam into one of my servers in the basement and point it at the place where we've done our "remediation," and check it occasionally. We even have neighbors we could call and ask to take a limited range of actions, if needed. (Mostly just plugging in the backup pump.)

Is there something really dirt-simple I can do with a webcam, like cat from a video device to a file, then scp that file to my laptop at the hotel? I know that there is a motion-detecting bungler-alarm package, but that's way overkill for what I want, and probably would involve too much setup.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
palmer
Guru
Guru


Joined: 17 Nov 2004
Posts: 322
Location: Berkeley, CA

PostPosted: Sat May 21, 2011 12:04 am    Post subject: Reply with quote

`cat` probably won't work for these purposes because AFAIK there isn't really a standard image file format. The following C code will take constant pictures and save them as PPM (which is uncompressed, but you can use `convert` from ImageMagick to convert them to JPEG if you're worried about bandwidth).

You'll need "media-libs/libv4l". Compile with `gcc -l v4l2 v4l2ppm.c -o v4l2ppm`.

Code:
/* part of media-libs/libv4l */
#include <libv4l2.h>

#include <linux/videodev2.h>
#include <sys/mman.h>
#include <assert.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>

#define V4L_FORMAT   V4L2_PIX_FMT_RGB24
#define IMAGE_WIDTH      800
#define IMAGE_HEIGHT   600
#define VIDEO_PATH   "/dev/video0"
#define IMAGE_PATH   "v4l2.ppm"

int main(int argc, char ** argv)
{
   int err;
   int video_dev;
   static struct v4l2_format format;
   uint8_t * image_data;
   int image_width, image_height;
   
   /* Opens the video VIDEO_PATH using the wrapped call */
   video_dev = v4l2_open(VIDEO_PATH, O_RDWR);
   assert(video_dev > 0);
   
   /* Zeros out the format, just in case */
   memset(&format, 0x00, sizeof(format));
   
   /* Fills in the format type to get BGR24 */
   format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
   format.fmt.pix.pixelformat = V4L_FORMAT;
   format.fmt.pix.width = IMAGE_WIDTH;
   format.fmt.pix.height = IMAGE_HEIGHT;
   
   /* Calls the IOCTL to set the format */
   err = v4l2_ioctl(video_dev, VIDIOC_S_FMT, &format);
   assert(err == 0);
   
   /* The call _will_ succeed because we are using the wrapper, but to make
      sure we can test anyway */
   assert(format.fmt.pix.pixelformat == V4L_FORMAT);
   
   /* Creates some space to store the data */
   image_width = format.fmt.pix.width;
   image_height = format.fmt.pix.height;
   image_data = malloc(3 * image_width * image_height);
   assert(image_data != NULL);
   
   while (1)
   {
      int size;
      FILE * file;
      
      size = 3 * image_width * image_height;
      v4l2_read(video_dev, image_data, size);
      
      file = fopen(IMAGE_PATH, "w");
      fprintf(file, "P6\n%d %d\n%d\n", image_width, image_height, 255);
      fwrite(image_data, size, 1, file);
      fclose(file);
   }
}
Back to top
View user's profile Send private message
OneOfOne
Guru
Guru


Joined: 28 May 2003
Posts: 368

PostPosted: Sat May 21, 2011 6:57 am    Post subject: Reply with quote

You can use ffserver (part of ffmpeg) and simply view the stream remotely, this howto is decent http://ubuntuforums.org/showthread.php?t=665607
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sat May 21, 2011 7:38 am    Post subject: Reply with quote

Look at the package media-video/motion. It could be just what you wanted! :)

EDIT i am not sure if you were referring to motion when you talked about "motion detecting burglar alarm package". I think motion has very little dependency (even ffmpeg is optional) and it by default at least saves the images captured from the webcam, to a folder.
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3509

PostPosted: Sun May 22, 2011 12:54 am    Post subject: Reply with quote

Thank you all for the suggestions, I'll see what I can manager. For the moment, my daughter doesn't know where the webcam is, and I spent the day working in the basement, moving appliances, ripping stuff out, etc. I'll see what I can manager.

EDIT... All done, back from the trip. No webcam. Still water in the basement, still too busy to do much extra, like badger my daughter to find the camera, build software, etc. Maybe when things dry out I'll look into this again. In the meantime, thanks for the suggestions.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum