From c29499d9b03ac184da271e888882e35dcbdd1ce9 Mon Sep 17 00:00:00 2001 From: devdesk Date: Fri, 16 Feb 2024 00:41:39 +0200 Subject: [PATCH] to fifo and gst-launch --- examples/live.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ read_gst.sh | 6 ++++ 2 files changed, 88 insertions(+) create mode 100644 examples/live.rs create mode 100755 read_gst.sh diff --git a/examples/live.rs b/examples/live.rs new file mode 100644 index 0000000..811e2ca --- /dev/null +++ b/examples/live.rs @@ -0,0 +1,82 @@ +use indicatif::ProgressBar; +use std::fs::File; +use std::io::Write; +use thermaldecoder::{write_raw_frame, Frame, Header, HDR_SIZE}; + +// fn main() -> Result<(), eframe::Error> { +// env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). +// let options = eframe::NativeOptions { +// viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 800.0]), +// ..Default::default() +// }; +// let (sender, receiver) = crossbeam::channel::unbounded(); +// eframe::run_native( +// "Image Viewer", +// options, +// Box::new(|cc| { +// // This gives us image support: +// egui_extras::install_image_loaders(&cc.egui_ctx); +// Box::::default() +// }), +// ) +// } + +// #[derive(Default)] +// struct MyApp {} + +// impl eframe::App for MyApp { +// fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { +// egui::CentralPanel::default().show(ctx, |ui| { +// egui::ScrollArea::both().show(ui, |ui| { +// ui.add(egui::Image::new().rounding(10.0)); + +// ui.image(egui::include_image!("ferris.svg")); +// }); +// }); +// } +// } + +fn main() -> anyhow::Result<()> { + // get the default Device + let device = pcap::Device::lookup() + .expect("device lookup failed") + .expect("no device available"); + println!("Using device {}", device.name); + + // Setup Capture + let mut cap = pcap::Capture::from_device(device) + .unwrap() + .immediate_mode(true) + .open() + .unwrap(); + + // get a packet and print its bytes + let mut parts = vec![]; + let pb = ProgressBar::new(1024); + let mut out = File::create("output.raw")?; + while let Ok(p) = cap.next_packet() { + let data = p.data; + if data.len() != 6972 { + continue; + } + let data = &data[0x2a..]; + let header = match Header::read(data) { + Ok(header) => header, + Err(_) => continue, + }; + let data = &data[HDR_SIZE..]; + if header.part == 0 && parts.len() > 0 { + let frame = Frame { + header, + raw: parts.concat(), + }; + if frame.raw.len() == 384 * 288 * 2 { + out.write_all(&frame.raw)?; + pb.inc(1); + } + parts.clear(); + } + parts.push(data.to_vec()); + } + Ok(()) +} diff --git a/read_gst.sh b/read_gst.sh new file mode 100755 index 0000000..b572932 --- /dev/null +++ b/read_gst.sh @@ -0,0 +1,6 @@ +#!/bin/bash +export GST_DEBUG_DUMP_DOT_DIR=$(pwd) +gst-launch-1.0 filesrc location=output.raw \ + ! rawvideoparse use_sink_caps=false height=384 width=288 format=gray16-be \ + ! videoconvertscale \ + ! autovideosink