合并 WAV 音频和 WebM 视频 [英] Merge WAV audio and WebM video

查看:72
本文介绍了合并 WAV 音频和 WebM 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 nodejs 服务器中合并音频(wav)和视频(webm)?

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

由于 WebM 是一种容器格式,我希望可以将音轨添加到现有的 WebM 文件中.我是对的?

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

有人知道这样做的 NodeJS 包吗?

Anyone know a NodeJS package for doing this?

推荐答案

找到了解决方案,但做起来并不简单.这样做是必需的ffmpeg(或类似的).

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. (仅适用于 mac)安装 HomeBrew.
  2. 使用所需的所有依赖项运行 ffmpeg 的安装:

  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

现在我们可以使用这个 shell 命令合并音频和视频文件:

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

这里我们可以从我们的 shell 合并文件,但我需要的不是这个.我需要能够从 NodeJS 服务器执行此操作,现在我们可以运行此代码.

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.

这篇关于合并 WAV 音频和 WebM 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆