scuffle_h264/
lib.rs

1//! A pure Rust implementation of the H.264 (header only) builder and parser.
2//!
3//! This crate is designed to provide a simple and safe interface to build and parse H.264 headers.
4#![cfg_attr(feature = "docs", doc = "\n\nSee the [changelog][changelog] for a full release history.")]
5#![cfg_attr(feature = "docs", doc = "## Feature flags")]
6#![cfg_attr(feature = "docs", doc = document_features::document_features!())]
7//! ## Examples
8//!
9//! ### Parsing
10//!
11//! ```rust
12//! use std::io;
13//!
14//! use scuffle_bytes_util::zero_copy::Deserialize;
15//!
16//! use scuffle_h264::{AVCDecoderConfigurationRecord, Sps};
17//!
18//! // A sample h264 bytestream to parse
19//! # let bytes = b"\x01d\0\x1f\xff\xe1\0\x17\x67\x64\x00\x1F\xAC\xD9\x41\xE0\x6D\xF9\xE6\xA0\x20\x20\x28\x00\x00\x00\x08\x00\x00\x01\xE0\x01\0\x06h\xeb\xe3\xcb\"\xc0\xfd\xf8\xf8\0";
20//!
21//! // Parsing
22//! let result = AVCDecoderConfigurationRecord::deserialize(scuffle_bytes_util::zero_copy::Slice::from(&bytes[..])).unwrap();
23//!
24//! // Do something with it!
25//!
26//! // You can also parse an Sps from the Sps struct:
27//! let sps = Sps::parse_with_emulation_prevention(io::Cursor::new(&result.sps[0]));
28//! ```
29//!
30//! For more examples, check out the tests in the source code for the parse function.
31//!
32//! ### Building
33//!
34//! ```rust
35//! use scuffle_bytes_util::BytesCow;
36//! use scuffle_bytes_util::zero_copy::Serialize;
37//!
38//! use scuffle_h264::{AVCDecoderConfigurationRecord, AvccExtendedConfig, Sps, SpsExtended};
39//!
40//! let extended_config = AvccExtendedConfig {
41//!     chroma_format_idc: 1,
42//!     bit_depth_luma_minus8: 0,
43//!     bit_depth_chroma_minus8: 0,
44//!     sequence_parameter_set_ext: vec![SpsExtended {
45//!         chroma_format_idc: 1,
46//!         separate_color_plane_flag: false,
47//!         bit_depth_luma_minus8: 2,
48//!         bit_depth_chroma_minus8: 3,
49//!         qpprime_y_zero_transform_bypass_flag: false,
50//!         scaling_matrix: vec![],
51//!     }],
52//! };
53//! let config = AVCDecoderConfigurationRecord {
54//!     configuration_version: 1,
55//!     profile_indication: 100,
56//!     profile_compatibility: 0,
57//!     level_indication: 31,
58//!     length_size_minus_one: 3,
59//!     sps: vec![
60//!         BytesCow::from_static(b"spsdata"),
61//!     ],
62//!     pps: vec![BytesCow::from_static(b"ppsdata")],
63//!     extended_config: Some(extended_config),
64//! };
65//!
66//! // Creating a buffer to store the built bytestream
67//! let mut built = Vec::new();
68//!
69//! // Building
70//! config.serialize(&mut built).unwrap();
71//!
72//! // Do something with it!
73//! ```
74//!
75//! For more examples, check out the tests in the source code for the build function.
76//!
77//! ## License
78//!
79//! This project is licensed under the MIT or Apache-2.0 license.
80//! You can choose between one of them if you use this work.
81//!
82//! `SPDX-License-Identifier: MIT OR Apache-2.0`
83#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))]
84#![cfg_attr(docsrs, feature(doc_auto_cfg))]
85#![deny(missing_docs)]
86#![deny(unsafe_code)]
87#![deny(unreachable_pub)]
88#![deny(clippy::mod_module_files)]
89
90#[cfg(feature = "isobmff")]
91pub mod boxes;
92mod config;
93mod enums;
94mod sps;
95
96pub use enums::*;
97pub use sps::*;
98
99pub use self::config::{AVCDecoderConfigurationRecord, AvccExtendedConfig};
100
101/// Changelogs generated by [scuffle_changelog]
102#[cfg(feature = "docs")]
103#[scuffle_changelog::changelog]
104pub mod changelog {}