remove indicatif, add dotenv, write to stdout, gst to v4lsink, usable with ffplay, still some hiccups, not cpu related

This commit is contained in:
devdesk
2024-02-17 15:43:20 +02:00
parent 5acd03828d
commit 49f9aa98ed
5 changed files with 49 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
use indicatif::ProgressBar;
use dotenv::dotenv;
use std::fs::File;
use std::io::Write;
use thermaldecoder::{Frame, Header, HDR_SIZE};
@@ -37,11 +37,27 @@ use thermaldecoder::{Frame, Header, HDR_SIZE};
// }
fn main() -> anyhow::Result<()> {
dotenv().ok();
let device = match std::env::var("THERMALCAM_IFACE=enp1s0f0") {
Ok(d) => {
let device = pcap::Device::list()
.expect("device list failed")
.into_iter()
.find(|x| x.name == d)
.expect(&format!("could not find device {}", d));
device
}
Err(_) => pcap::Device::lookup()
.expect("device lookup failed")
.expect("no device available"),
};
// get the default Device
let device = pcap::Device::lookup()
.expect("device lookup failed")
.expect("no device available");
println!("Using device {}", device.name);
let output = std::env::args()
.nth(1)
.expect("required output file argument");
println!("Using output {}", output);
// Setup Capture
let mut cap = pcap::Capture::from_device(device)
@@ -52,8 +68,7 @@ fn main() -> anyhow::Result<()> {
// get a packet and print its bytes
let mut parts = vec![];
let pb = ProgressBar::new(1024);
let mut out = File::create("output.raw")?;
let mut out = File::create(&output)?;
while let Ok(p) = cap.next_packet() {
let data = p.data;
if data.len() != 6972 {
@@ -72,7 +87,6 @@ fn main() -> anyhow::Result<()> {
};
if frame.raw.len() == 384 * 288 * 2 {
out.write_all(&frame.raw)?;
pb.inc(1);
}
parts.clear();
}