Skip to content

Commit

Permalink
MP4/M4A : Only insert the 1x1 bogus chapter picture on files where us…
Browse files Browse the repository at this point in the history
…er-defined chapter pictures are actually present [#296]
  • Loading branch information
Zeugma440 committed Dec 22, 2024
1 parent dd14b08 commit 1c5efda
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ATL/AudioData/IO/MP4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Linq;
using System.Collections.Concurrent;
using static ATL.TagData;
using System.Collections;

namespace ATL.AudioData.IO
{
Expand Down Expand Up @@ -2299,10 +2298,11 @@ private static int writeQTChaptersData(BinaryWriter w, ICollection<ChapterInfo>
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;
Expand Down Expand Up @@ -2601,12 +2601,20 @@ private int writeQTChaptersTrack(BinaryWriter w, int trackNum, IList<ChapterInfo
}
if (!isText)
{
int nbActualChapterImages = chapters.Count(ch => 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;
Expand Down

0 comments on commit 1c5efda

Please sign in to comment.