Skip to content

Instantly share code, notes, and snippets.

@bcarlso
Created August 22, 2010 17:49
Show Gist options
  • Save bcarlso/544052 to your computer and use it in GitHub Desktop.
Save bcarlso/544052 to your computer and use it in GitHub Desktop.
Create a movie using ffmpeg
class MovieBuilder
include FileUtils
def initialize(image_directory = '.', image_type = 'png')
@base_dir = image_directory
@temp_dir = "#{@base_dir}/temp"
@image_type = image_type
end
def make(movie_name, frame_rate = 5)
rm_rf @temp_dir
mkdir @temp_dir
Dir.glob("*.#{@image_type}").sort.each_with_index do | file, index |
frame = sprintf('%03d',index + 1)
cp File.join(@base_dir, file), File.join(@temp_dir, "#{frame}.#{@image_type}")
end
`ffmpeg -y -r #{frame_rate} -i #{File.join(@temp_dir, "%03d.#{@image_type}")} #{File.join(@base_dir, movie_name)}`
end
end
MovieBuilder.new.make 'my-project-movie.mp4', 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment