Designed as successor to Pretty-Good-Video for improved codec structure, API design & performance

Overview

Pretty Fast Video

Minimal video codec designed as a successor to Pretty Good Video

Goals are to improve:

  • Quality
  • API design
  • Codec structure
  • (Hopefully) performance

Current codec version is 2.1.1

Why?

The goal of PFV is to be to video what QOA is to audio - that is, an extremely minimal codec that aims to prioritize simplicity and decoding speed over compression ratio, is completely free for use, and aimed at playing back video in offline applications such as games.

The primary target to beat for performance has been Theora. While this Rust library does not manage to beat Theora's decoding performance, I have written an accompanying pure C library which does beat Theora's decoding performance (especially when scaled to use all available cores in the system, as it is an extremely parallel algorithm): libpfvdec

A future target to explore would be GPU decoding via compute shaders - as each macroblock can already be processed completely in parallel, it should be simple to upload DCT coefficients and perform decoding completely on the GPU, decoding directly into a game-ready texture.

Usage

Encoding Video

Create pfv_rs::enc::Encoder, feed in frames, and then write results:

use pfv_rs::enc::Encoder;

let out_video = File::create("my_video.pfv").unwrap();
let mut enc = Encoder::new(out_video, width, height, framerate, quality, num_threads).unwrap();

// feed in frames as VideoFrames (1 keyframe every 15 frames)
for (idx, frame) in &my_frames.iter().enumerate() {
  if idx % 15 == 0 {
    enc.encode_iframe(frame).unwrap();
  } else {
    enc.encode_pframe(frame).unwrap();
  }
}

// finish PFV stream (will also be automatically called if encoder is dropped)
enc.finish().unwrap();

Decoding Video

Create pfv_rs::dec::Decoder and call advance_delta every frame, passing in elapsed time since previous frame, and handling frames using a closure:

use pgv_rs::dec::Decoder;

let mut dec = Decoder::new(my_file, num_threads).unwrap();

while dec.advance_delta(delta_time, &mut |frame| {
    // do something with returned &VideoFrame
}).unwrap() {}

Alternatively, you may call advance_frame to skip directly to the next frame without passing a delta parameter. The signature is the same.

Both functions will also return Ok(true) if there is more data to read in the file, or Ok(false) if the decoder has reached the end of the file.

Algorithm Overview

Video frame encoding is pretty standard as far as video codecs go. Frames are split into 16x16 macroblocks, which are further divided into 8x8 subblocks. Each subblock is DCT transformed & quantized to reduce the number of bits required for storage. Coefficients are further compressed using entropy coding.

PFV also employs 4:2:0 chroma subsampling - so U and V chroma planes are half the size of the Y plane on each axis.

There are three kinds of frames: drop frames, i-frames, and p-frames.

  • Drop frames encode nothing, and are just treated as being unchanged since the previous frame.
  • I-Frames just encode a full frame.
  • P-Frames encode a frame as a delta from the previous frame. Each macroblock has a pixel offset from the previous frame to copy from, and the macroblock may also encode the per-pixel delta from previous frame (quantized to the 0..255 range).

Audio

Audio has been removed from the spec as of codec version 2.0.0

You may use any audio stream format of choice with PFV video streams, whether this be embedded in some kind of container format or just shipped alongside the video files. For lightweight CPU requirements, QOA is a decent choice for audio tracks.

You might also like...
g3k: Generate Good-looking GPG Keys

g3k: Generate Good-looking GPG Keys Yet another vanity key generator. Usage: git clone https://github.com/bnoctis/g3k cd g3k cargo build --release tar

Recompile Rust faster. Good for your flow state.

plonk Plonk is a development-time build tool for Rust projects. cargo install cargo-plonk # fn main() { # lib::say_hello(); # } $ cargo build -p exam

SKYULL is a command-line interface (CLI) in development that creates REST API project structure templates with the aim of making it easy and fast to start a new project.

SKYULL is a command-line interface (CLI) in development that creates REST API project structure templates with the aim of making it easy and fast to start a new project. With just a few primary configurations, such as project name, you can get started quickly.

The Amp programming language: a language designed for building high performance systems.

A language designed for building high performance systems. Platform Support x86_64-pc-windows ✅ x86_64-unknown-linux ⚠️ untested x86_64-unknown-darwin

Local-first high performance codebase index engine designed for AI

CodeIndex CodeIndex is a local-first high performance codebase index engine designed for AI. It helps your LLM understand the structure and semantics

A lightweight and high-performance order-book designed to process level 2 and trades data. Available in Rust and Python

ninjabook A lightweight and high-performance order-book implemented in Rust, designed to process level 2 and trades data. Available in Python and Rust

Desktop app for reading and downloading manga. With clean distraction-free design and no clutter

Tonbun Tonbun is a desktop app for reading and downloading manga. With clean distraction-free design and no clutter. Build with Rust, Tauri, Vue.js, a

Service-Oriented Design Patterns for Rust

SOD: Service-Oriented Design Overview This crate provides Service, MutService, and AsyncService traits and associated utilities to facilitiate service

📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.
📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.

📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.

Comments
  • Investigate alternative integer/fixed-point DCT

    Investigate alternative integer/fixed-point DCT

    Current DCT implementation likely leaves a lot on the table, performance wise. Should investigate alternatives with an eye towards including decoding performance in particular

    opened by GlaireDaggers 2
  • Pretty bad artifacting in delta coding

    Pretty bad artifacting in delta coding

    New version of codec seems to produce some patches of extreme noise during p-frames.

    I suspect the change to remove the >>1 from the delta coding may be to blame? Perhaps overflowing something internally, causing a patch of garbage data which doesn't recover until the next i-frame.

    opened by GlaireDaggers 1
  • Switch to fixed-point algorithm

    Switch to fixed-point algorithm

    Currently with larger keyframe intervals (even at just 60 frames) accumulating errors are very noticeable and result in a "pulsing" behavior.

    Will likely need to switch to a fixed-point integer algorithm instead, so that any error is 100% predictable can be precisely accounted for in the encoder.

    opened by GlaireDaggers 1
Owner
Hazel Stagner
Hazel Stagner
A web-based streaming service with improved privacy, performance, and simplicity.

Majiix Majiix is a web-based open-source streaming service. The backend that handles the core streaming logic is written in Rust and makes use of cutt

Majgix 3 Nov 21, 2023
The cutest successor of cowsay.

kittysay The cutest successor of cowsay. ---- < meow > ---- \ \ /l、 (゚、 。 7 l ~ヽ じしf_,)ノ Installation Cargo cargo

uncenter 28 Mar 12, 2024
CLI for video images. Generates animated video contact sheets fast.

vimg CLI for video images. Generate animated video contact sheets fast. Uses ffmpeg. Note: Support for animated avif isn't everywhere yet, try viewing

Alex Butler 4 Mar 12, 2023
ratlab is a programming platform designed loosely for hobbyist and masochist to analyse and design stuff and things that transform our world?

ratlab A programming language developed by Quinn Horton and Jay Hunter. ratlab is a programming platform designed loosely for hobbyists and masochists

Jay 10 Sep 4, 2023
Improved Notion data entry, at the command line

notion-entry NOTE: This project is a work in progress and has a pile of FIXMEs This program lets you input data into Notion from the command line. It

Jade Lovelace 1 Jan 16, 2022
A community improved version of the polycubes project!

Polycubes This code is associated with the Computerphile video on generating polycubes. The original repository may be found here. That version is unc

Michael Pound 30 Jul 26, 2023
A high-performance Rust library designed to seamlessly integrate with the Discord API.

Rucord - Rust Library for Discord API Interactions Note: This library is currently under development and is not yet recommended for production use. Ov

Coders' Collab 4 Feb 26, 2023
A small CLI tool to query ArcGIS REST API services, implemented in Rust. The server response is returned as pretty JSON.

A small CLI tool to query ArcGIS REST API services, implemented in Rust. The server response is returned as pretty JSON.

Andrew Vitale 2 Apr 25, 2022
Fls - Ferris-LS, a very bad LS replacement. Besides that, proves that I suck at clean & good code.

FLS A handy ls remake, purely for learning. Why FLS? There's no reason, at all, don't use it. I just want to learn Rust :D Usage Flags: -i = Use icons

florida 6 Jan 24, 2022
Firefox used to have this feature a while back (from Firefox 11 to 46) and it is so good, that I feel it needs revival.

3D WebPage Inspector By: Seanpm2001, Et; Al. Top README.md Read this article in a different language Sorted by: A-Z Sorting options unavailable ( af A

Sean P. Myrick V19.1.7.2 3 Nov 10, 2022