dr.benchi
dr.benchi
DDeno
Created by dr.benchi on 9/7/2023 in #help
Piping streams through a shell program (ffmpeg) and writing the output to a file
Thanks, that's helped me get the stdin Writer, though I got a little stuck feeding into it. For anyone else who reads this my now-working code looks like this:
const input_file = `./sample_recording.wav`;
const ffmpeg_bin = `/usr/bin/ffmpeg`;
const output_file = './sample_output.ogg';

const input_data = await Deno.open(input_file, { read: true });

const command = new Deno.Command(ffmpeg_bin, {
args: [
'-i', '-',
output_file,
],
stdin: 'piped',
stdout: 'piped',
});

const child_process = await command.spawn();

const stdin = await child_process.stdin.getWriter();

for await (const chunk of input_data.readable) {
stdin.write(chunk);
}
stdin.releaseLock();
await child_process.stdin.close();
const input_file = `./sample_recording.wav`;
const ffmpeg_bin = `/usr/bin/ffmpeg`;
const output_file = './sample_output.ogg';

const input_data = await Deno.open(input_file, { read: true });

const command = new Deno.Command(ffmpeg_bin, {
args: [
'-i', '-',
output_file,
],
stdin: 'piped',
stdout: 'piped',
});

const child_process = await command.spawn();

const stdin = await child_process.stdin.getWriter();

for await (const chunk of input_data.readable) {
stdin.write(chunk);
}
stdin.releaseLock();
await child_process.stdin.close();
3 replies