Merge 3 uploaded videos

Hello,

I’m having 3 categories of videos , one header , main video and one footer.
Headers and footers videos are already on amazon s3.
I want a user to be able to choose between the header , footer , and a main video which he choose to upload and the output to be a merged video of these three.
Would you recommend a correct approach , a gem , a library i could use for that.

Thanks in advance for any help.