aboutsummaryrefslogtreecommitdiff
path: root/evc
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-12-06 19:30:03 +0100
committermetamuffin <metamuffin@disroot.org>2022-12-06 19:30:03 +0100
commit70514416c2ade2abe628efbd0a629a66febdeb13 (patch)
tree03b54f677046afe5a2e1b04768c1cb9104771462 /evc
parentc4e995d29209e0e0a1aafd9652971b8980fafb15 (diff)
downloadvideo-codec-experiments-70514416c2ade2abe628efbd0a629a66febdeb13.tar
video-codec-experiments-70514416c2ade2abe628efbd0a629a66febdeb13.tar.bz2
video-codec-experiments-70514416c2ade2abe628efbd0a629a66febdeb13.tar.zst
minor stuff, store translation as i8
Diffstat (limited to 'evc')
-rwxr-xr-xevc/scripts/gen11
-rwxr-xr-xevc/scripts/gen-debug4
-rwxr-xr-xevc/scripts/stream8
-rwxr-xr-xevc/scripts/stream-lq8
-rw-r--r--evc/spec.md4
-rw-r--r--evc/src/block.rs6
-rw-r--r--evc/src/debug.rs11
-rw-r--r--evc/src/frame.rs5
-rw-r--r--evc/src/ser.rs12
-rw-r--r--evc/src/vec2.rs15
10 files changed, 61 insertions, 23 deletions
diff --git a/evc/scripts/gen b/evc/scripts/gen
index 9754079..8fd53dd 100755
--- a/evc/scripts/gen
+++ b/evc/scripts/gen
@@ -1,4 +1,9 @@
#/bin/fish
-cargo run --release --bin encode -- -W 1920 -H 1080 < samples/raw > samples/encoded
-cargo run --release --bin decode -- < samples/encoded > samples/decoded
-ffmpeg -y -framerate 30 -video_size 1920x1080 -pixel_format rgb24 -f rawvideo -i samples/decoded samples/decoded.mp4
+set w $argv[1]
+set h $argv[2]
+ffmpeg -i $argv[3] -to 10 -vf scale={$w}x{$h},fps=30 -f rawvideo -pixel_format rgb24 > samples/raw
+LOG=info cargo run --release --bin encode -- -W {$w} -H {$h} < samples/raw > samples/encoded
+LOG=info cargo run --release --bin decode -- < samples/encoded > samples/decoded
+LOG=info cargo run --release --bin decode -- --debug < samples/encoded > samples/decoded-debug
+ffmpeg -y -framerate 30 -video_size {$w}x{$h} -pixel_format rgb24 -f rawvideo -i samples/decoded samples/decoded.mp4
+ffmpeg -y -framerate 30 -video_size {$w}x{$h} -pixel_format rgb24 -f rawvideo -i samples/decoded-debug samples/decoded-debug.mp4
diff --git a/evc/scripts/gen-debug b/evc/scripts/gen-debug
deleted file mode 100755
index 513afab..0000000
--- a/evc/scripts/gen-debug
+++ /dev/null
@@ -1,4 +0,0 @@
-#/bin/fish
-cargo run --release --bin encode -- -W 1920 -H 1080 < samples/raw > samples/encoded
-cargo run --release --bin decode -- --debug < samples/encoded > samples/decoded
-ffmpeg -y -framerate 30 -video_size 1920x1080 -pixel_format rgb24 -f rawvideo -i samples/decoded samples/decoded.mp4
diff --git a/evc/scripts/stream b/evc/scripts/stream
index 2072e21..10098b6 100755
--- a/evc/scripts/stream
+++ b/evc/scripts/stream
@@ -1,5 +1,7 @@
#!/bin/fish
-ffmpeg -i $argv[1] -vf scale=1920x1080,fps=30,format=rgb24 -f rawvideo pipe:1 2>/dev/null |
- cargo run --release --bin encode -- -W 1920 -H 1080 |
+set w $argv[1]
+set h $argv[2]
+ffmpeg -hide_banner -i $argv[3] -vf scale={$w}x{$h},fps=30,format=rgb24 -f rawvideo pipe:1 |
+ cargo run --release --bin encode -- -W {$w} -H {$h} |
cargo run --release --bin decode -- --debug |
- ffplay -framerate 30 -video_size 1920x1080 -pixel_format rgb24 -f rawvideo pipe:0 2>/dev/null
+ ffplay -hide_banner -framerate 30 -video_size {$w}x{$h} -pixel_format rgb24 -f rawvideo pipe:0
diff --git a/evc/scripts/stream-lq b/evc/scripts/stream-lq
index 486dbaf..300800a 100755
--- a/evc/scripts/stream-lq
+++ b/evc/scripts/stream-lq
@@ -1,5 +1,5 @@
#!/bin/fish
-ffmpeg -i $argv[1] -vf scale=1280x720,fps=30,format=rgb24 -f rawvideo pipe:1 2>/dev/null |
- cargo run --release --bin encode -- -W 1280 -H 720 |
- cargo run --release --bin decode -- --debug |
- ffplay -framerate 30 -video_size 1280x720 -pixel_format rgb24 -f rawvideo pipe:0 2>/dev/null
+ffmpeg -i $argv[1] -vf scale=920x550,fps=30,format=rgb24 -f rawvideo pipe:1 2>/dev/null |
+ LOG=info cargo run --release --bin encode -- -W 920 -H 550 |
+ LOG=info cargo run --release --bin decode -- --debug |
+ ffplay -framerate 30 -video_size 920x550 -pixel_format rgb24 -f rawvideo pipe:0 2>/dev/null
diff --git a/evc/spec.md b/evc/spec.md
index b22fbb6..a6994e0 100644
--- a/evc/spec.md
+++ b/evc/spec.md
@@ -8,11 +8,11 @@
- frames (repeated [frame count]-times)
- block type
- block
- - **I-Block** (literal contents)
+ - **Literal-Block** (pixels saved)
- pixels: _`[[u8; 3]]`_
- **Split-Block** (delegated to 2 sub-blocks split on the longest axis)
- sub-blocks: _`[block; 2]` (see above)_
- - **Reference-Block**
+ - **Reference-Block** (reuses previous frame in some way)
- translation: _`i8, i8`_
### Todo
diff --git a/evc/src/block.rs b/evc/src/block.rs
index 024adb6..929793d 100644
--- a/evc/src/block.rs
+++ b/evc/src/block.rs
@@ -3,7 +3,7 @@ use anyhow::bail;
use crate::{
pixel::Pixel,
ser::{Ser, Sink, Source},
- vec2::Vec2,
+ vec2::{Small, Vec2},
};
#[derive(Clone, Debug)]
@@ -27,7 +27,7 @@ impl Block {
}
Block::Reference { translation } => {
sink.put(2u8)?;
- sink.put(*translation)?;
+ sink.put(Small(*translation))?;
}
}
Ok(())
@@ -54,7 +54,7 @@ impl Block {
[a, b]
})),
2 => Block::Reference {
- translation: source.get()?,
+ translation: source.get::<Small<Vec2>>()?.0,
},
x => bail!("corrupt block type ({})", x),
})
diff --git a/evc/src/debug.rs b/evc/src/debug.rs
index cbc598e..0858fe4 100644
--- a/evc/src/debug.rs
+++ b/evc/src/debug.rs
@@ -25,10 +25,13 @@ impl Frame {
let (mut cx, mut cy) = (sx, sy);
let mut lc = 0.0;
while lc < len {
- self[Vec2 {
- x: cx as isize,
- y: cy as isize,
- }] = color;
+ self.set(
+ Vec2 {
+ x: cx as isize,
+ y: cy as isize,
+ },
+ color,
+ );
lc += 0.5;
cx += nx * 0.5;
cy += ny * 0.5;
diff --git a/evc/src/frame.rs b/evc/src/frame.rs
index 81390a2..3c40a3d 100644
--- a/evc/src/frame.rs
+++ b/evc/src/frame.rs
@@ -49,6 +49,11 @@ impl Frame {
pub fn view_area_mut<'a>(&'a mut self, offset: Vec2, size: Vec2) -> View<&'a mut Frame> {
View::new(self, offset, size)
}
+ pub fn set(&mut self, pos: Vec2, color: Pixel) {
+ if pos.x >= 0 && pos.y >= 0 && pos.x < self.size.x && pos.y < self.size.y {
+ self[pos] = color
+ }
+ }
}
impl Index<Vec2> for Frame {
diff --git a/evc/src/ser.rs b/evc/src/ser.rs
index 61ca684..98d6706 100644
--- a/evc/src/ser.rs
+++ b/evc/src/ser.rs
@@ -93,6 +93,18 @@ impl Ser for u8 {
Ok(buf[0])
}
}
+impl Ser for i8 {
+ fn write(&self, sink: &mut impl Write) -> anyhow::Result<()> {
+ Ok(sink
+ .write_all(&unsafe { std::mem::transmute_copy::<_, [u8; 1]>(self) })
+ .context("write i8")?)
+ }
+ fn read(source: &mut impl Read) -> anyhow::Result<Self> {
+ let mut buf = [0u8; 1];
+ source.read_exact(&mut buf)?;
+ Ok(unsafe { std::mem::transmute_copy(&buf) })
+ }
+}
impl Ser for u16 {
fn write(&self, sink: &mut impl Write) -> anyhow::Result<()> {
Ok(sink
diff --git a/evc/src/vec2.rs b/evc/src/vec2.rs
index b1dd1b4..8b01fdb 100644
--- a/evc/src/vec2.rs
+++ b/evc/src/vec2.rs
@@ -26,6 +26,21 @@ impl Ser for Vec2 {
}
}
+pub struct Small<T>(pub T);
+impl Ser for Small<Vec2> {
+ fn write(&self, sink: &mut impl std::io::Write) -> anyhow::Result<()> {
+ sink.put((self.0.x as i8, self.0.y as i8))
+ }
+
+ fn read(source: &mut impl std::io::Read) -> anyhow::Result<Self> {
+ let (x, y): (i8, i8) = source.get()?;
+ Ok(Small(Vec2 {
+ x: x as isize,
+ y: y as isize,
+ }))
+ }
+}
+
impl std::ops::Add for Vec2 {
type Output = Vec2;
#[inline]