feat: extract and store fps/codec/resolution/duration_ms from source file
Uses getMediaInfo (ffprobe) on the downloaded original before transcoding. Populates the asset record so the library can display accurate metadata.
This commit is contained in:
parent
817eaff8b1
commit
717fdcd611
1 changed files with 31 additions and 4 deletions
|
|
@ -4,7 +4,7 @@ import { tmpdir } from 'os';
|
||||||
import { Queue } from 'bullmq';
|
import { Queue } from 'bullmq';
|
||||||
import { query } from '../db/client.js';
|
import { query } from '../db/client.js';
|
||||||
import { downloadFromS3, uploadToS3 } from '../s3/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';
|
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}`);
|
console.log(`[proxy] Downloading ${inputKey} for asset ${assetId}`);
|
||||||
await downloadFromS3(S3_BUCKET, inputKey, inputPath);
|
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
|
// Transcode to H.264 proxy
|
||||||
await job.updateProgress(30);
|
await job.updateProgress(30);
|
||||||
console.log(`[proxy] Transcoding asset ${assetId}`);
|
console.log(`[proxy] Transcoding asset ${assetId}`);
|
||||||
|
|
@ -47,11 +57,28 @@ export const proxyWorker = async (job) => {
|
||||||
console.log(`[proxy] Uploading to ${outputKey}`);
|
console.log(`[proxy] Uploading to ${outputKey}`);
|
||||||
await uploadToS3(S3_BUCKET, outputKey, outputPath);
|
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 job.updateProgress(90);
|
||||||
await query(
|
await query(
|
||||||
`UPDATE assets SET proxy_s3_key = $1, updated_at = NOW() WHERE id = $2`,
|
`UPDATE assets
|
||||||
[outputKey, assetId]
|
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
|
// Now proxy exists in S3 — safe to queue thumbnail generation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue