1

有没有人知道如何使用 ffmpeg(fluent-ffmpeg) 的 node.js 包装器将两个视频合并为一个在左侧显示另一个在右侧显示的视频,而不是连接。

谢谢!

4

3 回答 3

0

您可能可以使用过滤器的组合来获得您想要的。您首先将第一个视频重新缩放到左侧所需的大小:https ://ffmpeg.org/ffmpeg-filters.html#scale-1

'scale=width:height'

然后应用黑条定位左侧视频;totalwidth并且totalheight是输出视频的最终尺寸,x以及y重新缩放的左侧视频的位置:https ://ffmpeg.org/ffmpeg-filters.html#pad-1

{
  filter: 'pad',
  options: 'totalwidth:totalheigth:x:y'
}

最后,使用复合滤镜overlay放置右侧视频;请注意,它应该首先重新缩放:https ://ffmpeg.org/ffmpeg-filters.html#overlay-1

{
  filter: 'overlay', options: { x: 'x', y: 'y' },
},

这是您的代码应如下所示:(基于快速文档:https ://github.com/fluent-ffmpeg/node-fluent-ffmpeg#complexfilterfilters-map-set-complex-filtergraph )

ffmpeg('left_video.avi')
.input('right_video.avi')
.complexFilter([
 // Rescale input video
 'scale=width:height',

 // Add black bars to position your left video at x, y position
 {
  filter: 'pad',
  options: 'totalwidth:totalheigth:x:y'
 }

 // Overlay the second input for right side video
 {
  filter: 'overlay', options: { x: 'x', y: 'y' },
 },
], 'output');

请注意,我没有测试过它,但它应该可以工作

于 2016-07-06T22:24:12.923 回答
0

这就是我用来并排显示 2 个视频的方式。

ffmpeg()
.input("video1.mp4")
.input("video2.mp4")
.complexFilter([
  '[0:v]scale=300:300[0scaled]',
  '[1:v]scale=300:300[1scaled]',
  '[0scaled]pad=600:300[0padded]',
  '[0padded][1scaled]overlay=shortest=1:x=300[output]'
])
.outputOptions([
  '-map [output]'
])
.output("output.mp4")
.on("error",function(er){
  console.log("error occured: "+er.message);
})
.on("end",function(){
  console.log("success");
})
.run();
于 2020-10-09T19:48:12.007 回答
0

我需要同样的结果;在 NodeJS 中,在一个视频中并排显示两个视频。经过一些研究,我通过使用exec库(Node 随附)和ffmpeg来自此处的 bash 命令来完成此操作:https ://unix.stackexchange.com/a/233833/443530 。

我使用的解决方案(为我工作):

let cmd = `ffmpeg -i ${pathToVid1} -i /home/shani/projects/open-app-p/files${pathToVid2} -filter_complex '[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]' -map [vid] -c:v libx264 -crf 23 -preset veryfast ${outputFilePath}.mp4`; // one line

console.log("executing ffmpeg command... this might take a sec... ");
exec(cmd, (err, stdout, stderr) => {
  if (err) console.log("Error ", err)
  else console.log("Done!")
})
于 2020-12-02T08:54:17.613 回答