Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { spawn } = require('child_process');
- const fs = require('fs');
- // Define your FFmpeg command and arguments
- const ffmpegCommand = 'ffmpeg';
- const args = [
- '-f', 'mulaw',
- '-ar', '8000',
- '-ac', '1',
- '-i', 'pipe:0', // Use stdin as input
- '-ar', '8000',
- '-ac', '1',
- '-acodec', 'pcm_s16le',
- '-f', 'wav',
- 'pipe:1' // Use stdout as output
- ];
- // Spawn the FFmpeg process
- const ffmpeg = spawn(ffmpegCommand, args);
- // Prepare the input stream (for example, reading from a file)
- const inputStream = fs.createReadStream('input.raw');
- // Pipe the input file into FFmpeg's stdin
- inputStream.pipe(ffmpeg.stdin);
- // Handle the output stream
- ffmpeg.stdout.on('data', (data) => {
- // Handle the data from FFmpeg's stdout
- console.log('Data from FFmpeg:', data);
- });
- // Handle errors
- ffmpeg.stderr.on('data', (data) => {
- console.error('Error from FFmpeg:', data.toString());
- });
- ffmpeg.on('close', (code) => {
- console.log(`FFmpeg process exited with code ${code}`);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement