Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

* **MP4**: A missing `mdat` atom is no longer a hard error when reading properties ([PR](https://github.com/Serial-ATA/lofty-rs/pull/515))
* This is now only an error in `Strict` mode. Note that any properties read in a file with no `mdat` atom are essentially useless.

## [0.22.3] - 2025-04-04

### Added
Expand Down
16 changes: 13 additions & 3 deletions lofty/src/mp4/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,18 @@ where
if duration > 0 {
// TODO: We should keep track of the `mdat` length when first reading the file.
// This extra read is unnecessary.
let mdat_len = mdat_length(reader)?;
let mdat_len;
match mdat_length(reader) {
Ok(len) => mdat_len = len,
Err(err) => {
if parse_mode == ParsingMode::Strict {
return Err(err);
}

log::warn!("No \"mdat\" atom found, any audio properties will be useless.");
return Ok(properties);
},
}

if let Some(stts) = stts {
let stts_specifies_duration =
Expand Down Expand Up @@ -547,8 +558,7 @@ where
if properties.audio_bitrate == 0 {
log::warn!("Estimating audio bitrate from 'mdat' size");

properties.audio_bitrate =
(u128::from(mdat_length(reader)? * 8) / duration_millis) as u32;
properties.audio_bitrate = (u128::from(mdat_len * 8) / duration_millis) as u32;
}
}

Expand Down