Fix chunk assembly order and surface video duration in the optimizer

- The streaming assembler applied chunks sorted by position, so header
  patches written last could be overwritten by earlier data. Chunks now
  apply in arrival order (newest write wins per byte range) and are only
  laid out by position afterwards.
- The Optimize modal now reads the media metadata itself: both previews
  show resolution and duration, and the processed video is flagged in red
  when it comes out shorter than the original (a truncated encode is no
  longer something you have to guess by file size).
This commit is contained in:
2026-09-17 20:45:12 -05:00
parent 58f030878e
commit fed1e8bb5a
2 changed files with 63 additions and 15 deletions
+5 -5
View File
@@ -68,11 +68,11 @@ function assembleBlob(chunks: CollectedChunk[], type: string): Blob {
if (chunks.length === 0) {
throw new Error("Encoding produced no output.");
}
const sorted = [...chunks].sort(
(a, b) => a.position - b.position || a.sequence - b.sequence,
);
// The muxer may rewrite earlier ranges (header patching), so apply writes
// in arrival order — the newest write wins per byte range — and only then
// lay the segments out by position.
const ordered = [...chunks].sort((a, b) => a.sequence - b.sequence);
// Overwrite ranges so the newest write for each byte range survives.
interface Segment {
start: number;
end: number;
@@ -80,7 +80,7 @@ function assembleBlob(chunks: CollectedChunk[], type: string): Blob {
blob: Blob;
}
let segments: Segment[] = [];
for (const chunk of sorted) {
for (const chunk of ordered) {
const start = chunk.position;
const end = start + chunk.blob.size;
const next: Segment[] = [];