This commit is contained in:
Oliver Atkinson 2023-06-29 15:14:57 -06:00
parent 61b6adb5bb
commit 117c64a9a1
2 changed files with 17 additions and 12 deletions

7
README.md Normal file
View File

@ -0,0 +1,7 @@
## Video Parser
This takes a visual media input (photo / video / etc) and uses ffmpeg to read the rgb values then writes them to `stdout` as raw data. This can the be piped to [/dev/ttyACMx](https://github.com/Rushmore75/led_matrix) which will display them.
To find the arduino you can run:
```
ls /dev/serial/by-id/ | grep arduino | xargs -I{} readlink /dev/serial/by-id/{}
```
which will output `../../ttyACMX` or simmilar. Then `/dev/ttyACMX` (for example) is your arduino.

View File

@ -1,15 +1,5 @@
use std::io::*; use std::io::{stdout, Write};
use ffmpeg::format::Pixel; use ffmpeg::format::Pixel;
use rand::Rng;
#[inline]
/// Assumes a square ig
pub fn print_raw(buf: &[u8]) {
let mut stdout = stdout();
let mut lock = stdout.lock();
lock.write(buf).unwrap();
stdout.flush().unwrap();
}
/// Must use square images /// Must use square images
// pub fn print_square(buf: &[u8], width_hight: usize, line) { // pub fn print_square(buf: &[u8], width_hight: usize, line) {
@ -25,6 +15,10 @@ pub fn print_square(frame: &ffmpeg::frame::Video) {
// How many bytes per pixel RGBA // How many bytes per pixel RGBA
let linesize = unsafe { std::ptr::addr_of!((*frame.as_ptr()).linesize) }; let linesize = unsafe { std::ptr::addr_of!((*frame.as_ptr()).linesize) };
let step = (unsafe { *linesize })[z] as usize; let step = (unsafe { *linesize })[z] as usize;
let mut stdout = stdout();
let mut lock = stdout.lock();
// (Assuming square) Step thru buffer. // (Assuming square) Step thru buffer.
for i in 0..size { for i in 0..size {
let j = i*step; let j = i*step;
@ -34,7 +28,11 @@ pub fn print_square(frame: &ffmpeg::frame::Video) {
let slice = &pre_slice[0..size*3]; let slice = &pre_slice[0..size*3];
// let lol = &buf[j..j+step][0..size*3]; // let lol = &buf[j..j+step][0..size*3];
println!("{:?} || {}-{}", slice, j, j+step); // DEBUG
// println!("{:?} || {}-{}", slice, j, j+step);
// NORMAL
lock.write(slice).unwrap();
} }
stdout.flush().unwrap();
} }