Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
96 lines (65 sloc) 1.87 KB
#!perl -w
use strict;
use Imager;
# this is just to exercise the code, see the capture2image
# function below for the meat
my $from = shift;
my $to = shift;
my $width = shift || 320;
my $height = shift || 240;
$to or die "Usage: $0 from to [width [height]]\n";
my $data;
open RAWVIDEO, "< $from"
or die "Cannot open $from: $!\n";
binmode RAWVIDEO;
$data = do { local $/; <RAWVIDEO> };
length $data >= $width * $height * 3
or die "Not enough data for video frame\n";
my $im = Imager->new(xsize=>$width, ysize=>$height);
capture2image($im, $data);
or die "Cannot save $to: $!\n";
use Inline C => <<'EOS' => WITH => 'Imager';
capture2image(Imager::ImgRaw out, unsigned char *data) {
i_color *line_buf = mymalloc(sizeof(i_color) * out->xsize);
i_color *pixelp;
int x, y;
for (y = 0; y < out->ysize; ++y) {
pixelp = line_buf;
for (x = 0; x < out->xsize; ++x) {
pixelp->rgba.b = *data++;
pixelp->rgba.g = *data++;
pixelp->rgba.r = *data++;
i_plin(out, 0, out->xsize, y, line_buf);
=head1 NAME - convert captured BGR data to any Imager supported format
perl rawbgr foo.ext
perl rawbgr foo.ext width
perl rawbgr foo.ext width height
This was inspired by the discussion at (Feeding video data to
Imager). takes V4L raw captured image data and outputs
an image in any image format supported by Imager.
=head1 SEE ALSO
Imager, Imager::API
Perl and Video Capture
Feeding video data to Imager
=head1 AUTHOR
Tony Cook <>
Jump to Line
Something went wrong with that request. Please try again.