Skip to content

Instantly share code, notes, and snippets.

@Marahin
Created January 24, 2023 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marahin/33186293acbfadb7af3478392aff83cd to your computer and use it in GitHub Desktop.
Save Marahin/33186293acbfadb7af3478392aff83cd to your computer and use it in GitHub Desktop.
#!/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