1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2025-04-15 08:14:15 +00:00
This commit is contained in:
damitha 2025-03-26 14:52:32 +11:00
parent 3f9084df05
commit b06846e132
5 changed files with 99 additions and 11 deletions

View file

@ -51,8 +51,26 @@ 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: None,
general_profile_space: None,
general_tier_flag: None,
general_profile_idc: None,
general_profile_compatibility_flags: None,
general_constraint_indicator_flag: None,
general_level_idc: None,
min_spatial_segmentation_idc: None,
parallelism_type: None,
chroma_format_idc: None,
bit_depth_luma_minus8: None,
bit_depth_chroma_minus8: None,
avg_frame_rate: None,
constant_frame_rate: None,
num_temporal_layers: None,
temporal_id_nested: None,
length_size_minus_one: None,
arrays: None,
}),
MediaType::VP9 => MediaConfig::Vp9Config(Vp9Config {
width: track.width(),

View file

@ -39,8 +39,8 @@ impl Hev1Box {
pub fn new(config: &HevcConfig) -> Self {
Hev1Box {
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,

View file

@ -39,8 +39,8 @@ impl Hvc1Box {
pub fn new(config: &HevcConfig) -> Self {
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,

View file

@ -784,8 +784,8 @@ impl Mp4TrackWriter {
trak.mdia.minf.stbl.stsd.avc1 = Some(avc1);
}
MediaConfig::HevcConfig(ref hevc_config) => {
trak.tkhd.set_width(hevc_config.width);
trak.tkhd.set_height(hevc_config.height);
trak.tkhd.set_width(hevc_config.width.unwrap_or(0));
trak.tkhd.set_height(hevc_config.height.unwrap_or(0));
let vmhd = VmhdBox::default();
trak.mdia.minf.vmhd = Some(vmhd);

View file

@ -3,6 +3,7 @@ use std::borrow::Cow;
use std::convert::TryFrom;
use std::fmt;
use crate::hev1::HvcCArray;
use crate::mp4a::EsdsBox;
use crate::mp4box::*;
use crate::*;
@ -610,10 +611,79 @@ pub struct AvcConfig {
pub pic_param_set: Vec<u8>,
}
#[derive(Debug, PartialEq, Eq, Clone, Default)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct HevcConfig {
pub width: u16,
pub height: u16,
pub width: Option<u16>,
pub height: Option<u16>,
pub configuration_version: Option<u8>,
pub general_profile_space: Option<u8>,
pub general_tier_flag: Option<bool>,
pub general_profile_idc: Option<u8>,
pub general_profile_compatibility_flags: Option<u32>,
pub general_constraint_indicator_flag: Option<u64>,
pub general_level_idc: Option<u8>,
pub min_spatial_segmentation_idc: Option<u16>,
pub parallelism_type: Option<u8>,
pub chroma_format_idc: Option<u8>,
pub bit_depth_luma_minus8: Option<u8>,
pub bit_depth_chroma_minus8: Option<u8>,
pub avg_frame_rate: Option<u16>,
pub constant_frame_rate: Option<u8>,
pub num_temporal_layers: Option<u8>,
pub temporal_id_nested: Option<bool>,
pub length_size_minus_one: Option<u8>,
pub arrays: Option<Vec<HvcCArray>>,
}
impl Default for HevcConfig {
fn default() -> Self {
Self {
width: None,
height: None,
configuration_version: None,
general_profile_space: None,
general_tier_flag: None,
general_profile_idc: None,
general_profile_compatibility_flags: None,
general_constraint_indicator_flag: None,
general_level_idc: None,
min_spatial_segmentation_idc: None,
parallelism_type: None,
chroma_format_idc: None,
bit_depth_luma_minus8: None,
bit_depth_chroma_minus8: None,
avg_frame_rate: None,
constant_frame_rate: None,
num_temporal_layers: None,
temporal_id_nested: None,
length_size_minus_one: None,
arrays: None,
}
}
}
impl HevcConfig {
pub fn new() -> Self {
Self::default()
}
// Builder methods for each field
pub fn with_width(mut self, width: u16) -> Self {
self.width = Some(width);
self
}
pub fn with_height(mut self, height: u16) -> Self {
self.height = Some(height);
self
}
pub fn with_configuration_version(mut self, version: u8) -> Self {
self.configuration_version = Some(version);
self
}
// ... add similar methods for all other fields ...
}
#[derive(Debug, PartialEq, Eq, Clone, Default)]