5 # this is just to exercise the code, see the capture2image
6 # function below for the meat
11 my $width = shift || 320;
13 my $height = shift || 240;
15 $to or die "Usage: $0 from to [width [height]]\n";
18 open RAWVIDEO, "< $from"
19 or die "Cannot open $from: $!\n";
21 $data = do { local $/; <RAWVIDEO> };
24 length $data >= $width * $height * 3
25 or die "Not enough data for video frame\n";
27 my $im = Imager->new(xsize=>$width, ysize=>$height);
29 capture2image($im, $data);
32 or die "Cannot save $to: $!\n";
34 use Inline C => <<'EOS' => WITH => 'Imager';
36 capture2image(Imager::ImgRaw out, unsigned char *data) {
37 i_color *line_buf = mymalloc(sizeof(i_color) * out->xsize);
41 for (y = 0; y < out->ysize; ++y) {
43 for (x = 0; x < out->xsize; ++x) {
44 pixelp->rgba.b = *data++;
45 pixelp->rgba.g = *data++;
46 pixelp->rgba.r = *data++;
49 i_plin(out, 0, out->xsize, y, line_buf);
60 inline_capture2image.pl - convert captured C<BGR> data to any Imager supported format
64 perl inline_capture2image.pl rawbgr foo.ext
65 perl inline_capture2image.pl rawbgr foo.ext width
66 perl inline_capture2image.pl rawbgr foo.ext width height
70 This was inspired by the discussion at
71 http://www.perlmonks.org/?node_id=539316 (Feeding video data to
74 inline_capture2image.pl takes V4L raw captured image data and outputs
75 an image in any image format supported by Imager.
81 Perl and Video Capture
82 http://www.perlmonks.org/?node=474047
84 Feeding video data to Imager
85 http://www.perlmonks.org/?node_id=539316
89 Tony Cook <tonyc@cpan.org>