Skip to content

Commit

Permalink
mjpeg support
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Jan 26, 2025
1 parent 1fc5d89 commit fdeacf1
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

0 comments on commit fdeacf1

Please sign in to comment.