Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created May 9, 2011 21:53
Show Gist options
  • Save ucnv/963497 to your computer and use it in GitHub Desktop.
Save ucnv/963497 to your computer and use it in GitHub Desktop.
makes glitch beats using AviGlitch
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'
f.gsub /\w/, '1'
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