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//!
5//! ## Why do we need this?
6//!
7//! This crate aims to provides a simple and safe interface for h264.
8//!
9//! ## How is this different from other h264 crates?
10//!
11//! This crate is only for encoding and decoding H.264 headers.
12//!
13//! ## Notable features
14//!
15//! This crate is a completely safe implementation of encoding and decoding H.264 headers.
16//!
17//! We mainly use this with scuffle-mp4 and scuffle-flv to work with mp4 and flv container formats respectively.
18//!
19//! ## Examples
20//!
21//! ### Parsing
22//!
23//! ```rust
24//! use std::io;
25//!
26//! use bytes::Bytes;
27//!
28//! use scuffle_h264::{AVCDecoderConfigurationRecord, Sps};
29//!
30//! // A sample h264 bytestream to parse
31//! # let bytes = Bytes::from(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".to_vec());
32//!
33//! // Parsing
34//! let result = AVCDecoderConfigurationRecord::parse(&mut io::Cursor::new(bytes)).unwrap();
35//!
36//! // Do something with it!
37//!
38//! // You can also parse an Sps from the Sps struct:
39//! let sps = Sps::parse_with_emulation_prevention(io::Cursor::new(&result.sps[0]));
40//! ```
41//!
42//! For more examples, check out the tests in the source code for the parse function.
43//!
44//! ### Building
45//!
46//! ```rust
47//! use bytes::Bytes;
48//!
49//! use scuffle_h264::{AVCDecoderConfigurationRecord, AvccExtendedConfig, Sps, SpsExtended};
50//!
51//! let extended_config = AvccExtendedConfig {
52//! chroma_format_idc: 1,
53//! bit_depth_luma_minus8: 0,
54//! bit_depth_chroma_minus8: 0,
55//! sequence_parameter_set_ext: vec![SpsExtended {
56//! chroma_format_idc: 1,
57//! separate_color_plane_flag: false,
58//! bit_depth_luma_minus8: 2,
59//! bit_depth_chroma_minus8: 3,
60//! qpprime_y_zero_transform_bypass_flag: false,
61//! scaling_matrix: vec![],
62//! }],
63//! };
64//! let config = AVCDecoderConfigurationRecord {
65//! configuration_version: 1,
66//! profile_indication: 100,
67//! profile_compatibility: 0,
68//! level_indication: 31,
69//! length_size_minus_one: 3,
70//! sps: vec![
71//! Bytes::from_static(b"spsdata"),
72//! ],
73//! pps: vec![Bytes::from_static(b"ppsdata")],
74//! extended_config: Some(extended_config),
75//! };
76//!
77//! // Creating a buffer to store the built bytestream
78//! let mut built = Vec::new();
79//!
80//! // Building
81//! config.build(&mut built).unwrap();
82//!
83//! // Do something with it!
84//! ```
85//!
86//! For more examples, check out the tests in the source code for the build function.
87//!
88//! ## Status
89//!
90//! This crate is currently under development and is not yet stable.
91//!
92//! Unit tests are not yet fully implemented. Use at your own risk.
93//!
94//! ## License
95//!
96//! This project is licensed under the [MIT](./LICENSE.MIT) or [Apache-2.0](./LICENSE.Apache-2.0) license.
97//! You can choose between one of them if you use this work.
98//!
99//! `SPDX-License-Identifier: MIT OR Apache-2.0`
100#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))]
101#![cfg_attr(docsrs, feature(doc_cfg))]
102#![deny(missing_docs)]
103#![deny(unsafe_code)]
104#![deny(unreachable_pub)]
105
106mod config;
107mod enums;
108mod sps;
109
110pub use enums::*;
111pub use sps::*;
112
113pub use self::config::{AVCDecoderConfigurationRecord, AvccExtendedConfig};