mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
23 lines
544 B
TypeScript
23 lines
544 B
TypeScript
import { ffprobe } from './ffprobe.ts';
|
|
|
|
export async function getVideoDimensions(
|
|
input: URL | ReadableStream<Uint8Array>,
|
|
): Promise<{ width: number; height: number } | null> {
|
|
const stream = ffprobe(input, {
|
|
'v': 'error',
|
|
'select_streams': 'v:0',
|
|
'show_streams': '',
|
|
'of': 'json',
|
|
});
|
|
|
|
const { streams } = await new Response(stream).json();
|
|
|
|
for (const stream of streams) {
|
|
if (stream.codec_type === 'video') {
|
|
const { width, height } = stream;
|
|
return { width, height };
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|