Merge WAV audio and WebM video

你。 提交于 2019-12-21 20:35:33

问题


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?


回答1:


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.




回答2:


Take a look at this:

====> https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-to-Nodejs

====> https://github.com/schaermu/node-fluent-ffmpeg



来源:https://stackoverflow.com/questions/20263131/merge-wav-audio-and-webm-video

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!