Pretty Fast Video

Minimal video codec designed as a successor to Pretty Good Video

Goals are to improve:

Current codec version is 2.0.0

Usage

Encoding Video

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

```rs use pfv_rs::enc::Encoder;

let outvideo = File::create("myvideo.pfv").unwrap(); let mut enc = Encoder::new(outvideo, width, height, framerate, quality, numthreads).unwrap();

// feed in frames as VideoFrames (1 keyframe every 15 frames) for (idx, frame) in &myframes.iter().enumerate() { if idx % 15 == 0 { enc.encodeiframe(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 pfvrs::dec::Decoder and call advancedelta every frame, passing in elapsed time since previous frame, and handling frames using a closure:

```rs use pgv_rs::dec::Decoder;

let mut dec = Decoder::new(myfile, numthreads).unwrap();

while dec.advancedelta(deltatime, &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.

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.