Skip to content

Instantly share code, notes, and snippets.

@rickychilcott
Last active January 28, 2024 16:16
Show Gist options
  • Save rickychilcott/9a702e811980b47bcc15 to your computer and use it in GitHub Desktop.
Save rickychilcott/9a702e811980b47bcc15 to your computer and use it in GitHub Desktop.
FFMpeg multi video overlay
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