#less #bit #advanced #encoder #coding #encoding

no-std less-avc

less Advanced Video Coding (H.264) encoding

6 releases

0.1.5 Aug 29, 2023
0.1.4 May 24, 2023
0.1.3 Mar 30, 2023
0.1.2 Nov 20, 2022

#57 in Video

Download history 227/week @ 2023-12-14 57/week @ 2023-12-21 43/week @ 2023-12-28 50/week @ 2024-01-04 100/week @ 2024-01-11 258/week @ 2024-01-18 693/week @ 2024-01-25 425/week @ 2024-02-01 344/week @ 2024-02-08 127/week @ 2024-02-15 288/week @ 2024-02-22 496/week @ 2024-02-29 269/week @ 2024-03-07 244/week @ 2024-03-14 145/week @ 2024-03-21 314/week @ 2024-03-28

1,075 downloads per month

MIT/Apache

62KB
1.5K SLoC

less-avc - Less Advanced Video Coding - H.264 Encoder

Crates.io Documentation Crate License

This module contains a pure Rust implementation of an H.264 encoder optimized for lossless encoding. It is simple ("less advanced") and uses a small subset of the encoder features in the H.264 specification.

Features and characteristics:

  • Pure rust.
  • No use of unsafe.
  • Lossless encoding of 8 bit and 12 bit monochrome (luminance only 4:0:0) and color (4:2:0) data.
  • Includes an optimized path for luminance-only data in which no chroma data is saved.
  • Encodes using ALL-Intra, also called All-I. Every frame is recorded as an I (intra) frame (also "keyframe") using PCM encoding.
  • Tests decode image with openh264 and ffmpeg to ensure encoded image is losslessly preserved.
  • Can be compiled without using the rust standard library std. In other words, the no_std attribute is specified. (A global allocator is required.)

Desired but not implemented feature:

  • Support for other bit-depths and chroma sampling resolutions (e.g. 4:4:4).

Worthy of consideration features:

  • Support for context-adaptive variable-length coding (CAVLC).
  • Support for context-adaptive binary arithmetic coding (CABAC).

This was inspired by Ben Mesander's World's Smallest H.264 Encoder.

Testing

Run the basic tests with:

cargo test

Full round-trip tests with ffmpeg and openh264 are in the testbench directory and crate. For those:

cd testbench
cargo test

These tests can export the created streams to .h264 files if the LESSAVC_SAVE_TEST_H264 environment variable is set. (To view the location where the .h264 files are saved, run the tests with cargo test -- --nocapture.) To convert these to .mp4:

#!/bin/bash -x
set -o errexit

FILES="./*.h264"
for f in $FILES
do
    echo "Processing $f file..."
    ffmpeg -i $f -vcodec copy $f.mp4
    # ffmpeg -i $f $f.png
done

Benchmarking

Benchmarks are in the testbench directory and crate:

cd testbench
cargo bench

# Or, to benckmark while compiling for the native CPU architecture, like so:
RUSTFLAGS='-C target-cpu=native' cargo bench

License

Copyright 2022-2023 Andrew D. Straw.

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.

Dependencies

~1MB
~28K SLoC