Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created May 14, 2011 19:52
Show Gist options
  • Save ucnv/972563 to your computer and use it in GitHub Desktop.
Save ucnv/972563 to your computer and use it in GitHub Desktop.
makes glitch beats using AviGlitch (2)
require 'aviglitch'
unless ARGV.size >= 2
puts "Usage: ruby #{$0} INFILE PATTERN [FPS]"
puts " ruby #{$0} file.mp3 0010001000010011"
exit
end
infile, pattern, fps = ARGV
fps = 60 unless fps
cmd = "ffmpeg -i %s -sameq -r %d -vn tmp1.avi" % [infile, fps]
system cmd
a = AviGlitch.open 'tmp1.avi'
a.glitch_with_index do |f, i|
if pattern[i % pattern.size] == '1'
a.frames[rand(a.frames.size)].data
else
f
end
end
a.output 'tmp2.avi'
outfile = 'out' + Pathname(infile).extname
cmd = "ffmpeg -i tmp2.avi -sameq -y %s" % outfile
system cmd
Dir.glob('tmp*.avi').each {|f| File.unlink f }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment