Only write out one MDAT box for a video transcode.

Co-authored-by: Milan Stevanovic <milan@signal.org>
This commit is contained in:
Greyson Parrelli
2025-01-15 15:11:09 -05:00
parent 753927bf30
commit 7c7dc679e9
8 changed files with 83 additions and 18 deletions

View File

@@ -267,8 +267,9 @@ public final class AttachmentCompressionJob extends BaseJob {
boolean faststart = false;
try {
int mdatLength;
try (OutputStream outputStream = ModernEncryptingPartOutputStream.createFor(attachmentSecret, file, true).second) {
transcoder.transcode(percent -> {
mdatLength = (int) transcoder.transcode(percent -> {
if (notification != null) {
notification.setProgress(percent / 100f);
}
@@ -299,7 +300,7 @@ public final class AttachmentCompressionJob extends BaseJob {
});
final long plaintextLength = ModernEncryptingPartOutputStream.getPlaintextLength(file.length());
try (MediaStream mediaStream = new MediaStream(postProcessor.process(plaintextLength), MimeTypes.VIDEO_MP4, 0, 0, true)) {
try (MediaStream mediaStream = new MediaStream(postProcessor.processWithMdatLength(plaintextLength, mdatLength), MimeTypes.VIDEO_MP4, 0, 0, true)) {
attachmentDatabase.updateAttachmentData(attachment, mediaStream);
faststart = true;
} catch (VideoPostProcessingException e) {