Add returning codec type to audio util function
This commit is contained in:
parent
695f404ba8
commit
5d7ac2bb80
@ -1,11 +1,13 @@
|
|||||||
|
use symphonia::core::codecs::CodecType;
|
||||||
use symphonia::core::formats::FormatOptions;
|
use symphonia::core::formats::FormatOptions;
|
||||||
use symphonia::core::io::MediaSourceStream;
|
use symphonia::core::io::MediaSourceStream;
|
||||||
use symphonia::core::meta::MetadataOptions;
|
use symphonia::core::meta::MetadataOptions;
|
||||||
use symphonia::core::probe::Hint;
|
use symphonia::core::probe::Hint;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
/// Measure the duration (in seconds) of an audio file
|
/// Extract the codec and duration of an audio file
|
||||||
pub fn measure_duration(file: File) -> Result<u64, Box<dyn std::error::Error>> {
|
/// This is combined into one function because the file object will be consumed
|
||||||
|
pub fn extract_metadata(file: File) -> Result<(CodecType, u64), Box<dyn std::error::Error>> {
|
||||||
let source_stream = MediaSourceStream::new(Box::new(file), Default::default());
|
let source_stream = MediaSourceStream::new(Box::new(file), Default::default());
|
||||||
|
|
||||||
let hint = Hint::new();
|
let hint = Hint::new();
|
||||||
@ -26,8 +28,10 @@ pub fn measure_duration(file: File) -> Result<u64, Box<dyn std::error::Error>> {
|
|||||||
.map(|frames| track.codec_params.start_ts + frames)
|
.map(|frames| track.codec_params.start_ts + frames)
|
||||||
.ok_or("Missing number of frames")?;
|
.ok_or("Missing number of frames")?;
|
||||||
|
|
||||||
duration
|
let duration = duration
|
||||||
.checked_mul(time_base.numer as u64)
|
.checked_mul(time_base.numer as u64)
|
||||||
.and_then(|v| v.checked_div(time_base.denom 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))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user