mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Support readable in extractVideoFrame
This commit is contained in:
parent
a28e6509fd
commit
2533d2f469
3 changed files with 15 additions and 5 deletions
|
|
@ -38,7 +38,13 @@ export function ffmpeg(input: URL | ReadableStream<Uint8Array>, flags: FFmpegFla
|
|||
|
||||
// Pipe the input stream into FFmpeg stdin and ensure completion
|
||||
if (input instanceof ReadableStream) {
|
||||
input.pipeTo(child.stdin);
|
||||
input.pipeTo(child.stdin).catch((e: unknown) => {
|
||||
if (e instanceof Error && e.name === 'BrokenPipe') {
|
||||
// Ignore. ffprobe closes the pipe once it has read the metadata.
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Return the FFmpeg stdout stream
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { extractVideoFrame } from './frame.ts';
|
||||
|
||||
Deno.test('extractVideoFrame', async () => {
|
||||
const uri = new URL('./buckbunny.mp4', import.meta.url);
|
||||
const result = await extractVideoFrame(uri);
|
||||
await using file = await Deno.open(new URL('./buckbunny.mp4', import.meta.url));
|
||||
|
||||
const result = await extractVideoFrame(file.readable);
|
||||
|
||||
await Deno.mkdir(new URL('./tmp', import.meta.url), { recursive: true });
|
||||
await Deno.writeFile(new URL('./tmp/buckbunny-poster.jpg', import.meta.url), result);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import { ffmpeg } from './ffmpeg.ts';
|
||||
|
||||
export function extractVideoFrame(file: URL, ss: string = '00:00:01'): Promise<Uint8Array> {
|
||||
const output = ffmpeg(file, {
|
||||
export function extractVideoFrame(
|
||||
input: URL | ReadableStream<Uint8Array>,
|
||||
ss: string = '00:00:01',
|
||||
): Promise<Uint8Array> {
|
||||
const output = ffmpeg(input, {
|
||||
'ss': ss, // Seek to timestamp
|
||||
'frames:v': '1', // Extract only 1 frame
|
||||
'q:v': '2', // High-quality JPEG (lower = better quality)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue