DSV2 is a lossy/lossless video codec using wavelets and block-based motion compensation. It performs best at medium-low to medium-high bitrates at resolutions between ~352x288 (CIF) to 1920x1080 (FHD). Comparable to MPEG-4 Part 2 and Part 10 (H.264) (P frames only) in terms of efficiency and quality.
Stefan CIF minih264:
minih264_gop60.mp4
DSV2:
dsv2_gop60.mp4
- compression using multiresolution subband analysis instead of DCT
- also known as a wavelet transform
- up to quarter-pixel motion compensation
- 4:1:0, 4:1:1, 4:2:0, 4:2:2 (+ UYVY) and 4:4:4 chroma subsampling formats
- adaptive quantization
- in-loop filtering
- lossless coding support
- intra and inter frames with variable length closed GOP
- no bidirectional prediction (also known as B-frames). Only forward prediction with previous picture as reference
- in-loop filtering after motion compensation
- more adaptive quantization potential
- skip blocks for temporal stability
- new subband filters + support for adaptive subband filtering
- better motion compensation through Expanded Prediction Range Mode (EPRM)
- quarter pixel compensation
- lossless coding support
- psychovisual optimizations in the codec and encoder design
--- for more detailed information please refer to the informal specification document (DSV2_spec.pdf) in the repository.
- single pass average bitrate (ABR) or constant rate factor (CRF) rate control
- more advanced Human Visual System (HVS) based intra block mode determination
- new Human Visual System (HVS) based intra frame adaptive quantization
- more complex scene change detection
- hierarchical motion estimation
- better temporal adaptive quantization
- written to be compatible with C89
--- for more detailed information please refer to the encoder information document (DSV2_encoder.pdf) in the repository.
- no built-in interlacing support
- only 8 bits of depth per component supported
- frame sizes must be divisible by two
This code follows my self-imposed restrictions:
- Everything must be done in software, no explicit usage of hardware acceleration.
- No floating point types or literals, everything must be integer only.
- No 3rd party libraries, only C standard library and OS libraries for window, input, etc.
- No languages used besides C.
- No compiler specific features and no SIMD.
- Single threaded.
All you need is a C compiler.
In the root directory of the project (with all the .h and .c files):
cc -O3 -o dsv2 *.c
If you have Zig installed, you can use the build.zig file to compile the project. Building requires Zig version ≥0.13.0
.
-
Ensure you have Zig & git installed
-
Clone this repo & enter the cloned directory:
git clone https://github.com/LMP88959/Digital-Subband-Video-2
cd Digital-Subband-Video-2
- Build the binary with Zig:
zig build
Note: If you'd like to specify a different build target from your host OS/architecture, simply supply the target flag. Example:
zig build -Dtarget=x86_64-linux-gnu
- Find the build binary in
zig-out/bin
. You can install it like so:
sudo cp zig-out/bin/dsv2 /usr/local/bin
Now, you should be all set to use the compiled dsv2
binary.
Sample usage:
./dsv2 e -inp=video.y4m -out=compressed.dsv -y4m=1 -qp=60 -gop=48
Sample usage:
./dsv2 d -inp=video.dsv -out=decompressed.y4m -y4m=1 -out420p=1
NOTE: if -inp= and -out= are not specified, it will default to standard in / out (stdin/stdout). Only .yuv (one file containing all the frames) and .y4m files are supported as inputs to the encoder.
This codec is by no means fully optimized, so there is a lot of room for performance gains. It performs quite well for what it is though.
Check out this open source / work in progress wavelet codec testbench by Gianni Rosato!
https://github.com/gianni-rosato/wavelet-bench
If you have any questions feel free to leave a comment on YouTube OR join the King's Crook Discord server :)
YouTube: https://www.youtube.com/@EMMIR_KC/videos
Discord: https://discord.gg/hdYctSmyQJ
itch.io: https://kingscrook.itch.io/kings-crook
The H.264 file sizes were within a few kilobytes of their respective DSV2 file size.
H.264 examples were encoded using https://github.com/lieff/minih264 using -speed0 (best quality) unless otherwise stated
DSV2 examples were encoded with -effort=10 (best quality)
Husky CIF - 29.97fps, GOP = 60 minih264:
h_minih264_gop60.mp4
DSV2:
h_dsv2_gop60.mp4
Mobile CIF - 29.97fps, GOP = 60 minih264:
m_minih264_gop60.mp4
DSV2:
m_dsv2_gop60.mp4
Parkrun 1280x720 - 50fps, GOP = 250
minih264:
p_minih264_gop250.mp4
x264 (encoded via ffmpeg with -c:v libx264 -preset superfast -crf 29.8 -refs 1 -coder vlc -bf 0 -g 250
):
p_x264_gop250.mp4
DSV2: (Note this video here had to be re-encoded to fit under 10MB. I re-encoded with x264 CRF 22.5 with the veryslow preset)