feat(media): media put seals durationMs, width and height measured by ffprobe
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { describe, test, expect, afterAll } from 'bun:test';
|
||||
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { liveEncodePlan, prepareForWeb, probe } from '../src/web-prep.js';
|
||||
import { describeMedia, liveEncodePlan, prepareForWeb, probe } from '../src/web-prep.js';
|
||||
import type { ProbeStream } from '../src/web-prep.js';
|
||||
|
||||
const hasFfmpeg = Bun.which('ffmpeg') !== null && Bun.which('ffprobe') !== null;
|
||||
@@ -105,3 +105,25 @@ describe('liveEncodePlan (live video --input)', () => {
|
||||
expect(() => liveEncodePlan('x', [], { realtime: false })).toThrow(/no audio or video/);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!hasFfmpeg)('describeMedia (the meta media put seals)', () => {
|
||||
test('a film has length and size, a sound only length, a picture only size', async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), 'shade-describe-'));
|
||||
dirs.push(dir);
|
||||
const film = join(dir, 'film.mp4');
|
||||
const sound = join(dir, 'sound.ogg');
|
||||
const still = join(dir, 'still.webp');
|
||||
await ff(['-f', 'lavfi', '-i', 'testsrc=size=320x180:rate=25', '-t', '2.5', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', film]);
|
||||
await ff(['-f', 'lavfi', '-i', 'sine=frequency=440:sample_rate=48000', '-t', '1.5', '-c:a', 'libvorbis', sound]);
|
||||
await ff(['-f', 'lavfi', '-i', 'testsrc=size=64x48', '-frames:v', '1', still]);
|
||||
|
||||
const f = await describeMedia(film);
|
||||
expect([f.width, f.height]).toEqual([320, 180]);
|
||||
expect(Math.abs(f.durationMs! - 2500)).toBeLessThan(80);
|
||||
const a = await describeMedia(sound);
|
||||
expect(a.width).toBeUndefined();
|
||||
expect(Math.abs(a.durationMs! - 1500)).toBeLessThan(80);
|
||||
expect(await describeMedia(still)).toEqual({ width: 64, height: 48 });
|
||||
expect(await describeMedia(join(dir, 'missing.mp4'))).toEqual({});
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user