diff --git a/packages/ditto/utils/transcode.test.ts b/packages/ditto/utils/transcode.test.ts index 54bbbdd8..f57402c4 100644 --- a/packages/ditto/utils/transcode.test.ts +++ b/packages/ditto/utils/transcode.test.ts @@ -2,7 +2,7 @@ import { transcodeVideo } from './transcode.ts'; Deno.test('transcodeVideo', async () => { await using file = await Deno.open(new URL('./buckbunny.mp4', import.meta.url)); - const output = await transcodeVideo(file.readable); + const output = transcodeVideo(file.readable); await Deno.writeFile(new URL('./buckbunny-transcoded.mp4', import.meta.url), output); }); diff --git a/packages/ditto/utils/transcode.ts b/packages/ditto/utils/transcode.ts index d2b22957..23271588 100644 --- a/packages/ditto/utils/transcode.ts +++ b/packages/ditto/utils/transcode.ts @@ -1,4 +1,4 @@ -export async function transcodeVideo(input: ReadableStream): Promise> { +export function transcodeVideo(input: ReadableStream): ReadableStream { const opts = { 'i': 'pipe:0', // Read input from stdin 'c:v': 'libx264', // Convert to H.264 @@ -18,38 +18,13 @@ export async function transcodeVideo(input: ReadableStream): Promise ], stdin: 'piped', stdout: 'piped', - stderr: 'piped', }); // Spawn the FFmpeg process - const process = command.spawn(); - - // Capture stderr for debugging - const stderrPromise = new Response(process.stderr).text().then((text) => { - if (text.trim()) console.error('FFmpeg stderr:', text); - }); + const child = command.spawn(); // Pipe the input stream into FFmpeg stdin and ensure completion - const writer = process.stdin.getWriter(); - const reader = input.getReader(); + input.pipeTo(child.stdin); - async function pumpInput() { - try { - while (true) { - const { done, value } = await reader.read(); - if (done) break; - await writer.write(value); - } - } finally { - writer.close(); // Close stdin to signal FFmpeg that input is done - } - } - - // Start pumping input asynchronously - pumpInput(); - - // Ensure stderr logs are captured - stderrPromise.catch(console.error); - - return process.stdout; + return child.stdout; }