5 releases

Uses new Rust 2024

new 0.2.2 May 17, 2025
0.2.1 May 15, 2025
0.2.0 Apr 27, 2025
0.1.1 Feb 21, 2025
0.0.1 Feb 9, 2025

#74 in Video

Download history 248/week @ 2025-02-09 145/week @ 2025-02-16 29/week @ 2025-02-23 19/week @ 2025-03-02 4/week @ 2025-03-09 3/week @ 2025-04-06 2/week @ 2025-04-13 134/week @ 2025-04-27 16/week @ 2025-05-04 171/week @ 2025-05-11

321 downloads per month
Used in 3 crates

MIT/Apache

285KB
4.5K SLoC

scuffle-h264

[!WARNING]
This crate is under active development and may not be stable.

License: MIT OR Apache-2.0 docs.rs crates.io GitHub Actions: ci Codecov


A pure Rust implementation of the H.264 (header only) builder and parser.

This crate is designed to provide a simple and safe interface to build and parse H.264 headers.

See the changelog for a full release history.

Feature flags

  • docs — Enables changelog and documentation of feature flags

Examples

Parsing

use std::io;

use bytes::Bytes;

use scuffle_h264::{AVCDecoderConfigurationRecord, Sps};

// A sample h264 bytestream to parse

// Parsing
let result = AVCDecoderConfigurationRecord::parse(&mut io::Cursor::new(bytes)).unwrap();

// Do something with it!

// You can also parse an Sps from the Sps struct:
let sps = Sps::parse_with_emulation_prevention(io::Cursor::new(&result.sps[0]));

For more examples, check out the tests in the source code for the parse function.

Building

use bytes::Bytes;

use scuffle_h264::{AVCDecoderConfigurationRecord, AvccExtendedConfig, Sps, SpsExtended};

let extended_config = AvccExtendedConfig {
    chroma_format_idc: 1,
    bit_depth_luma_minus8: 0,
    bit_depth_chroma_minus8: 0,
    sequence_parameter_set_ext: vec![SpsExtended {
        chroma_format_idc: 1,
        separate_color_plane_flag: false,
        bit_depth_luma_minus8: 2,
        bit_depth_chroma_minus8: 3,
        qpprime_y_zero_transform_bypass_flag: false,
        scaling_matrix: vec![],
    }],
};
let config = AVCDecoderConfigurationRecord {
    configuration_version: 1,
    profile_indication: 100,
    profile_compatibility: 0,
    level_indication: 31,
    length_size_minus_one: 3,
    sps: vec![
        Bytes::from_static(b"spsdata"),
    ],
    pps: vec![Bytes::from_static(b"ppsdata")],
    extended_config: Some(extended_config),
};

// Creating a buffer to store the built bytestream
let mut built = Vec::new();

// Building
config.build(&mut built).unwrap();

// Do something with it!

For more examples, check out the tests in the source code for the build function.

License

This project is licensed under the MIT or Apache-2.0 license. You can choose between one of them if you use this work.

SPDX-License-Identifier: MIT OR Apache-2.0

Dependencies

~0.3–1MB
~17K SLoC