mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add ffmpeg module
This commit is contained in:
parent
bd47ae5930
commit
bb13a8dc71
3 changed files with 51 additions and 0 deletions
0
packages/transcode/analyze.ts
Normal file
0
packages/transcode/analyze.ts
Normal file
20
packages/transcode/ffmpeg.test.ts
Normal file
20
packages/transcode/ffmpeg.test.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { ffmpeg } from './ffmpeg.ts';
|
||||
|
||||
Deno.test('ffmpeg', async () => {
|
||||
await using file = await Deno.open(new URL('./buckbunny.mp4', import.meta.url));
|
||||
|
||||
const output = ffmpeg(file.readable, {
|
||||
'i': 'pipe:0',
|
||||
'c:v': 'libx264',
|
||||
'preset': 'veryfast',
|
||||
'loglevel': 'fatal',
|
||||
'crf': '23',
|
||||
'c:a': 'aac',
|
||||
'b:a': '128k',
|
||||
'movflags': 'frag_keyframe+empty_moov',
|
||||
'f': 'mp4',
|
||||
});
|
||||
|
||||
await Deno.mkdir(new URL('./tmp', import.meta.url), { recursive: true });
|
||||
await Deno.writeFile(new URL('./tmp/buckbunny-transcoded.mp4', import.meta.url), output);
|
||||
});
|
||||
31
packages/transcode/ffmpeg.ts
Normal file
31
packages/transcode/ffmpeg.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
export type FFmpegFlags = {
|
||||
'i': string;
|
||||
'c:v': string;
|
||||
'preset': string;
|
||||
'loglevel': string;
|
||||
'crf': string;
|
||||
'c:a': string;
|
||||
'b:a': string;
|
||||
'movflags': string;
|
||||
'f': string;
|
||||
[key: string]: string;
|
||||
};
|
||||
|
||||
export function ffmpeg(input: BodyInit, flags: FFmpegFlags): ReadableStream<Uint8Array> {
|
||||
const command = new Deno.Command('ffmpeg', {
|
||||
args: [
|
||||
...Object.entries(flags).flatMap(([k, v]) => [`-${k}`, v]),
|
||||
'pipe:1', // Output to stdout
|
||||
],
|
||||
stdin: 'piped',
|
||||
stdout: 'piped',
|
||||
});
|
||||
|
||||
// Spawn the FFmpeg process
|
||||
const child = command.spawn();
|
||||
|
||||
// Pipe the input stream into FFmpeg stdin and ensure completion
|
||||
new Response(input).body!.pipeTo(child.stdin);
|
||||
|
||||
return child.stdout;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue