Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging two video streams and saving as one file

I'm writing chat application with video call using webRTC. I have two MediaStreams, remote and local and want to merge and save them as one file. So when opening a file, i shall see large video frame (remote stream) and little video frame at top right (local stream). Now I can record these two streams separately using RecordRTC. How can i merge them with nodejs? (no code because I don't know how it's done)

like image 682
karaxuna Avatar asked Oct 21 '22 23:10

karaxuna


1 Answers

You can use FFmpeg with -filter_complex, here is a working and tested example using FFmpeg version N-62162-gec8789a:

ffmpeg -i main_video.mp4 -i in_picture.mp4 -filter_complex "[0:v:0]scale=640x480[main_video]; [1:v:0]scale=240x180[in_picture];[main_video][in_picture]overlay=390:10" output.mp4

So, this command tells FFmpeg to read from two input files, main_video.mp4 and in_picture.mp4, then it send some information to the -filter_complex flag...

The -filter_complex flag takes the [0:v:0] (first input, first video track) and scale this video to be 640x480px and it identifies the video as [main_video], then, takes the [1:v:0] (second input, video track 0) and resize the video to 240x180px naming the video [in_picture], then it merges both videos making an overlay of the second one at x=390 y=10.

Then it saves the output to output.mp4

It is that what you want?

UPDATE: I forgot to add, all you need in node is a module to run FFmpeg, there are plenty of those: https://nodejsmodules.org/tags/ffmpeg

like image 189
Rodrigo Polo Avatar answered Oct 27 '22 09:10

Rodrigo Polo