Files
hyperframes/packages/parsers
Miguel Ángel 07928702f8 fix(studio-server): preview copies of long clips with sound finish again (#8253)
* fix(studio-server): preview copies of long clips with sound finish again

The piece join ran with ffmpeg's -xerror once it moved onto the shared concat input, which made the timestamp repair at each seam of a clip with sound fatal: the copy failed, its pieces stayed, and the clip waited for a copy that never came. The join opts out of -xerror; the video-only render joins keep it.

* fix(studio-server): a preview copy that joins short is refused and made again

Only a join of pieces with sound runs without -xerror, and every join is measured before it is kept: a copy shorter than its pieces is refused and its pieces are removed, so the next attempt makes them again. The sound test reads ffprobe's JSON so CRLF output parses too.

* fix(studio-server): a preview copy is measured against its own pieces

The join was compared with the source container's length, which counts tracks the copy leaves out, so a whole copy of a source with a longer subtitle or alternate audio track was refused on every try. It is now compared with the summed length of its pieces, which carry only the streams the copy maps; a piece that cannot be measured refuses the join.

* fix(studio-server): every piece of a preview copy is checked against its own stretch

The copy's length now comes from the picture and the sound it keeps (stream durations, or the Matroska DURATION tag), not the container, so its stretches end where those streams end. Each piece and the joined copy are measured against their own stretch, so a short piece can no longer lower the bar. A caller that leaves while the copy is measured stops the measuring, and a left copy is never written to the cache.

* fix(studio-server): long preview copies keep only the picture in pieces and add the sound once

AAC pieces overlap at every seam (each piece's priming frame reaches back into the one before), so a strict join refuses them. Pieces now carry only the picture and join strictly, exactly like the render joins; the sound is encoded once from the source and put with the picture by a stream copy that keeps both on the source's timeline. This replaces the length checks of the earlier commits, and old pieces with sound get a new name tag so they are never joined as picture-only pieces.

* fix(studio-server): each picture piece of a preview copy starts exactly where its stretch does

At a frame rate that does not divide 15 s, such as 29.97, every piece ran about 15 ms long and the join placed the next piece after it, so the picture drifted from the continuous sound (600 ms over 10 minutes). The join list now gives each piece its stretch's length (ffconcat duration), so pieces land on the source's timeline and the offset stays within a frame.

* fix(studio-server): a preview copy of a clip whose picture starts late keeps that start

On ffmpeg 8 the piece join moved the first piece to zero, so a picture that starts after the sound lost its lead against the sound added later. The join now keeps each piece's own timestamps (ffconcat inpoint 0 with each stretch's duration, and -copyts), on ffmpeg 7 and 8 alike. The long-source path moves into copyInPieces.

* fix(studio-server): a preview copy never keeps a short or broken piece from a stopped copy

A piece left by an earlier run is made again when it runs short of its stretch; when the join refuses one, every piece is dropped and made again once in the same run. A refused join no longer leaves its pieces or a picture temp behind; a stopped one keeps its pieces.

* fix(studio-server): a resumed preview copy remakes a piece a frame short and stops on cancel

A piece left by a stopped copy now has to run its stretch to within half a frame. The pieces are measured one at a time, and leaving the copy stops the running ffprobe (probeMediaMetadata takes a signal) and frees the copy.

* refactor(studio-server): read the piece check's frame rate outside the copy setup

* test(studio-server): run the real-ffmpeg join tests in their own file, inside the flake gate's limit

The flake gate runs each changed test file under full CPU load with 120 s per run. With this change's real-ffmpeg join tests added, proxyTranscoder.test.ts took about 108 s a run at a6d62ae2 and went over at 56cf7c74. Those tests move to proxyTranscoder.seams.test.ts; under 4-core load the two files take 15 s and 32 s.

* test(studio-server): keep the real-ffmpeg join tests inside the flake gate's limit

The seams file went over the gate's 120 s per run. Three tests whose checks the others already make are gone (plain copy with sound, the picture-and-sound-together clap case, the 5 s piece), each clip is measured in one ffmpeg pass, and the stopped-copy tests have their own file. On 4 busy cores the files take 15 s and 10 s. The cut piece keeps its header now, so the test reaches the retry after a refused join.
2026-11-20 06:29:05 +00:00
..
2026-11-19 22:02:17 -05:00