diff --git a/services/worker/src/workers/proxy.js b/services/worker/src/workers/proxy.js index 9ca85d3..d7587a8 100644 --- a/services/worker/src/workers/proxy.js +++ b/services/worker/src/workers/proxy.js @@ -4,7 +4,7 @@ import { tmpdir } from 'os'; import { Queue } from 'bullmq'; import { query } from '../db/client.js'; import { downloadFromS3, uploadToS3 } from '../s3/client.js'; -import { transcodeVideo } from '../ffmpeg/executor.js'; +import { transcodeVideo, getMediaInfo } from '../ffmpeg/executor.js'; const S3_BUCKET = process.env.S3_BUCKET || 'wild-dragon'; @@ -31,6 +31,16 @@ export const proxyWorker = async (job) => { console.log(`[proxy] Downloading ${inputKey} for asset ${assetId}`); await downloadFromS3(S3_BUCKET, inputKey, inputPath); + // Extract source metadata (fps, codec, resolution, duration, size) + await job.updateProgress(20); + let mediaInfo = {}; + try { + mediaInfo = await getMediaInfo(inputPath); + console.log(`[proxy] Metadata for ${assetId}: ${JSON.stringify(mediaInfo)}`); + } catch (err) { + console.warn(`[proxy] getMediaInfo failed for ${assetId}: ${err.message}`); + } + // Transcode to H.264 proxy await job.updateProgress(30); console.log(`[proxy] Transcoding asset ${assetId}`); @@ -47,11 +57,28 @@ export const proxyWorker = async (job) => { console.log(`[proxy] Uploading to ${outputKey}`); await uploadToS3(S3_BUCKET, outputKey, outputPath); - // Update asset record — proxy ready, status stays processing until thumbnail done + // Update asset record — store extracted metadata + proxy key + // Use COALESCE so we never overwrite fields the capture service already set await job.updateProgress(90); await query( - `UPDATE assets SET proxy_s3_key = $1, updated_at = NOW() WHERE id = $2`, - [outputKey, assetId] + `UPDATE assets + SET proxy_s3_key = $1, + fps = COALESCE($2, fps), + codec = COALESCE($3, codec), + resolution = COALESCE($4, resolution), + duration_ms = COALESCE($5, duration_ms), + file_size = COALESCE($6, file_size), + updated_at = NOW() + WHERE id = $7`, + [ + outputKey, + mediaInfo.fps ?? null, + mediaInfo.codec ?? null, + mediaInfo.resolution ?? null, + mediaInfo.durationMs ?? null, + mediaInfo.fileSizeBytes ?? null, + assetId, + ] ); // Now proxy exists in S3 — safe to queue thumbnail generation