Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: process Loom originals with decoder glitches on first view

Richie McIlroy9186186f93d1
diff --git a/apps/media-server/src/__tests__/lib/video-input-validation.integration.test.ts b/apps/media-server/src/__tests__/lib/video-input-validation.integration.test.ts
index be9c875a5..93a90f66a 100644
--- a/apps/media-server/src/__tests__/lib/video-input-validation.integration.test.ts
+++ b/apps/media-server/src/__tests__/lib/video-input-validation.integration.test.ts
@@ -119,10 +119,11 @@ describe("raw recording input validation", () => {
expect(readFileSync(corrupt).length).toBeGreaterThan(0);
});
- for (const [name, source, expectedPhase, extension] of [
- ["clean", clean, "complete", ".webm"],
- ["damaged", corrupt, "error", ".webm"],
- ["fragmented-mp4", cleanMp4, "complete", ".mp4"],
+ for (const [name, source, expectedPhase, extension, importedOriginal] of [
+ ["clean", clean, "complete", ".webm", false],
+ ["damaged", corrupt, "error", ".webm", false],
+ ["imported-damaged", corrupt, "complete", ".webm", true],
+ ["fragmented-mp4", cleanMp4, "complete", ".mp4", false],
] as const) {
test(`processing route handles ${name} source before conversion`, async () => {
spyOn(jobManager, "canAcceptNewVideoProcess").mockReturnValue(true);
@@ -155,6 +156,7 @@ describe("raw recording input validation", () => {
outputPresignedUrl: "https://example.com/result.mp4",
inputExtension: extension,
preset: "ultrafast",
+ ...(importedOriginal ? { importedOriginal } : {}),
}),
}),
);
diff --git a/apps/media-server/src/routes/video.ts b/apps/media-server/src/routes/video.ts
index 0bb5ae53c..de7585238 100644
--- a/apps/media-server/src/routes/video.ts
+++ b/apps/media-server/src/routes/video.ts
@@ -194,6 +194,7 @@ const processSchema = z.object({
preset: z.enum(["ultrafast", "fast", "medium", "slow"]).optional(),
remuxOnly: z.boolean().optional(),
normalizeH264Level: z.boolean().optional(),
+ importedOriginal: z.boolean().optional(),
});
const editRangeSchema = z
@@ -1586,7 +1587,7 @@ async function processVideoAsync(
}
const isWebm = isWebmInput(options.inputExtension);
- if (isWebm) {
+ if (isWebm && !options.importedOriginal) {
updateJob(jobId, { message: "Checking the original recording..." });
await withJobHeartbeat(jobId, () =>
validateVideoInput(input.path, signal),
diff --git a/apps/web/__tests__/unit/media-processing-workflows.test.ts b/apps/web/__tests__/unit/media-processing-workflows.test.ts
index 939f74b20..1702588d4 100644
--- a/apps/web/__tests__/unit/media-processing-workflows.test.ts
+++ b/apps/web/__tests__/unit/media-processing-workflows.test.ts
@@ -195,6 +195,51 @@ describe("media processing workflows", () => {
expect(mocks.remove).toHaveBeenCalledWith(payload.rawFileKey);
});
+ it("marks deferred Loom originals so the worker accepts their decoder glitches", async () => {
+ const loomVideo = {
+ ...video,
+ metadata: {
+ loomDeferredProcessing: {
+ status: "started",
+ rawFileKey: payload.rawFileKey,
+ },
+ },
+ };
+ mocks.rows = [
+ [loomVideo],
+ [{ ...pending, rawFileKey: payload.rawFileKey }],
+ [loomVideo],
+ [pending],
+ [],
+ [metadata],
+ [loomVideo],
+ [],
+ ];
+ await expect(processVideoWorkflow(payload)).resolves.toMatchObject({
+ success: true,
+ });
+ const body = JSON.parse(String(mocks.fetch.mock.calls[0]?.[1]?.body));
+ expect(body.importedOriginal).toBe(true);
+ });
+
+ it("checks ordinary uploads strictly", async () => {
+ mocks.rows = [
+ [video],
+ [{ ...pending, rawFileKey: payload.rawFileKey }],
+ [video],
+ [pending],
+ [],
+ [metadata],
+ [video],
+ [],
+ ];
+ await expect(processVideoWorkflow(payload)).resolves.toMatchObject({
+ success: true,
+ });
+ const body = JSON.parse(String(mocks.fetch.mock.calls[0]?.[1]?.body));
+ expect(body.importedOriginal).toBeUndefined();
+ });
+
it("keeps uploaded source data when processing fails", async () => {
mocks.rows = [
[video],
diff --git a/apps/web/workflows/process-video.ts b/apps/web/workflows/process-video.ts
index 52cb4ca89..77bb20b63 100644
--- a/apps/web/workflows/process-video.ts
+++ b/apps/web/workflows/process-video.ts
@@ -177,6 +177,7 @@ async function startMediaServerProcessJob(
webhookSecret?: string;
inputExtension: string;
audioLevels?: boolean;
+ importedOriginal?: boolean;
},
): Promise<string> {
for (let attempt = 0; attempt < MEDIA_SERVER_START_MAX_ATTEMPTS; attempt++) {
@@ -350,6 +351,9 @@ async function processVideoOnMediaServer(
webhookUrl,
webhookSecret: webhookSecret || undefined,
inputExtension: getInputExtension(rawFileKey),
+ importedOriginal:
+ video.metadata?.loomDeferredProcessing?.rawFileKey === rawFileKey ||
+ undefined,
});
}