From 1c5efdace327ba135722da8206aee18929a10395 Mon Sep 17 00:00:00 2001 From: Zeugma440 Date: Sun, 22 Dec 2024 16:05:34 +0100 Subject: [PATCH] MP4/M4A : Only insert the 1x1 bogus chapter picture on files where user-defined chapter pictures are actually present [#296] --- ATL/AudioData/IO/MP4.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ATL/AudioData/IO/MP4.cs b/ATL/AudioData/IO/MP4.cs index 7e616194..50341699 100644 --- a/ATL/AudioData/IO/MP4.cs +++ b/ATL/AudioData/IO/MP4.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Collections.Concurrent; using static ATL.TagData; -using System.Collections; namespace ATL.AudioData.IO { @@ -2299,10 +2298,11 @@ private static int writeQTChaptersData(BinaryWriter w, ICollection w.Write(StreamUtils.EncodeBEInt32(256)); } + int nbActualChapterImages = chapters.Count(ch => ch.Picture != null && ch.Picture.PictureData.Length > 0); foreach (var chapter in chapters) { if (chapter.Picture != null) w.Write(chapter.Picture.PictureData); - else w.Write(Properties.Resources._1px_black); + else if (nbActualChapterImages > 0) w.Write(Properties.Resources._1px_black); } return 1; @@ -2601,12 +2601,20 @@ private int writeQTChaptersTrack(BinaryWriter w, int trackNum, IList ch.Picture != null && ch.Picture.PictureData.Length > 0); foreach (ChapterInfo chapter in workingChapters) { byte[] pictureData = chapter.Picture != null ? chapter.Picture.PictureData : Properties.Resources._1px_black; - w.Write(StreamUtils.EncodeBEUInt32((uint)pictureData.Length)); + if (nbActualChapterImages > 0) + { + w.Write(StreamUtils.EncodeBEUInt32((uint)pictureData.Length)); + } + else + { + w.Write(0); + } } } finalFramePos = w.BaseStream.Position;