aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-11-15 21:01:56 +0100
committermetamuffin <metamuffin@disroot.org>2023-11-15 21:01:56 +0100
commitfeb3c7be85dd1f17c3f34b15906ce7c4b6c017f5 (patch)
tree5ade7b77c6686b82e2ba4b5a23e2060d9de7201c
parent9a064fb7b48df214677f4518de1ebddb475cb115 (diff)
downloadvideo-codec-experiments-feb3c7be85dd1f17c3f34b15906ce7c4b6c017f5.tar
video-codec-experiments-feb3c7be85dd1f17c3f34b15906ce7c4b6c017f5.tar.bz2
video-codec-experiments-feb3c7be85dd1f17c3f34b15906ce7c4b6c017f5.tar.zst
a
-rw-r--r--difftree/src/main.rs59
-rw-r--r--framework/src/lib.rs2
-rwxr-xr-xtest2
3 files changed, 41 insertions, 22 deletions
diff --git a/difftree/src/main.rs b/difftree/src/main.rs
index 24b7aad..9b6d35f 100644
--- a/difftree/src/main.rs
+++ b/difftree/src/main.rs
@@ -5,11 +5,14 @@ use framework::{
};
use rayon::join;
-const WIDTH: usize = 1920;
-const HEIGHT: usize = 1080;
-
fn main() {
let (mut framework, params) = Framework::init();
+ let root = Area {
+ x1: 0,
+ y1: 0,
+ x2: params.width,
+ y2: params.height,
+ };
match params.mode {
framework::CodecMode::Encode => {
@@ -17,20 +20,23 @@ fn main() {
let mut dframe = Frame::new(params.width, params.height);
let mut out = Vec::<u8>::new();
while let Some(iframe) = framework.next_frame() {
- let t = encode(&oframe, &iframe, Area::root());
- decode(&mut oframe, Area::root(), &t);
-
+ let t = encode(&oframe, &iframe, root);
+ decode(&mut oframe, root, &t);
write(&mut out, &t);
- if params.debug > 0 {
+ if params.debug == 1 {
dframe.pixels.copy_from_slice(&oframe.pixels);
- debug(&mut dframe, Area::root(), &t);
+ debug(&mut dframe, root, &t);
+ framework.decode_done(&dframe);
+ } else if params.debug == 2 {
+ debug_diff(&mut dframe, root, &t);
framework.decode_done(&dframe);
} else {
framework.decode_done(&oframe)
}
- framework.encode_done(&encode_huff(&out));
+ let huff = encode_huff(&out);
+ framework.encode_done(&huff);
out.clear();
}
}
@@ -65,8 +71,8 @@ pub fn debug(f: &mut Frame, area: Area, tree: &DiffTree) {
match tree {
DiffTree::Split([ta, tb]) => {
let (aa, ab) = area.split();
- decode(f, aa, ta);
- decode(f, ab, tb);
+ debug(f, aa, ta);
+ debug(f, ab, tb);
}
DiffTree::Diff(_diff) => {
let Area { x1, y1, x2, y2 } = area;
@@ -78,6 +84,27 @@ pub fn debug(f: &mut Frame, area: Area, tree: &DiffTree) {
}
}
}
+pub fn debug_diff(f: &mut Frame, area: Area, tree: &DiffTree) {
+ match tree {
+ DiffTree::Split([ta, tb]) => {
+ let (aa, ab) = area.split();
+ debug_diff(f, aa, ta);
+ debug_diff(f, ab, tb);
+ }
+ DiffTree::Diff(diff) => {
+ let Area { x1, y1, x2, y2 } = area;
+ for x in x1..x2 {
+ for y in y1..y2 {
+ f[(x, y)] = Pixel {
+ r: 127u8.saturating_add_signed(diff.r),
+ b: 127u8.saturating_add_signed(diff.b),
+ g: 127u8.saturating_add_signed(diff.g),
+ }
+ }
+ }
+ }
+ }
+}
pub fn encode(a: &Frame, b: &Frame, area: Area) -> DiffTree {
if area.area() == 1 {
@@ -101,7 +128,7 @@ pub fn encode(a: &Frame, b: &Frame, area: Area) -> DiffTree {
let d_b = ad.b.abs_diff(bd.b);
let visdiff = (d_r as usize + d_g as usize + d_b as usize) * aa.area();
- if visdiff < 1000 {
+ if visdiff < 100 {
return DiffTree::Diff(Pixel {
r: ((ad.r as i16 + bd.r as i16) / 2) as i8,
g: ((ad.g as i16 + bd.g as i16) / 2) as i8,
@@ -166,14 +193,6 @@ impl Area {
pub fn height(&self) -> usize {
self.y2 - self.y1
}
- pub fn root() -> Self {
- Area {
- x1: 0,
- y1: 0,
- x2: WIDTH,
- y2: HEIGHT,
- }
- }
pub fn split(&self) -> (Self, Self) {
let Area { x1, y1, x2, y2 } = *self;
if self.width() > self.height() {
diff --git a/framework/src/lib.rs b/framework/src/lib.rs
index 230aedb..c542d71 100644
--- a/framework/src/lib.rs
+++ b/framework/src/lib.rs
@@ -60,7 +60,7 @@ impl Framework {
eprintln!(
"size={}KB ratio={:.02} t={el:?}",
output.len() / 1000,
- (self.params.width * self.params.height * 3) / output.len()
+ (self.params.width * self.params.height * 3) as f32 / output.len() as f32
)
}
diff --git a/test b/test
index bba8fbb..defc559 100755
--- a/test
+++ b/test
@@ -1,4 +1,4 @@
#!/bin/fish
ffmpeg -loglevel quiet -i $argv[2] -vf 'scale=1920x1080,format=rgb24' -f rawvideo pipe:1 \
- | V_WIDTH=1920 V_HEIGHT=1080 V_DEBUG=0 V_MODE=encode cargo run --release --bin $argv[1] \
+ | V_WIDTH=1920 V_HEIGHT=1080 V_MODE=encode cargo run --release --bin $argv[1] \
| ffplay -loglevel quiet -video_size 1920x1080 -pixel_format rgb24 -f rawvideo pipe:0