From 5d7ac2bb805c27dce8491458c32796cfffa5c7c9 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Fri, 10 May 2024 14:09:24 -0400 Subject: [PATCH] Add returning codec type to audio util function --- src/util/audio.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/util/audio.rs b/src/util/audio.rs index 719052f..ff7291f 100644 --- a/src/util/audio.rs +++ b/src/util/audio.rs @@ -1,11 +1,13 @@ +use symphonia::core::codecs::CodecType; use symphonia::core::formats::FormatOptions; use symphonia::core::io::MediaSourceStream; use symphonia::core::meta::MetadataOptions; use symphonia::core::probe::Hint; use std::fs::File; -/// Measure the duration (in seconds) of an audio file -pub fn measure_duration(file: File) -> Result> { +/// Extract the codec and duration of an audio file +/// This is combined into one function because the file object will be consumed +pub fn extract_metadata(file: File) -> Result<(CodecType, u64), Box> { let source_stream = MediaSourceStream::new(Box::new(file), Default::default()); let hint = Hint::new(); @@ -26,8 +28,10 @@ pub fn measure_duration(file: File) -> Result> { .map(|frames| track.codec_params.start_ts + frames) .ok_or("Missing number of frames")?; - duration + let duration = duration .checked_mul(time_base.numer as u64) .and_then(|v| v.checked_div(time_base.denom as u64)) - .ok_or("Overflow while computing duration".into()) + .ok_or("Overflow while computing duration")?; + + Ok((track.codec_params.codec, duration)) }