mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-12-22 20:16:27 +00:00
Update examples (#16)
* Add ReadBox trait * Add boxtype macro * Remove offset in BoxHeader * Fix parsing error when box has largesize * Remove duplicated codes reading version and flags * Update examples * Fix test failure Co-authored-by: Byungwan Jun <unipro.kr@gmail.com>
This commit is contained in:
parent
3104a2d95b
commit
b5367032a7
4 changed files with 8 additions and 10 deletions
|
@ -70,8 +70,8 @@ fn copy<P: AsRef<Path>>(src_filename: &P, dst_filename: &P) -> Result<()> {
|
||||||
|
|
||||||
let track_id = track_idx as u32 + 1;
|
let track_id = track_idx as u32 + 1;
|
||||||
let sample_count = mp4_reader.sample_count(track_id)?;
|
let sample_count = mp4_reader.sample_count(track_id)?;
|
||||||
for six in 0..sample_count {
|
for sample_idx in 0..sample_count {
|
||||||
let sample_id = six + 1;
|
let sample_id = sample_idx + 1;
|
||||||
let sample = mp4_reader.read_sample(track_id, sample_id)?.unwrap();
|
let sample = mp4_reader.read_sample(track_id, sample_id)?.unwrap();
|
||||||
mp4_writer.write_sample(track_id, &sample)?;
|
mp4_writer.write_sample(track_id, &sample)?;
|
||||||
// println!("copy {}:({})", sample_id, sample);
|
// println!("copy {}:({})", sample_id, sample);
|
||||||
|
|
|
@ -35,11 +35,7 @@ fn info<P: AsRef<Path>>(filename: &P) -> Result<()> {
|
||||||
compatible_brands.push_str(",");
|
compatible_brands.push_str(",");
|
||||||
}
|
}
|
||||||
println!(" compatible_brands: {}", compatible_brands);
|
println!(" compatible_brands: {}", compatible_brands);
|
||||||
println!(
|
println!("Duration: {:?}", mp4.duration());
|
||||||
"Duration: {}, timescale: {}",
|
|
||||||
mp4.duration(),
|
|
||||||
mp4.timescale()
|
|
||||||
);
|
|
||||||
|
|
||||||
for track in mp4.tracks().iter() {
|
for track in mp4.tracks().iter() {
|
||||||
let media_info = match track.track_type()? {
|
let media_info = match track.track_type()? {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::mp4box::*;
|
use crate::mp4box::*;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
@ -95,8 +96,8 @@ impl<R: Read + Seek> Mp4Reader<R> {
|
||||||
&self.ftyp.compatible_brands
|
&self.ftyp.compatible_brands
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn duration(&self) -> u64 {
|
pub fn duration(&self) -> Duration {
|
||||||
self.moov.mvhd.duration
|
Duration::from_millis(self.moov.mvhd.duration * 1000 / self.moov.mvhd.timescale as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timescale(&self) -> u32 {
|
pub fn timescale(&self) -> u32 {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use mp4::{AudioObjectType, AvcProfile, ChannelConfig, MediaType, SampleFreqIndex, TrackType};
|
use mp4::{AudioObjectType, AvcProfile, ChannelConfig, MediaType, SampleFreqIndex, TrackType};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_read_mp4() {
|
fn test_read_mp4() {
|
||||||
|
@ -29,7 +30,7 @@ fn test_read_mp4() {
|
||||||
assert_eq!(t, true);
|
assert_eq!(t, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(mp4.duration(), 62);
|
assert_eq!(mp4.duration(), Duration::from_millis(62));
|
||||||
assert_eq!(mp4.timescale(), 1000);
|
assert_eq!(mp4.timescale(), 1000);
|
||||||
assert_eq!(mp4.tracks().len(), 2);
|
assert_eq!(mp4.tracks().len(), 2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue