1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-12-22 12:06:33 +00:00

Do not fail if media info fails (#70)

This commit is contained in:
Data Retriever 2022-04-21 01:43:18 +00:00 committed by GitHub
parent 93dbb56464
commit 084381bde5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,7 +4,7 @@ use std::io::prelude::*;
use std::io::{self, BufReader}; use std::io::{self, BufReader};
use std::path::Path; use std::path::Path;
use mp4::{Mp4Track, Result, TrackType, Error}; use mp4::{Error, Mp4Track, Result, TrackType};
fn main() { fn main() {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
@ -38,7 +38,10 @@ fn info<P: AsRef<Path>>(filename: &P) -> Result<()> {
println!("Movie:"); println!("Movie:");
println!(" version: {}", mp4.moov.mvhd.version); println!(" version: {}", mp4.moov.mvhd.version);
println!(" creation time: {}", creation_time(mp4.moov.mvhd.creation_time)); println!(
" creation time: {}",
creation_time(mp4.moov.mvhd.creation_time)
);
println!(" duration: {:?}", mp4.duration()); println!(" duration: {:?}", mp4.duration());
println!(" fragments: {:?}", mp4.is_fragmented()); println!(" fragments: {:?}", mp4.is_fragmented());
println!(" timescale: {:?}\n", mp4.timescale()); println!(" timescale: {:?}\n", mp4.timescale());
@ -46,16 +49,17 @@ fn info<P: AsRef<Path>>(filename: &P) -> Result<()> {
println!("Found {} Tracks", mp4.tracks().len()); println!("Found {} Tracks", mp4.tracks().len());
for track in mp4.tracks().values() { for track in mp4.tracks().values() {
let media_info = match track.track_type()? { let media_info = match track.track_type()? {
TrackType::Video => video_info(track)?, TrackType::Video => video_info(track),
TrackType::Audio => audio_info(track)?, TrackType::Audio => audio_info(track),
TrackType::Subtitle => subtitle_info(track)?, TrackType::Subtitle => subtitle_info(track),
}; };
println!( println!(
" Track: #{}({}) {}: {}", " Track: #{}({}) {}: {}",
track.track_id(), track.track_id(),
track.language(), track.language(),
track.track_type()?, track.track_type()?,
media_info media_info.unwrap_or_else(|e| e.to_string())
); );
} }
Ok(()) Ok(())
@ -89,7 +93,6 @@ fn video_info(track: &Mp4Track) -> Result<String> {
fn audio_info(track: &Mp4Track) -> Result<String> { fn audio_info(track: &Mp4Track) -> Result<String> {
if let Some(ref mp4a) = track.trak.mdia.minf.stbl.stsd.mp4a { if let Some(ref mp4a) = track.trak.mdia.minf.stbl.stsd.mp4a {
if mp4a.esds.is_some() { if mp4a.esds.is_some() {
let profile = match track.audio_profile() { let profile = match track.audio_profile() {
Ok(val) => val.to_string(), Ok(val) => val.to_string(),
_ => "-".to_string(), _ => "-".to_string(),
@ -124,11 +127,7 @@ fn audio_info(track: &Mp4Track) -> Result<String> {
fn subtitle_info(track: &Mp4Track) -> Result<String> { fn subtitle_info(track: &Mp4Track) -> Result<String> {
if track.trak.mdia.minf.stbl.stsd.tx3g.is_some() { if track.trak.mdia.minf.stbl.stsd.tx3g.is_some() {
Ok(format!( Ok(format!("{} ({:?})", track.media_type()?, track.box_type()?,))
"{} ({:?})",
track.media_type()?,
track.box_type()?,
))
} else { } else {
Err(Error::InvalidData("tx3g box not found")) Err(Error::InvalidData("tx3g box not found"))
} }