Skip to content

Commit

Permalink
Merge branch 'camera-mjpeg'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Jan 26, 2025
2 parents 7d2caa5 + fdeacf1 commit 0970eb5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions crates/media/src/feeds/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ fn run_camera_feed(
match camera_format.format() {
FrameFormat::BGRA => Pixel::BGRA,
FrameFormat::MJPEG => {
todo!("handle mjpeg for camera")
Pixel::RGB24
// todo!("handle mjpeg for camera")
}
FrameFormat::RAWRGB => Pixel::RGB24,
FrameFormat::NV12 => Pixel::NV12,
Expand Down Expand Up @@ -265,7 +266,8 @@ fn run_camera_feed(
match camera_format.format() {
FrameFormat::BGRA => Pixel::BGRA,
FrameFormat::MJPEG => {
todo!("handle mjpeg for camera")
Pixel::RGB24
// todo!("handle mjpeg for camera")
}
FrameFormat::RAWRGB => Pixel::RGB24,
FrameFormat::NV12 => Pixel::NV12,
Expand Down Expand Up @@ -384,6 +386,24 @@ fn buffer_to_ffvideo(buffer: nokhwa::Buffer) -> FFVideo {
}
})
}
FrameFormat::MJPEG => (Pixel::RGB24, |frame, buffer| {
let decoded = buffer
.decode_image::<nokhwa::pixel_format::RgbFormat>()
.unwrap();

let bytes = decoded.into_raw();

let width = frame.width() as usize;
let height = frame.height() as usize;
let stride = frame.stride(0) as usize;

for y in 0..height {
let row_length = width * 3;

frame.data_mut(0)[y * stride..(y * stride + row_length)]
.copy_from_slice(&bytes[y * width * 3..y * width * 3 + row_length]);
}
}),
_ => todo!("implement more camera formats"),
}
};
Expand Down

1 comment on commit 0970eb5

@vercel
Copy link

@vercel vercel bot commented on 0970eb5 Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.