Create a gist now

Instantly share code, notes, and snippets.

reorder.rb
# Execute it by loading it within an interactive ruby session by going `irb -r reorder.rb`.
require 'ftools'
require 'yaml'
@files = Dir['*.jpg'].sort
@collection = {}
#set up intro
@collection["colophon.001.jpg"] = 150
@collection["colophon.002.jpg"] = 2
@collection["colophon.003.jpg"] = 2
@collection["colophon.004.jpg"] = 2
@collection["colophon.005.jpg"] = 2
@collection["colophon.006.jpg"] = 2
@collection["colophon.007.jpg"] = 10
@collection["colophon.008.jpg"] = 3
@collection["zzzz-blank.jpg"] = 30
# return an array of files
# that match a given "date"
def lookup(str)
@files.select do |f|
f =~ Regexp.new(str)
end
end
# return an array of files whose
# "dates" are within this range
def range_it(start, cnd)
arr = []
beg = Regexp.new(start)
endd = Regexp.new(cnd)
flag = false
@files.each do |file|
if flag
arr << file
else
if file =~ beg
flag = true
arr << file
end
end
if file =~ endd
break
end
end
arr
end
def oi(str)
`open -a Preview #{str}`
str
end
# "stretch" the amount of time
# a frame "spends" on the screen
def stretch(str, times)
@collection[str] = times
end
# copy & rename the files into a
# numerically increasing series
def writeout
count = 0
@files.each_with_index do |f, i|
if (rep = @collection[f])
rep.times do |j|
out = i + j + count
File.copy(f, "output/#{out}.jpg")
end
count += rep - 1
else
out = i + count
File.copy(f, "output/#{out}.jpg")
end
end
puts "yay!"
end
# count the number of output frames
# used for aligning with the audio
def blank_writeout(foo)
count = 0
@files.each_with_index do |f, i|
if (rep = @collection[f])
rep.times do |j|
out = i + j + count
#File.copy(f, "output/#{out}.jpg")
end
count += rep - 1
else
out = i + count
#File.copy(f, "output/#{out}.jpg")
end
if out == foo
puts f
end
end
count + @files.size
end
def write_this_mofo
`cd output/ && ffmpeg -y -r 30 -i %d.jpg -vcodec libx264 -bf 0 -crf 12 -threads 2 -an -r 30 "filenamehere.mp4" && ffmpeg -i filenamehere.mp4 -i justice.mp3 -map 0:0 -map 1:0 -r 30 -acodec copy -vcodec copy -threads 2 "foo.mkv"`
end
# save the program state, obv.
def dump_it(str = "dump.yml")
open(str, "w") do |io|
io.puts YAML.dump(:files => @files, :collection => @collection)
end
end
def load_it(str = "dump.yml")
dump = YAML.load(open(str).read)
@files = dump[:files]
@collection = dump[:collection]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment