fix(video): write faststart mp4/mov output from stabilize-video (#593)

Add -movflags +faststart for mp4/mov/m4v output from stabilize-video so
the stabilized result streams and previews progressively instead of
appearing broken or corrupted (moov atom was landing after mdat).

Fixes #588
This commit is contained in:
SnapOtter
2026-07-21 13:23:25 +08:00
committed by GitHub
parent a361f94584
commit df92f7ee42
2 changed files with 43 additions and 1 deletions
@@ -47,6 +47,20 @@ function codecForContainer(ext: string): {
};
}
/**
* mp4/mov muxers write the moov atom at the end of the file by default. A
* progressive player (browsers, the in-app player, most mobile players) then
* cannot start playback or seek until the whole file is downloaded, so the
* stabilized result looks broken or "corrupted" on preview. +faststart moves
* the moov atom to the front. Mirrors convert-video / compress-video (#588).
*/
function faststartArgs(ext: string): string[] {
const lower = ext.toLowerCase();
return lower === ".mp4" || lower === ".m4v" || lower === ".mov"
? ["-movflags", "+faststart"]
: [];
}
export function registerStabilizeVideo(app: FastifyInstance) {
createToolRoute(app, {
toolId: "stabilize-video",
@@ -98,6 +112,7 @@ export function registerStabilizeVideo(app: FastifyInstance) {
`vidstabtransform=input=${trf}:smoothing=${settings.smoothing}`,
...encodeArgs,
...audioArgs,
...faststartArgs(origExt),
outPath,
],
info.durationS,