Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP4: Dont discard tags on multiple udta #405

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- **ID3v2**: Disallow 4 character TXXX/WXXX frame descriptions from being converted to `ItemKey` ([issue](https://github.com/Serial-ATA/lofty-rs/issues/309)) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/394))
- **MPEG**: Durations estimated by bitrate are more accurate ([PR](https://github.com/Serial-ATA/lofty-rs/pull/395))
- **MP4**: Bitrate calculation is now more accurate ([PR](https://github.com/Serial-ATA/lofty-rs/pull/398))
- **MP4**:
- Bitrate calculation is now more accurate ([PR](https://github.com/Serial-ATA/lofty-rs/pull/398))
- Existing tags will no longer be overridden if another `udta` atom is encountered ([PR](https://github.com/Serial-ATA/lofty-rs/pull/405))
- **WAV**: Bitrate calculation is now more accurate ([PR](https://github.com/Serial-ATA/lofty-rs/pull/399))
- **MusePack**: Overall improved audio properties ([PR](https://github.com/Serial-ATA/lofty-rs/pull/402))

Expand Down
23 changes: 18 additions & 5 deletions lofty/src/mp4/moov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) struct Moov {
// Represents the trak.mdia atom
pub(crate) traks: Vec<AtomInfo>,
// Represents a parsed moov.udta.meta.ilst
pub(crate) meta: Option<Ilst>,
pub(crate) ilst: Option<Ilst>,
}

impl Moov {
Expand Down Expand Up @@ -43,7 +43,7 @@ impl Moov {
R: Read + Seek,
{
let mut traks = Vec::new();
let mut meta = None;
let mut ilst = None;

while let Ok(Some(atom)) = reader.next() {
if let AtomIdent::Fourcc(fourcc) = atom.ident {
Expand All @@ -56,7 +56,20 @@ impl Moov {
}
},
b"udta" => {
meta = meta_from_udta(reader, parse_mode, atom.len - 8)?;
let ilst_parsed = ilst_from_udta(reader, parse_mode, atom.len - 8)?;
if let Some(ilst_parsed) = ilst_parsed {
let Some(mut existing_ilst) = ilst else {
ilst = Some(ilst_parsed);
continue;
};

log::warn!("Multiple `ilst` atoms found, combining them");
for atom in ilst_parsed.atoms {
existing_ilst.insert(atom);
}

ilst = Some(existing_ilst);
}
},
_ => skip_unneeded(reader, atom.extended, atom.len)?,
}
Expand All @@ -67,11 +80,11 @@ impl Moov {
skip_unneeded(reader, atom.extended, atom.len)?
}

Ok(Self { traks, meta })
Ok(Self { traks, ilst })
}
}

fn meta_from_udta<R>(
fn ilst_from_udta<R>(
reader: &mut AtomReader<R>,
parsing_mode: ParsingMode,
len: u64,
Expand Down
2 changes: 1 addition & 1 deletion lofty/src/mp4/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ where

Ok(Mp4File {
ftyp,
ilst_tag: moov.meta,
ilst_tag: moov.ilst,
properties: if parse_options.read_properties {
// Remove the length restriction
reader.reset_bounds(0, file_length);
Expand Down