mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-06-10 17:09:22 +00:00
Run cargo fmt
This commit is contained in:
parent
8a7d2ae813
commit
82f9e2580c
|
@ -4,7 +4,7 @@ use std::io::prelude::*;
|
|||
use std::io::{self, BufReader, BufWriter};
|
||||
use std::path::Path;
|
||||
|
||||
use mp4::{Result, MediaType, AvcConfig, AacConfig, MediaConfig, TrackConfig};
|
||||
use mp4::{AacConfig, AvcConfig, MediaConfig, MediaType, Result, TrackConfig};
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
@ -28,30 +28,29 @@ fn copy<P: AsRef<Path>>(src_filename: &P, dst_filename: &P) -> Result<()> {
|
|||
let writer = BufWriter::new(dst_file);
|
||||
|
||||
let mut mp4_reader = mp4::Mp4Reader::read_header(reader, size)?;
|
||||
let mut mp4_writer = mp4::Mp4Writer::write_header(writer, mp4_reader.major_brand(), mp4_reader.minor_version(), mp4_reader.compatible_brands())?;
|
||||
let mut mp4_writer = mp4::Mp4Writer::write_header(
|
||||
writer,
|
||||
mp4_reader.major_brand(),
|
||||
mp4_reader.minor_version(),
|
||||
mp4_reader.compatible_brands(),
|
||||
)?;
|
||||
|
||||
// TODO interleaving
|
||||
for track_idx in 0..mp4_reader.tracks().len() {
|
||||
if let Some(ref track) = mp4_reader.tracks().get(track_idx) {
|
||||
let media_conf = match track.media_type()? {
|
||||
MediaType::H264 => {
|
||||
MediaConfig::AvcConfig(
|
||||
AvcConfig {
|
||||
width: track.width(),
|
||||
height: track.height(),
|
||||
seq_param_set: track.sequence_parameter_set()?.to_vec(),
|
||||
pic_param_set: track.picture_parameter_set()?.to_vec(),
|
||||
})
|
||||
}
|
||||
MediaType::AAC => {
|
||||
MediaConfig::AacConfig(
|
||||
AacConfig {
|
||||
bitrate: track.bitrate(),
|
||||
profile: track.audio_profile()?,
|
||||
freq_index: track.sample_freq_index()?,
|
||||
chan_conf: track.channel_config()?,
|
||||
})
|
||||
}
|
||||
MediaType::H264 => MediaConfig::AvcConfig(AvcConfig {
|
||||
width: track.width(),
|
||||
height: track.height(),
|
||||
seq_param_set: track.sequence_parameter_set()?.to_vec(),
|
||||
pic_param_set: track.picture_parameter_set()?.to_vec(),
|
||||
}),
|
||||
MediaType::AAC => MediaConfig::AacConfig(AacConfig {
|
||||
bitrate: track.bitrate(),
|
||||
profile: track.audio_profile()?,
|
||||
freq_index: track.sample_freq_index()?,
|
||||
chan_conf: track.channel_config()?,
|
||||
}),
|
||||
};
|
||||
|
||||
let track_conf = TrackConfig {
|
||||
|
|
|
@ -238,7 +238,7 @@ pub struct NalUnit {
|
|||
impl From<&[u8]> for NalUnit {
|
||||
fn from(bytes: &[u8]) -> Self {
|
||||
Self {
|
||||
bytes: bytes.to_vec()
|
||||
bytes: bytes.to_vec(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
33
src/track.rs
33
src/track.rs
|
@ -4,7 +4,7 @@ use std::time::Duration;
|
|||
|
||||
use crate::atoms::trak::TrakBox;
|
||||
use crate::atoms::*;
|
||||
use crate::atoms::{vmhd::VmhdBox, smhd::SmhdBox, avc1::Avc1Box, mp4a::Mp4aBox};
|
||||
use crate::atoms::{avc1::Avc1Box, mp4a::Mp4aBox, smhd::SmhdBox, vmhd::VmhdBox};
|
||||
use crate::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -19,12 +19,8 @@ pub struct TrackConfig {
|
|||
impl From<MediaConfig> for TrackConfig {
|
||||
fn from(media_conf: MediaConfig) -> Self {
|
||||
match media_conf {
|
||||
MediaConfig::AvcConfig(avc_conf) => {
|
||||
Self::from(avc_conf)
|
||||
}
|
||||
MediaConfig::AacConfig(aac_conf) => {
|
||||
Self::from(aac_conf)
|
||||
}
|
||||
MediaConfig::AvcConfig(avc_conf) => Self::from(avc_conf),
|
||||
MediaConfig::AacConfig(aac_conf) => Self::from(aac_conf),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +29,7 @@ impl From<AvcConfig> for TrackConfig {
|
|||
fn from(avc_conf: AvcConfig) -> Self {
|
||||
Self {
|
||||
track_type: TrackType::Video,
|
||||
timescale: 1000, // XXX
|
||||
timescale: 1000, // XXX
|
||||
language: String::from("und"), // XXX
|
||||
media_conf: MediaConfig::AvcConfig(avc_conf),
|
||||
}
|
||||
|
@ -44,7 +40,7 @@ impl From<AacConfig> for TrackConfig {
|
|||
fn from(aac_conf: AacConfig) -> Self {
|
||||
Self {
|
||||
track_type: TrackType::Audio,
|
||||
timescale: 1000, // XXX
|
||||
timescale: 1000, // XXX
|
||||
language: String::from("und"), // XXX
|
||||
media_conf: MediaConfig::AacConfig(aac_conf),
|
||||
}
|
||||
|
@ -74,7 +70,7 @@ impl Mp4Track {
|
|||
let avc1 = Avc1Box::new(avc_config);
|
||||
trak.mdia.minf.stbl.stsd.avc1 = Some(avc1);
|
||||
}
|
||||
MediaConfig::AacConfig(ref aac_config ) => {
|
||||
MediaConfig::AacConfig(ref aac_config) => {
|
||||
let smhd = SmhdBox::default();
|
||||
trak.mdia.minf.smhd = Some(smhd);
|
||||
|
||||
|
@ -202,7 +198,10 @@ impl Mp4Track {
|
|||
|
||||
pub fn video_profile(&self) -> Result<AvcProfile> {
|
||||
if let Some(ref avc1) = self.trak.mdia.minf.stbl.stsd.avc1 {
|
||||
AvcProfile::try_from((avc1.avcc.avc_profile_indication, avc1.avcc.profile_compatibility))
|
||||
AvcProfile::try_from((
|
||||
avc1.avcc.avc_profile_indication,
|
||||
avc1.avcc.profile_compatibility,
|
||||
))
|
||||
} else {
|
||||
Err(Error::BoxInStblNotFound(self.track_id(), BoxType::Avc1Box))
|
||||
}
|
||||
|
@ -212,7 +211,11 @@ impl Mp4Track {
|
|||
if let Some(ref avc1) = self.trak.mdia.minf.stbl.stsd.avc1 {
|
||||
match avc1.avcc.sequence_parameter_sets.get(0) {
|
||||
Some(ref nal) => Ok(nal.bytes.as_ref()),
|
||||
None => Err(Error::EntryInStblNotFound(self.track_id(), BoxType::AvcCBox, 0)),
|
||||
None => Err(Error::EntryInStblNotFound(
|
||||
self.track_id(),
|
||||
BoxType::AvcCBox,
|
||||
0,
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::BoxInStblNotFound(self.track_id(), BoxType::Avc1Box))
|
||||
|
@ -223,7 +226,11 @@ impl Mp4Track {
|
|||
if let Some(ref avc1) = self.trak.mdia.minf.stbl.stsd.avc1 {
|
||||
match avc1.avcc.picture_parameter_sets.get(0) {
|
||||
Some(ref nal) => Ok(nal.bytes.as_ref()),
|
||||
None => Err(Error::EntryInStblNotFound(self.track_id(), BoxType::AvcCBox, 0)),
|
||||
None => Err(Error::EntryInStblNotFound(
|
||||
self.track_id(),
|
||||
BoxType::AvcCBox,
|
||||
0,
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::BoxInStblNotFound(self.track_id(), BoxType::Avc1Box))
|
||||
|
|
11
src/types.rs
11
src/types.rs
|
@ -70,7 +70,6 @@ impl FixedPointU16 {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl fmt::Debug for BoxType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let fourcc: FourCC = From::from(self.clone());
|
||||
|
@ -277,11 +276,11 @@ impl Into<&str> for &MediaType {
|
|||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum AvcProfile {
|
||||
AvcConstrainedBaseline, // 66 with constraint set 1
|
||||
AvcBaseline, // 66,
|
||||
AvcMain, // 77,
|
||||
AvcExtended, // 88,
|
||||
AvcHigh, // 100
|
||||
// TODO Progressive High Profile, Constrained High Profile, ...
|
||||
AvcBaseline, // 66,
|
||||
AvcMain, // 77,
|
||||
AvcExtended, // 88,
|
||||
AvcHigh, // 100
|
||||
// TODO Progressive High Profile, Constrained High Profile, ...
|
||||
}
|
||||
|
||||
impl TryFrom<(u8, u8)> for AvcProfile {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Write, Seek, SeekFrom};
|
||||
use std::io::{Seek, SeekFrom, Write};
|
||||
|
||||
use crate::atoms::*;
|
||||
use crate::*;
|
||||
|
@ -11,7 +11,12 @@ pub struct Mp4Writer<W> {
|
|||
}
|
||||
|
||||
impl<W: Write + Seek> Mp4Writer<W> {
|
||||
pub fn write_header(mut writer: W, major_brand: &FourCC, minor_version: u32, compatible_brands: &[FourCC]) -> Result<Self> {
|
||||
pub fn write_header(
|
||||
mut writer: W,
|
||||
major_brand: &FourCC,
|
||||
minor_version: u32,
|
||||
compatible_brands: &[FourCC],
|
||||
) -> Result<Self> {
|
||||
let ftyp = FtypBox {
|
||||
major_brand: major_brand.to_owned(),
|
||||
minor_version,
|
||||
|
|
12
tests/lib.rs
12
tests/lib.rs
|
@ -1,4 +1,4 @@
|
|||
use mp4::{MediaType, TrackType, AvcProfile, AudioObjectType, SampleFreqIndex, ChannelConfig};
|
||||
use mp4::{AudioObjectType, AvcProfile, ChannelConfig, MediaType, SampleFreqIndex, TrackType};
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
|
@ -93,8 +93,14 @@ fn test_read_mp4() {
|
|||
let track2 = mp4.tracks().get(1).unwrap();
|
||||
assert_eq!(track2.track_type().unwrap(), TrackType::Audio);
|
||||
assert_eq!(track2.media_type().unwrap(), MediaType::AAC);
|
||||
assert_eq!(track2.audio_profile().unwrap(), AudioObjectType::AacLowComplexity);
|
||||
assert_eq!(track2.sample_freq_index().unwrap(), SampleFreqIndex::Freq48000);
|
||||
assert_eq!(
|
||||
track2.audio_profile().unwrap(),
|
||||
AudioObjectType::AacLowComplexity
|
||||
);
|
||||
assert_eq!(
|
||||
track2.sample_freq_index().unwrap(),
|
||||
SampleFreqIndex::Freq48000
|
||||
);
|
||||
assert_eq!(track2.channel_config().unwrap(), ChannelConfig::Mono);
|
||||
assert_eq!(track2.bitrate(), 67695);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue