| 1 | |
| 2 | |
| 3 | use std::process::Command; |
| 4 | |
| 5 | use ec_core::frame::VideoFrame; |
| 6 | |
| 7 | pub(crate) fn chunk(id: &[u8; 4], body: &[u8]) -> Vec<u8> { |
| 8 | let mut v = id.to_vec(); |
| 9 | v.extend((body.len() as u32).to_le_bytes()); |
| 10 | v.extend(body); |
| 11 | if body.len() % 2 == 1 { |
| 12 | v.push(0); |
| 13 | } |
| 14 | v |
| 15 | } |
| 16 | |
| 17 | pub(crate) fn list(kind: &[u8; 4], body: &[u8]) -> Vec<u8> { |
| 18 | let mut b = kind.to_vec(); |
| 19 | b.extend(body); |
| 20 | chunk(b"LIST", &b) |
| 21 | } |
| 22 | |
| 23 | pub(crate) fn tool_ok(name: &str) -> bool { |
| 24 | Command::new(name) |
| 25 | .arg("-version") |
| 26 | .output() |
| 27 | .map(|o| o.status.success()) |
| 28 | .unwrap_or(false) |
| 29 | } |
| 30 | |
| 31 | pub(crate) fn ffmpeg(args: &[&str]) { |
| 32 | let ok = Command::new("ffmpeg") |
| 33 | .args(["-v", "error", "-y", "-nostdin"]) |
| 34 | .args(args) |
| 35 | .status() |
| 36 | .map(|s| s.success()) |
| 37 | .unwrap_or(false); |
| 38 | assert!(ok, "ffmpeg {args:?} failed"); |
| 39 | } |
| 40 | |
| 41 | pub(crate) fn frame_bytes(f: &VideoFrame) -> Vec<u8> { |
| 42 | let mut out = Vec::new(); |
| 43 | for (p, (row, rows)) in f |
| 44 | .planes |
| 45 | .iter() |
| 46 | .zip(f.format.plane_geometry(f.width, f.height)) |
| 47 | { |
| 48 | for y in 0..rows { |
| 49 | out.extend_from_slice(p.row(y, row).unwrap()); |
| 50 | } |
| 51 | } |
| 52 | out |
| 53 | } |