Should duration be calculated manually if TLEN is zero?
martpie opened this issue · comments
WTTS, duration is never set in most of the files I know (and it makes little sense as duration depends on the total bytes + biterate. Having a file of 5mn but with a TLEN of 2mn is weird to me.
Do you think it should be calculated with (or fallback to?) total_samples / sample_instead
instead of getting TLEN
?
The ID3 tag is completely unrelated to the actual audio data, so if you have both but they each tell something different, rely on the audio data.
@martpie would recommend using mpeg-audio-header if you're still looking for something to calculate the duration.
Was much easier to get up and running with than I was expecting being a bit of a rust noob.
use std::path::Path;
use mpeg_audio_header::{Header, ParseMode};
let path = Path::new("test/source.mp3");
let header = Header::read_from_path(&path, ParseMode::PreferVbrHeaders).unwrap();
println!("MPEG audio header: {:?}", header);
println!("just the duration: {:?}secs", header.total_duration);