Created
January 24, 2023 19:22
-
-
Save Marahin/33186293acbfadb7af3478392aff83cd to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
class FFMPEG | |
def self.generate_filter | |
scale_segment = '' | |
ingredients.each_with_index do |_, i| | |
scale_segment += "[#{i}:v]scale=1920:1080:force_original_aspect_ratio=1[v#{i}];" | |
end | |
output_segment = '' | |
ingredients.each_with_index do |_, i| | |
output_segment += "[v#{i}][#{i}:a]" | |
end | |
output_segment += "concat=n=#{ingredients.length}:v=1:a=1[v][a]" | |
"-filter_complex \"#{scale_segment} #{output_segment}\" -map \"[v]\" -map \"[a]\"" | |
end | |
def self.ingredients | |
Dir.entries('media').select { |f| File.file?(File.join('media', f)) && f.include?('mp4') }.map { |f| "media/#{f}" } | |
end | |
def self.inputs | |
ingredients.map { |path| "-i #{path}" }.join(' ') | |
end | |
def self.invocation | |
"ffmpeg #{inputs} -c:v h264_videotoolbox -vsync 2 -b:v 8000k #{generate_filter} stitched-video.mp4" | |
end | |
end | |
puts FFMPEG.invocation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment