1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-06-02 13:39:54 +00:00

Rename atoms to mp4box

This commit is contained in:
Ian Jun 2020-08-05 02:47:55 +09:00
parent f5f031c38d
commit 51252c16ae
32 changed files with 97 additions and 86 deletions

View file

@ -4,7 +4,7 @@ use std::io::prelude::*;
use std::io::{self, BufReader, BufWriter};
use std::path::Path;
use mp4::{AacConfig, AvcConfig, MediaConfig, MediaType, Result, TrackConfig, Mp4Config};
use mp4::{AacConfig, AvcConfig, MediaConfig, MediaType, Mp4Config, Result, TrackConfig};
fn main() {
let args: Vec<String> = env::args().collect();

View file

@ -1,6 +1,6 @@
use thiserror::Error;
use crate::atoms::BoxType;
use crate::mp4box::BoxType;
#[derive(Error, Debug)]
pub enum Error {

View file

@ -6,7 +6,7 @@ pub type Result<T> = std::result::Result<T, Error>;
mod types;
pub use types::*;
mod atoms;
mod mp4box;
mod track;
pub use track::{Mp4Track, TrackConfig};

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq)]
pub struct Avc1Box {
@ -263,7 +263,7 @@ impl NalUnit {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]
@ -282,21 +282,16 @@ mod tests {
profile_compatibility: 0,
avc_level_indication: 13,
length_size_minus_one: 3,
sequence_parameter_sets: vec![
NalUnit {
bytes: vec![
0x67, 0x64, 0x00, 0x0D, 0xAC, 0xD9, 0x41, 0x41,
0xFA, 0x10, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00,
0x00, 0x03, 0x03, 0x20, 0xF1, 0x42, 0x99, 0x60
]
}
],
picture_parameter_sets: vec![
NalUnit {
bytes: vec![0x68, 0xEB, 0xE3, 0xCB, 0x22, 0xC0]
}
]
}
sequence_parameter_sets: vec![NalUnit {
bytes: vec![
0x67, 0x64, 0x00, 0x0D, 0xAC, 0xD9, 0x41, 0x41, 0xFA, 0x10, 0x00, 0x00,
0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03, 0x20, 0xF1, 0x42, 0x99, 0x60,
],
}],
picture_parameter_sets: vec![NalUnit {
bytes: vec![0x68, 0xEB, 0xE3, 0xCB, 0x22, 0xC0],
}],
},
};
let mut buf = Vec::new();
src_box.write_box(&mut buf).unwrap();

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Co64Box {
@ -62,7 +62,7 @@ impl<W: Write> WriteBox<&mut W> for Co64Box {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CttsBox {
@ -72,7 +72,7 @@ impl<W: Write> WriteBox<&mut W> for CttsBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use std::io::{Read, Seek, Write};
use crate::atoms::elst::ElstBox;
use crate::atoms::*;
use crate::mp4box::elst::ElstBox;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EdtsBox {

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ElstBox {
@ -102,7 +102,7 @@ impl<W: Write> WriteBox<&mut W> for ElstBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct FtypBox {
@ -64,7 +64,7 @@ impl<W: Write> WriteBox<&mut W> for FtypBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct HdlrBox {
@ -80,7 +80,7 @@ impl<W: Write> WriteBox<&mut W> for HdlrBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -2,7 +2,7 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::char::{decode_utf16, REPLACEMENT_CHARACTER};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq)]
pub struct MdhdBox {
@ -141,7 +141,7 @@ fn language_code(language: &str) -> u16 {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
fn test_language_code(lang: &str) {

View file

@ -1,7 +1,7 @@
use std::io::{Read, Seek, SeekFrom, Write};
use crate::atoms::*;
use crate::atoms::{hdlr::HdlrBox, mdhd::MdhdBox, minf::MinfBox};
use crate::mp4box::*;
use crate::mp4box::{hdlr::HdlrBox, mdhd::MdhdBox, minf::MinfBox};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MdiaBox {

View file

@ -1,7 +1,7 @@
use std::io::{Read, Seek, SeekFrom, Write};
use crate::atoms::*;
use crate::atoms::{smhd::SmhdBox, stbl::StblBox, vmhd::VmhdBox};
use crate::mp4box::*;
use crate::mp4box::{smhd::SmhdBox, stbl::StblBox, vmhd::VmhdBox};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MinfBox {

View file

@ -1,7 +1,7 @@
use std::io::{Read, Seek, SeekFrom, Write};
use crate::atoms::*;
use crate::atoms::{mvhd::MvhdBox, trak::TrakBox};
use crate::mp4box::*;
use crate::mp4box::{mvhd::MvhdBox, trak::TrakBox};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MoovBox {

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq)]
pub struct Mp4aBox {
@ -306,7 +306,7 @@ impl<R: Read + Seek> ReadDesc<&mut R> for ESDescriptor {
impl<W: Write> WriteDesc<&mut W> for ESDescriptor {
fn write_desc(&self, writer: &mut W) -> Result<u32> {
let size = Self::desc_size();
write_desc(writer, Self::desc_tag(), size-1)?;
write_desc(writer, Self::desc_tag(), size - 1)?;
writer.write_u16::<BigEndian>(self.es_id)?;
writer.write_u8(0)?;
@ -334,7 +334,7 @@ impl DecoderConfigDescriptor {
pub fn new(config: &AacConfig) -> Self {
Self {
object_type_indication: 0x40, // XXX AAC
stream_type: 0x05, // XXX Audio
stream_type: 0x05, // XXX Audio
up_stream: 0,
buffer_size_db: 0,
max_bitrate: config.bitrate, // XXX
@ -403,7 +403,7 @@ impl<R: Read + Seek> ReadDesc<&mut R> for DecoderConfigDescriptor {
impl<W: Write> WriteDesc<&mut W> for DecoderConfigDescriptor {
fn write_desc(&self, writer: &mut W) -> Result<u32> {
let size = Self::desc_size();
write_desc(writer, Self::desc_tag(), size-1)?;
write_desc(writer, Self::desc_tag(), size - 1)?;
writer.write_u8(self.object_type_indication)?;
writer.write_u8((self.stream_type << 2) + (self.up_stream & 0x02))?;
@ -464,7 +464,7 @@ impl<R: Read + Seek> ReadDesc<&mut R> for DecoderSpecificDescriptor {
impl<W: Write> WriteDesc<&mut W> for DecoderSpecificDescriptor {
fn write_desc(&self, writer: &mut W) -> Result<u32> {
let size = Self::desc_size();
write_desc(writer, Self::desc_tag(), size-1)?;
write_desc(writer, Self::desc_tag(), size - 1)?;
writer.write_u8((self.profile << 3) + (self.freq_index >> 1))?;
writer.write_u8((self.freq_index << 7) + (self.chan_conf << 3))?;
@ -504,7 +504,7 @@ impl<R: Read + Seek> ReadDesc<&mut R> for SLConfigDescriptor {
impl<W: Write> WriteDesc<&mut W> for SLConfigDescriptor {
fn write_desc(&self, writer: &mut W) -> Result<u32> {
let size = Self::desc_size();
write_desc(writer, Self::desc_tag(), size-1)?;
write_desc(writer, Self::desc_tag(), size - 1)?;
writer.write_u8(0)?; // pre-defined
Ok(size)
@ -514,7 +514,7 @@ impl<W: Write> WriteDesc<&mut W> for SLConfigDescriptor {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]
@ -539,12 +539,12 @@ mod tests {
dec_specific: DecoderSpecificDescriptor {
profile: 2,
freq_index: 3,
chan_conf: 1
}
chan_conf: 1,
},
},
sl_config: SLConfigDescriptor::default()
}
}
sl_config: SLConfigDescriptor::default(),
},
},
};
let mut buf = Vec::new();
src_box.write_box(&mut buf).unwrap();

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq)]
pub struct MvhdBox {
@ -115,7 +115,7 @@ impl<W: Write> WriteBox<&mut W> for MvhdBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq)]
pub struct SmhdBox {
@ -65,7 +65,7 @@ impl<W: Write> WriteBox<&mut W> for SmhdBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use std::io::{Read, Seek, SeekFrom, Write};
use crate::atoms::*;
use crate::atoms::{
use crate::mp4box::*;
use crate::mp4box::{
co64::Co64Box, ctts::CttsBox, stco::StcoBox, stsc::StscBox, stsd::StsdBox, stss::StssBox,
stsz::StszBox, stts::SttsBox,
};

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct StcoBox {
@ -62,7 +62,7 @@ impl<W: Write> WriteBox<&mut W> for StcoBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct StscBox {
@ -90,7 +90,7 @@ impl<W: Write> WriteBox<&mut W> for StscBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,8 +1,8 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::atoms::{avc1::Avc1Box, mp4a::Mp4aBox};
use crate::mp4box::*;
use crate::mp4box::{avc1::Avc1Box, mp4a::Mp4aBox};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct StsdBox {

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct StssBox {
@ -62,7 +62,7 @@ impl<W: Write> WriteBox<&mut W> for StssBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct StszBox {
@ -72,7 +72,7 @@ impl<W: Write> WriteBox<&mut W> for StszBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SttsBox {
@ -72,7 +72,7 @@ impl<W: Write> WriteBox<&mut W> for SttsBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq)]
pub struct TkhdBox {
@ -192,7 +192,7 @@ impl<W: Write> WriteBox<&mut W> for TkhdBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,7 +1,7 @@
use std::io::{Read, Seek, SeekFrom, Write};
use crate::atoms::*;
use crate::atoms::{edts::EdtsBox, mdia::MdiaBox, tkhd::TkhdBox};
use crate::mp4box::*;
use crate::mp4box::{edts::EdtsBox, mdia::MdiaBox, tkhd::TkhdBox};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct TrakBox {

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{Read, Seek, Write};
use crate::atoms::*;
use crate::mp4box::*;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct VmhdBox {
@ -71,7 +71,7 @@ impl<W: Write> WriteBox<&mut W> for VmhdBox {
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::BoxHeader;
use crate::mp4box::BoxHeader;
use std::io::Cursor;
#[test]

View file

@ -1,6 +1,6 @@
use std::io::{Read, Seek, SeekFrom};
use crate::atoms::*;
use crate::mp4box::*;
use crate::*;
#[derive(Debug)]

View file

@ -1,12 +1,15 @@
use bytes::BytesMut;
use std::cmp;
use std::convert::TryFrom;
use std::io::{Read, Seek, SeekFrom, Write};
use std::time::Duration;
use std::cmp;
use crate::atoms::trak::TrakBox;
use crate::atoms::*;
use crate::atoms::{avc1::Avc1Box, mp4a::Mp4aBox, smhd::SmhdBox, vmhd::VmhdBox, ctts::CttsBox, stts::SttsEntry, ctts::CttsEntry, stss::StssBox, stco::StcoBox, stsc::StscEntry};
use crate::mp4box::trak::TrakBox;
use crate::mp4box::*;
use crate::mp4box::{
avc1::Avc1Box, ctts::CttsBox, ctts::CttsEntry, mp4a::Mp4aBox, smhd::SmhdBox, stco::StcoBox,
stsc::StscEntry, stss::StssBox, stts::SttsEntry, vmhd::VmhdBox,
};
use crate::*;
#[derive(Debug, Clone, PartialEq)]
@ -472,7 +475,13 @@ impl Mp4TrackWriter {
if self.trak.mdia.minf.stbl.stsz.sample_size > 0 {
self.trak.mdia.minf.stbl.stsz.sample_size = 0;
for _ in 0..self.trak.mdia.minf.stbl.stsz.sample_count {
self.trak.mdia.minf.stbl.stsz.sample_sizes.push(self.fixed_sample_size);
self.trak
.mdia
.minf
.stbl
.stsz
.sample_sizes
.push(self.fixed_sample_size);
}
}
self.trak.mdia.minf.stbl.stsz.sample_sizes.push(size);
@ -555,7 +564,8 @@ impl Mp4TrackWriter {
fn update_durations(&mut self, dur: u32, movie_timescale: u32) {
self.trak.mdia.mdhd.duration += dur as u64;
self.trak.tkhd.duration += dur as u64 * movie_timescale as u64 / self.trak.mdia.mdhd.timescale as u64;
self.trak.tkhd.duration +=
dur as u64 * movie_timescale as u64 / self.trak.mdia.mdhd.timescale as u64;
}
pub(crate) fn write_sample<W: Write + Seek>(

View file

@ -1,7 +1,7 @@
use std::convert::TryFrom;
use std::fmt;
use crate::atoms::*;
use crate::mp4box::*;
use crate::*;
pub use bytes::Bytes;

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, WriteBytesExt};
use std::io::{Seek, SeekFrom, Write};
use crate::atoms::*;
use crate::mp4box::*;
use crate::track::Mp4TrackWriter;
use crate::*;
@ -38,7 +38,13 @@ impl<W: Write + Seek> Mp4Writer<W> {
let tracks = Vec::new();
let timescale = config.timescale;
let duration = 0;
Ok(Self {writer, tracks, mdat_pos, timescale, duration})
Ok(Self {
writer,
tracks,
mdat_pos,
timescale,
duration,
})
}
pub fn add_track(&mut self, config: &TrackConfig) -> Result<()> {