Advertisement
djmango

Untitled

Dec 8th, 2023
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { spawn } = require('child_process');
  2. const fs = require('fs');
  3.  
  4. // Define your FFmpeg command and arguments
  5. const ffmpegCommand = 'ffmpeg';
  6. const args = [
  7.     '-f', 'mulaw',
  8.     '-ar', '8000',
  9.     '-ac', '1',
  10.     '-i', 'pipe:0',  // Use stdin as input
  11.     '-ar', '8000',
  12.     '-ac', '1',
  13.     '-acodec', 'pcm_s16le',
  14.     '-f', 'wav',
  15.     'pipe:1'  // Use stdout as output
  16. ];
  17.  
  18. // Spawn the FFmpeg process
  19. const ffmpeg = spawn(ffmpegCommand, args);
  20.  
  21. // Prepare the input stream (for example, reading from a file)
  22. const inputStream = fs.createReadStream('input.raw');
  23.  
  24. // Pipe the input file into FFmpeg's stdin
  25. inputStream.pipe(ffmpeg.stdin);
  26.  
  27. // Handle the output stream
  28. ffmpeg.stdout.on('data', (data) => {
  29.     // Handle the data from FFmpeg's stdout
  30.     console.log('Data from FFmpeg:', data);
  31. });
  32.  
  33. // Handle errors
  34. ffmpeg.stderr.on('data', (data) => {
  35.     console.error('Error from FFmpeg:', data.toString());
  36. });
  37.  
  38. ffmpeg.on('close', (code) => {
  39.     console.log(`FFmpeg process exited with code ${code}`);
  40. });
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement