Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
773e965
Support hvc1 box & enable simple access of hevc parameter sets
j-baker Oct 22, 2023
bfc1626
remove println
j-baker Oct 22, 2023
9c44199
clippy
j-baker Oct 22, 2023
7360c5c
support sidx
damitha-canva Dec 23, 2024
da7debf
reader update
damitha-canva Dec 23, 2024
aaee94a
Merge pull request #1 from morphkurt/sidx
morphkurt Dec 23, 2024
58c8dc1
.
damithag Mar 17, 2025
b2caeaf
opus support
damithag Mar 18, 2025
7889981
.
damithag Mar 18, 2025
c96f92f
Merge pull request #2 from morphkurt/opus-support
morphkurt Mar 18, 2025
f483d55
.
damithag Mar 18, 2025
8e0b548
.
damithag Mar 18, 2025
37bc464
.
damithag Mar 18, 2025
6232617
.
damithag Mar 18, 2025
d33ea6e
.
damithag Mar 19, 2025
e850368
.
damithag Mar 19, 2025
1199aa8
.
damithag Mar 19, 2025
284e01d
.
damithag Mar 19, 2025
1eda162
.
damithag Mar 20, 2025
792a922
.
damithag Mar 21, 2025
b388238
.
damithag Mar 21, 2025
c032eef
.
damithag Mar 21, 2025
c7cf24e
.
damithag Mar 21, 2025
2d8a14f
.
damithag Mar 21, 2025
b7ca802
.
damithag Mar 21, 2025
b9d5efa
.
damithag Mar 21, 2025
3236012
.
damithag Mar 21, 2025
8b47da9
.
damithag Mar 21, 2025
f085d79
.
damithag Mar 22, 2025
4e0db2a
.
damithag Mar 22, 2025
231d70d
.
damithag Mar 23, 2025
666939e
.
damithag Mar 24, 2025
b4dbe3f
.
damithag Mar 24, 2025
2422925
.
damithag Mar 24, 2025
263d205
.
damithag Mar 24, 2025
14934c0
.
damithag Mar 24, 2025
79c0ccf
.
damithag Mar 24, 2025
8747b9a
.
damithag Mar 24, 2025
21ce6a9
.
damithag Mar 24, 2025
b780ef0
.
damithag Mar 24, 2025
d2e69b9
.
damithag Mar 24, 2025
8f13262
Merge remote-tracking branch 'upstream1/jbaker/hvc1'
damithag Mar 25, 2025
90d089b
.
damithag Mar 25, 2025
3f9084d
.
damithag Mar 25, 2025
b06846e
.
damithag Mar 26, 2025
4807dc2
.
damithag Mar 26, 2025
0e70b58
.
damithag Mar 26, 2025
caf699f
.
damithag Mar 26, 2025
485d9c9
Implement detailed writing of HVCC configuration data in Hvc1Box, inc…
damithag Mar 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mp4"
version = "0.14.0"
version = "0.15.0"
authors = ["Alf <alf.g.jr@gmail.com>"]
edition = "2018"
description = "MP4 reader and writer library in Rust."
Expand Down
52 changes: 46 additions & 6 deletions examples/mp4copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::io::{self, BufReader, BufWriter};
use std::path::Path;

use mp4::{
AacConfig, AvcConfig, HevcConfig, MediaConfig, MediaType, Mp4Config, Result, TrackConfig,
TtxtConfig, Vp9Config,
AacConfig, AvcConfig, HevcBoxType, HevcConfig, MediaConfig, MediaType, Mp4Config, OpusConfig, Result, TrackConfig, TtxtConfig, Vp9Config
};

fn main() {
Expand Down Expand Up @@ -51,18 +50,59 @@ fn copy<P: AsRef<Path>>(src_filename: &P, dst_filename: &P) -> Result<()> {
pic_param_set: track.picture_parameter_set()?.to_vec(),
}),
MediaType::H265 => MediaConfig::HevcConfig(HevcConfig {
width: track.width(),
height: track.height(),
width: Some(track.width()),
height: Some(track.height()),
configuration_version: Some(1),
general_profile_space: Some(0),
general_tier_flag: Some(false),
general_profile_idc: Some(1),
general_profile_compatibility_flags: Some(0),
general_constraint_indicator_flag: Some(0),
general_level_idc: Some(93),
min_spatial_segmentation_idc: Some(0),
parallelism_type: Some(0),
chroma_format_idc: Some(1),
bit_depth_luma_minus8: Some(0),
bit_depth_chroma_minus8: Some(0),
avg_frame_rate: Some(0),
constant_frame_rate: Some(0),
num_temporal_layers: Some(1),
temporal_id_nested: Some(false),
length_size_minus_one: Some(3),
arrays: Some(vec![]),
use_hvc1: true,
}),
MediaType::VP9 => MediaConfig::Vp9Config(Vp9Config {
width: track.width(),
height: track.height(),
}),
MediaType::AAC => MediaConfig::AacConfig(AacConfig {
MediaType::AAC => {
let default_aac_config = AacConfig::default();
MediaConfig::AacConfig(AacConfig {
bitrate: track.bitrate(),
profile: track.audio_profile()?,
freq_index: track.sample_freq_index()?,
chan_conf: track.channel_config()?,
samplesize: 16,
data_reference_index: 1,
sound_version: 0,
esds_version: default_aac_config.esds_version,
esds_flags: default_aac_config.esds_flags,
es_id: default_aac_config.es_id,
object_type_indication: default_aac_config.object_type_indication,
stream_type: default_aac_config.stream_type,
up_stream: default_aac_config.up_stream,
buffer_size_db: default_aac_config.buffer_size_db,
max_bitrate: default_aac_config.max_bitrate,
avg_bitrate: default_aac_config.avg_bitrate,
qt_bytes: default_aac_config.qt_bytes,
})
}
MediaType::OPUS => MediaConfig::OpusConfig(OpusConfig {
bitrate: track.bitrate(),
profile: track.audio_profile()?,
freq_index: track.sample_freq_index()?,
chan_conf: track.channel_config()?,
pre_skip: 0,
}),
MediaType::TTXT => MediaConfig::TtxtConfig(TtxtConfig {}),
};
Expand Down
3 changes: 3 additions & 0 deletions examples/mp4dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ fn get_boxes(file: File) -> Result<Vec<Box>> {
if let Some(ref hev1) = &stbl.stsd.hev1 {
boxes.push(build_box(hev1));
}
if let Some(ref hvc1) = &stbl.stsd.hvc1 {
boxes.push(build_box(hvc1));
}
if let Some(ref mp4a) = &stbl.stsd.mp4a {
boxes.push(build_box(mp4a));
}
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub enum Error {
BoxInTrakNotFound(u32, BoxType),
#[error("traf[{0}].{1} not found")]
BoxInTrafNotFound(u32, BoxType),
#[error("trak[{0}].stbl.{1} not found")]
BoxInStblNotFound(u32, BoxType),
#[error("trak[{0}].stbl.{1:?} not found")]
BoxInStblNotFound(u32, Vec<BoxType>),
#[error("trak[{0}].stbl.{1}.entry[{2}] not found")]
EntryInStblNotFound(u32, BoxType, u32),
#[error("traf[{0}].trun.{1}.entry[{2}] not found")]
Expand Down
52 changes: 48 additions & 4 deletions src/mp4box/hev1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,34 @@ impl Default for Hev1Box {

impl Hev1Box {
pub fn new(config: &HevcConfig) -> Self {
Hev1Box {
Self {
data_reference_index: 1,
width: config.width,
height: config.height,
width: config.width.unwrap_or(0),
height: config.height.unwrap_or(0),
horizresolution: FixedPointU16::new(0x48),
vertresolution: FixedPointU16::new(0x48),
frame_count: 1,
depth: 0x0018,
hvcc: HvcCBox::new(),
hvcc: HvcCBox {
configuration_version: config.configuration_version.unwrap_or(1),
general_profile_space: config.general_profile_space.unwrap_or(0),
general_tier_flag: config.general_tier_flag.unwrap_or(false),
general_profile_idc: config.general_profile_idc.unwrap_or(1),
general_profile_compatibility_flags: config.general_profile_compatibility_flags.unwrap_or(0),
general_constraint_indicator_flag: config.general_constraint_indicator_flag.unwrap_or(0),
general_level_idc: config.general_level_idc.unwrap_or(93),
min_spatial_segmentation_idc: config.min_spatial_segmentation_idc.unwrap_or(0),
parallelism_type: config.parallelism_type.unwrap_or(0),
chroma_format_idc: config.chroma_format_idc.unwrap_or(1),
bit_depth_luma_minus8: config.bit_depth_luma_minus8.unwrap_or(0),
bit_depth_chroma_minus8: config.bit_depth_chroma_minus8.unwrap_or(0),
avg_frame_rate: config.avg_frame_rate.unwrap_or(0),
constant_frame_rate: config.constant_frame_rate.unwrap_or(0),
num_temporal_layers: config.num_temporal_layers.unwrap_or(1),
temporal_id_nested: config.temporal_id_nested.unwrap_or(false),
length_size_minus_one: config.length_size_minus_one.unwrap_or(3),
arrays: config.arrays.clone().unwrap_or_default(),
},
}
}

Expand Down Expand Up @@ -180,13 +199,38 @@ pub struct HvcCBox {
pub arrays: Vec<HvcCArray>,
}

const VPS: u8 = 32;
const SPS: u8 = 33;
const PPS: u8 = 34;

impl HvcCBox {
pub fn new() -> Self {
Self {
configuration_version: 1,
..Default::default()
}
}

fn parameter_set(&self, track_id: u32, nal_type: u8) -> Result<&[u8]> {
for array in &self.arrays {
if array.nal_unit_type == nal_type {
return Ok(&array.nalus[0].data);
}
}
Err(Error::EntryInStblNotFound(track_id, BoxType::HvcCBox, 0))
}

pub fn sequence_parameter_set(&self, track_id: u32) -> Result<&[u8]> {
self.parameter_set(track_id, SPS)
}

pub fn picture_parameter_set(&self, track_id: u32) -> Result<&[u8]> {
self.parameter_set(track_id, PPS)
}

pub fn video_parameter_set(&self, track_id: u32) -> Result<&[u8]> {
self.parameter_set(track_id, VPS)
}
}

impl Mp4Box for HvcCBox {
Expand Down
Loading
Loading