Domanda

There's a way to merge an audio (wav) and a video (webm) in a nodejs server?

Since WebM is a container format, I hope that is possible add audio track to an existing WebM file. I'm right?

Anyone know a NodeJS package for doing this?

È stato utile?

Soluzione

Found a solution, but is not really simple to do. For do this is required ffmpeg (or similar).

To install it I done this steps:

  1. (only for mac) install HomeBrew.
  2. run the installation of ffmpeg with all the dependences that is required:

    sudo brew install ffmpeg --with-libvpx --with-theora --whit-libogg --with-libvorbis

    now we can merge a audio and a video file with this shell command:

    ffmpeg -i video-file.webm -i audio-file.wav -map 0:0 -map 1:0 output-file-name.webm

Here we can merge file from our shell, but what I needed was not this. I needed the capability to do this from a NodeJS server, and for doing this now we can run this code.

var util = require('util'),
  child_process = require('child_process');

var exec = child_process.exec;

function puts(error, stdout, stderr) {
  stdout ? util.print('stdout: ' + stdout) : null;
  stderr ? util.print('stderr: ' + stderr) : null;
  error ? console.log('exec error: ' + error) : null;
}

exec("ffmpeg -i video-file.webm -i audio-file.wav -map 0:0 -map 1:0 output-file-name.webm", puts);

This simple solution work fine for me.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top