Last active
January 28, 2024 16:16
-
-
Save rickychilcott/9a702e811980b47bcc15 to your computer and use it in GitHub Desktop.
FFMpeg multi video overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ffmpeg < Thor | |
package_name "ffmpeg" | |
desc "install", "install ffmpeg" | |
def install | |
`brew install ffmpeg` | |
end | |
desc "merge FILE1 FILE2 FILE3 FILE4 OUTPUT", "" | |
def merge(file_1, file_2, file_3, file_4, output_file) | |
result_height = 360*2 | |
result_width = 640*2 | |
individual_height = result_height / 2 | |
individual_width = result_width / 2 | |
overlay_options="shortest=1" #Shortest video should determine the length of the video | |
cmd = "ffmpeg -i #{file_1} -i #{file_2} -i #{file_3} -i #{file_4} -filter_complex \"nullsrc=size=#{result_width}x#{result_height} [base]; [0:v] setpts=PTS-STARTPTS, scale=#{individual_width}x#{individual_height} [upperleft]; [1:v] setpts=PTS-STARTPTS, scale=#{individual_width}x#{individual_height} [upperright]; [2:v] setpts=PTS-STARTPTS, scale=#{individual_width}x#{individual_height} [lowerleft]; [3:v] setpts=PTS-STARTPTS, scale=#{individual_width}x#{individual_height} [lowerright]; [base][upperleft] overlay=#{overlay_options} [tmp1]; [tmp1][upperright] overlay=#{overlay_options}:x=#{individual_width} [tmp2]; [tmp2][lowerleft] overlay=#{overlay_options}:y=#{individual_height} [tmp3]; [tmp3][lowerright] overlay=#{overlay_options}:x=#{individual_width}:y=#{individual_height}\" -c:v libx264 #{output_file}" | |
`#{cmd}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos was super great!
https://www.ffmpeg.org/ffmpeg-filters.html#Examples-50