working v4l2 in rust, swapping bytes
This commit is contained in:
parent
e74fa87103
commit
6bcc541c86
|
@ -22,4 +22,4 @@ pcap-parser = { version = "0.14.1", features = ["data"] }
|
|||
png = "0.17.10"
|
||||
pyo3 = { version = "0.20.0", "features" = ["extension-module"] }
|
||||
serde = { version = "1.0.193", features = ["derive", "serde_derive", "alloc"] }
|
||||
v4l = "0.14.0"
|
||||
v4l = { version = "0.14.0", features = ["v4l2"], default-features = false }
|
||||
|
|
|
@ -30,7 +30,9 @@ fn main() -> anyhow::Result<()> {
|
|||
const HEIGHT: usize = 384;
|
||||
let fourcc_repr = [
|
||||
b'Y', // | 0b10000000
|
||||
b'1', b'6', b' ',
|
||||
b'1', b'6',
|
||||
b' ', // Note: not using b' ' | 0x80, (V4L2_PIX_FMT_Y16_BE)
|
||||
// because VID_S_FMT ioctl returns EINVAL, so just swap the bytes here
|
||||
];
|
||||
let fourcc = v4l::format::FourCC { repr: fourcc_repr };
|
||||
let mut out = v4l::Device::with_path(output)?;
|
||||
|
@ -67,7 +69,14 @@ fn main() -> anyhow::Result<()> {
|
|||
|| (data.len() + len > FRAME_LEN)
|
||||
{
|
||||
if len == FRAME_LEN {
|
||||
out.write_all(&frame[..])?;
|
||||
// swap the bytes, we are using LE, not BE, 16 bit grayscale
|
||||
// possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2
|
||||
let mut swapped = [0u8; FRAME_LEN];
|
||||
for i in 0..FRAME_LEN / 2 {
|
||||
swapped[i * 2] = frame[i * 2 + 1];
|
||||
swapped[i * 2 + 1] = frame[i * 2];
|
||||
}
|
||||
out.write_all(&swapped[..])?;
|
||||
}
|
||||
len = 0;
|
||||
}
|
||||
|
|
|
@ -9,5 +9,5 @@ cargo build --release --example live
|
|||
TARGET=./target/release/examples/live
|
||||
# setcap does not work yet (EPERM on socket AF_PACKET)
|
||||
# sudo setcap cap_net_raw,cap_net_admin=eip $TARGET
|
||||
#strace -f -o live.strace $TARGET /dev/video0
|
||||
#sudo strace -f -o live.strace $TARGET /dev/video0
|
||||
sudo $TARGET /dev/video0
|
||||
|
|
Loading…
Reference in New Issue
Block a user