Fork me on GitHub


A Ruby library to destroy your AVI files.


Install Ruby if you have not. And install AviGlitch through rubygems.

$ sudo gem install aviglitch

Codes and Examples

We'll show some code examples here. Before that, there is something you need to know.

The input file must be an AVI formatted file. AviGlitch doesn't provide any file converting function, use ffmpeg or something to make an input sample.

We recommend making the input file in small size (5 mins or shorter) for saving your machine power and executing time.

If you use Ruby 1.8.x, you must require 'rubygems' on the top of code lines.

And what we do is basically an illegal operation for the file and the player application, try codes at your own risk.

Datamoshing of the Dead

At first, let's do a simple glitch that is known as datamoshing. Datamoshing means key frames removed video. You can see in the code below that AviGlitch provides an easy way to remove key frames.

require 'aviglitch'
a = 'file.avi' # Rewrite this line for your file.
a.glitch :keyframe do |f|     # To touch key frames, pass the symbol :keyframe.
  nil                         # Returning nil in glitch method's yield block
end                           # offers to remove the frame.
a.output 'out.avi' 

This code will generate a video like this.

The AviGlitch library includes a command line tool named datamosh, The datamosh command does same thing as the code above. Without any coding, in the terminal, simply type;

$ datamosh file.avi

This is the world's easiest way to make a datamoshing video. If you like a complex and messy way, learn from this guy.

Crshed Universal

Next is an example of the frames manipulation. It's bit complicated. Following code makes a certain frame repeated a number of times.

require 'aviglitch'
a = 'file.avi'       # Rewrite this line for your file.
d = []
a.frames.each_with_index do |f, i|
  d.push(i) if f.is_deltaframe?     # Collecting non-keyframes indices.
q = a.frames[0, 5]                  # Keep first key frame.
100.times do
  x = a.frames[d[rand(d.size)], 1]  # Select a certain non-keyframe.
  q.concat(x * rand(50))            # Repeat the frame n times and concatenate with q.
o = q                # New AviGlitch instance using the frames.
o.output 'out.avi'

It makes a beautiful glitch like this.

VLC Bending

Next example uses a pretty neat trick. Following code overwrites key frames' screen size data randomly.

require 'aviglitch'
a = 'file.avi'
a.glitch_with_index(:keyframe) do |data, i|
  x = data[25..28].unpack('B*').first
  w = rand(('0b' + x[0..12]).oct * 1.5)
  h = rand(('0b' + x[14..26]).oct * 1.5)
  x[0..12] = "%013b" % ((w > 50) ? w : 50)
  x[14..26] = "%013b" % ((h > 50) ? h : 50)
  (i == 0) ? data : data[0..24] + [x].pack('B*') + data[]
a.output 'out.avi'

And to play the result output with the VLC player, it becomes like this.

It completely depends on the VLC player application and the Xvid codec. It doesn't work with other player and codec combinations.

Utah Kawasaki Band Aratame Ucnv Band on June 28, 2010

At last, we will show the achievement of excess glitches using ffmpeg, mencoder and AviGlitch (and no Adobe stuff).

For more details, read the documentation.