Auto-transcode on upload, show transcode status to user

This commit is contained in:
CallMeVerity
2026-06-03 04:38:51 +01:00
parent 8121369a58
commit ff2c3997a0
6 changed files with 141 additions and 47 deletions
+44 -11
View File
@@ -9,6 +9,7 @@ import {
getVideoByMapAndPlayer,
updateVideoPB,
updateTranscodedKey,
updateTranscodeStatus,
} from "../services/db";
import {
uploadObject,
@@ -335,6 +336,25 @@ export const videoRoutes = new Elysia({ prefix: "/api/videos" })
await completeMultipartUpload(video.videoKey, uploadId, s3Parts);
if (
!video.transcodedKey &&
video.transcodeStatus !== "pending" &&
video.transcodeStatus !== "processing"
) {
updateTranscodeStatus(id, "pending");
const videoKey = video.videoKey;
transcodeVideo(videoKey)
.then((transcodedKey) => {
updateTranscodedKey(id, transcodedKey);
updateTranscodeStatus(id, "done");
console.log(`[transcode] Done: ${id} -> ${transcodedKey}`);
})
.catch((err) => {
console.error(`[transcode] Failed: ${id}`, err);
updateTranscodeStatus(id, "failed");
});
}
return {
...video,
videoUrl: getStreamUrl(video.id),
@@ -349,6 +369,16 @@ export const videoRoutes = new Elysia({ prefix: "/api/videos" })
const video = getVideoById(id);
if (!video) return status(404, { error: "Not found" });
if (
video.transcodeStatus === "processing" ||
video.transcodeStatus === "pending"
) {
return status(409, {
error: "Transcode already in progress",
transcodeStatus: video.transcodeStatus,
});
}
if (video.transcodedKey) {
return {
...video,
@@ -360,18 +390,21 @@ export const videoRoutes = new Elysia({ prefix: "/api/videos" })
};
}
const transcodedKey = await transcodeVideo(video.videoKey);
updateTranscodedKey(id, transcodedKey);
updateTranscodeStatus(id, "pending");
return {
...video,
transcodedKey,
videoUrl: getStreamUrl(video.id),
mtvUrl: getObjectUrl(video.mtvKey),
thumbnailUrl: video.thumbnailKey
? getObjectUrl(video.thumbnailKey)
: undefined,
};
const videoKey = video.videoKey;
transcodeVideo(videoKey)
.then((transcodedKey) => {
updateTranscodedKey(id, transcodedKey);
updateTranscodeStatus(id, "done");
console.log(`[transcode] Done: ${id} -> ${transcodedKey}`);
})
.catch((err) => {
console.error(`[transcode] Failed: ${id}`, err);
updateTranscodeStatus(id, "failed");
});
return { id, transcodeStatus: "pending" };
})
.get("/:id/stream", async ({ params: { id }, request, set }) => {