Glitch Webcam

Glitch Webcam* is a small script that was developed during my time at Databit.me as part of the Open Camera project, which aimed at finding inexpensive ways to take images. Since then it has been in the MEMIC exhibition in November 2012 and usually makes an appearance wherever my laptop goes.

At only five lines of code and ~254 bytes, this script is a very quick way to glitch photos taken automatically by a webcam. The project was originally demoed using a Raspberry Pi/Raspbian and a digital photo frame, though problems with USB have prevented me from doing that since.

Below is the script, which requires you to have installed Streamer, feh (1.3.4 used), sed and xdotools:

[sourcecode language=”bash”]#!/bin/bash
mkdir output & streamer -s 640×480 -o ./output/glitch_00000000.jpeg -t 1000000000000 -r 0.48 &
sleep 1.8 ; feh –action1 ";sed -i s/g/2/ %f" -F -r ./output/ –force-aliasing -Z -Y –reload 1 –slideshow-delay 2 &
while true ; do xdotool key –delay 200 1 ; done[/sourcecode]

The script works by using Streamer to capture sequentially-numbered images to a folder called “output”. feh is then used to display the image and also to run a sed command, thanks to the –action1 option. Actions in feh can only be run via a key press, so xdotools is used to automatically press a key (1). feh is then finally used to display each image full-screen.

It’s not the most efficient way of glitching from a webcam – e.g. you can get glitch plugins for Pure Data, Quartz Composer and other software – but as a small utility it works well. Also, it saves all of the images so you can make an animation out of it!

Glitch Webcam

*terribly unimaginative name, I know!

Extrude in Inkscape

To design the poster image for The People VS The Machine I revisited an old technique that wrote about in 2009. The technique used the Extrude extension in Inkscape, combined with the Color > Randomize extension to create what could be described as a stained-glass effect for text.

TPVTM outline

I wanted to do the same and create an extrusion between each letter of the title text. This, however, presented a few challenges. In versions of Inkscape up to 0.49 the extrude extension would only work on two selected objects. Even if you highlighted more than two objects the extension would only choose two of them to apply the extrusion to (I’m still not sure how it decides which two to choose). I could do this manually with each pair of letters, but this would take a long time and could easily get confusing!

Pairing

I took my concerns to the Inkscape bug tracker. I explaind what I expected to see when I ran the extension on two or more objects:

Two objects – one extrusion

If you select two objects it should create one extrusion. Simple enough!
Two objects

Four objects – six extrusions

If you select four objects it creates six extrusions. A bit more complicated…
Four objects

Six objects – fifteen extrusions

If you select six objects it creates fifteen extrusions. Now it gets more complicated!
Six objects

As you can imagine doing all of that by hand would take some time and would be hard to keep track of. In fact, for all of the letters I would have to run the Extrude extension 220 times!

I argued my case to the developers of Inkscape on their bug tracker. After a bit of discussion around the intended purpose of the extension it has now been updated to work on all selected objects. The updated extension should be in Inkscape 0.49. Thanks to ~suv and to Alvin Penner for updating the extension!

Pure Data Play, Friday 2nd November

On Friday 2nd November from 12pm I’ll be running a Pure Data workshop as part of Flip Festival at Lighthouse Media Centre in Wolverhampton.

pd

Pure Data is a dataflow programming language that is utilised for a wide variety of purposes including making generative electronic music, creating glitch visuals, interactive live performance and VJing (Video Jockeying). I’ll guide participants through the basics of Pure Data – including general usage, playing and manipulating videos and creating generative visuals that respond to different inputs. No experience of Pure Data is necessary, only a laptop and a willingness to experiment and learn!

The event is free to Flip Festival ticket holders and £6 for everyone else. Tickets can be purchased online. Here’s the event details on Facebook. Don’t forget to bring your laptop!

To see what can be created with Pure Data take a look at what I’ve made in the past.

Create jpgs in Pure Data

For Some of My Favourite Songs I utilised Pure Data Extended (I’m using a beta version) to read the audio files and then save them as images. Pure Data is usually used for the production of music and/or generative live visuals, so to using it to produce jpg images from almost nothing, or random data input is quite new to me!

In search of a jpg header

The most important part of this process is knowing how to construct and apply a jpg header to data. Wikipedia informed me that all jpg images begin with FF D8. I thought that all I would need to do is use a hex editor, such as Ghex or Bless Hex Editor, to add those byte values to a file.

Unfortunately this is not the case at all. There’s so much more in a jpg header, such as Huffman Tables, Quantization Tables, bytes to define the width and height of an image, and much more that I still don’t quite understand.

I attempted to grab data from the beginning of a random jpg file, but this included lots of extraneous data such as camera make, program(s) used to modify the photo, gps data and creation date. This data amounted to several kilobytes, which is far too much data for a header. What I needed was a “vanilla” or plain header that I could apply to any file.

mesmeon showed me the HEADer REMIX project by Ted Davis. The header values on the left of the screen are used for glitching every image, be it the default image or one taken by a user.

I saved the default image, manually extracted the header image, ran it through exiftool and then ended up with a header for a 640×480 image that is only 588 bytes!

Enter Pure Data

Now that I had a vanilla header I had to devise a way to use it in Pure Data. The [binfile] object allows the reading and writing of binary data. Adding data to [binfile] is a case of sending a message containing numbers to the object.

[binfile] reads and outputs data as decimal values i.e. numbers from 0 to 255. I needed to find a way to add the decimal values of the vanilla header to a message box. Martin Meredith helped me with this whilst we were tackling bugs at the Ubuntu Global Jam. Using hexdump I was able to output all of the hex values to decimal values.

[bash]hexdump -v -e ‘1/1 "%02u "’ filename.here > decimalvalues.txt[/bash]

[bash toolbar=”true”]255 216 255 219 00 132 00 03 02 02 03 02 02 03 03 03 03 04 03 03 04 05 08 05 05 04 04 05 10 07 07 06 08 12 10 12 12 11 10 11 11 13 14 18 16 13 14 17 14 11 11 16 22 16 17 19 20 21 21 21 12 15 23 24 22 20 24 18 20 21 20 01 03 04 04 05 04 05 09 05 05 09 20 13 11 13 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 255 192 00 17 08 01 224 02 128 03 01 17 00 02 17 01 03 17 01 255 196 01 162 00 00 01 05 01 01 01 01 01 01 00 00 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 10 11 16 00 02 01 03 03 02 04 03 05 05 04 04 00 00 01 125 01 02 03 00 04 17 05 18 33 49 65 06 19 81 97 07 34 113 20 50 129 145 161 08 35 66 177 193 21 82 209 240 36 51 98 114 130 09 10 22 23 24 25 26 37 38 39 40 41 42 52 53 54 55 56 57 58 67 68 69 70 71 72 73 74 83 84 85 86 87 88 89 90 99 100 101 102 103 104 105 106 115 116 117 118 119 120 121 122 131 132 133 134 135 136 137 138 146 147 148 149 150 151 152 153 154 162 163 164 165 166 167 168 169 170 178 179 180 181 182 183 184 185 186 194 195 196 197 198 199 200 201 202 210 211 212 213 214 215 216 217 218 225 226 227 228 229 230 231 232 233 234 241 242 243 244 245 246 247 248 249 250 01 00 03 01 01 01 01 01 01 01 01 01 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 10 11 17 00 02 01 02 04 04 03 04 07 05 04 04 00 01 02 119 00 01 02 03 17 04 05 33 49 06 18 65 81 07 97 113 19 34 50 129 08 20 66 145 161 177 193 09 35 51 82 240 21 98 114 209 10 22 36 52 225 37 241 23 24 25 26 38 39 40 41 42 53 54 55 56 57 58 67 68 69 70 71 72 73 74 83 84 85 86 87 88 89 90 99 100 101 102 103 104 105 106 115 116 117 118 119 120 121 122 130 131 132 133 134 135 136 137 138 146 147 148 149 150 151 152 153 154 162 163 164 165 166 167 168 169 170 178 179 180 181 182 183 184 185 186 194 195 196 197 198 199 200 201 202 210 211 212 213 214 215 216 217 218 226 227 228 229 230 231 232 233 234 242 243 244 245 246 247 248 249 250 255 218 00 12 03 01 00 02 17 03 17 00 63[/bash]

(The output is sent to a text file for ease of copy/pasting)

With this output I copy/pasted the values into a message box, and whenever I needed to add a jpg header to a file I clicked on the message box! To then write the file I sent the message [write filename.jpg( to the [binfile] object.

A jpg header in Pure Data

Using this data alone you may notice that the jpg image doesn’t open in certain image viewers or is blank/black. That is because all that was added is the header. Image data is also needed! For this I added a few [metro]s to generate random numbers between 0-255. The output image then looks a little bit more colourful now.

jpg created by Pure Data

For some websites and image viewers the End Of Image bytes (FF D9/255 217) need to be added in order for it to be viewed properly. To start this process again send [clear( to [binfile]. This clears all binary data. Below is all of this theory put into one patch.

The finished Pure Data patch

Pure Data [binfile]

Generate jpg images – click to download

To use it, first click on the button to start the jpg file, then click the toggle button to add lots of random data. This may take a minute or so. Once done turn off the toggle, click on the button to end the file and then write the jpg image.

Further options

If you know the structure of a certain file type, in theory, it is possible to construct one in a similar way to this. I’ve already used this method to construct a bmp, but they produce far less interesting results. png files seem to be more fragile and, as such, I haven’t managed to create one using this method.

If you use a second [binfile] object you can load the bytes from another file and use them, in conjunction with random data, to produce glitchy – but slightly recognisable – images!

Is it also possible to reduce the size of the jpg header even further?

Create jpgs in SuperCollider

Holger Ballweg (uiae) has recreated this progress in SuperCollider. Check it out!

Feedback Loops in Pure Data

Recently I’ve been making a few video loops for Dreambait Recordings to use in their shows. The videos, made using video samples and Pure Data, focus on feedback loops. For BYOB Birmingham on Friday 16th March I decided to showcase these video feedbcak creations. Some photos of it in action:

BYOB Birmingham

BYOB Birmingham Flatpack Festival 2012

Photo by minuek

The Pure Data patch used to make these visuals, inspired by this patch is pretty simple: Put an object on screen, take a snapshot of the screen and then apply that snapshot as a texture to another object. You can download it below

Feedback Loops patch

Click to download

As a texture for the cube I used the Skin Cells video again. You could replace this with any video, image or webcam feed. The [pix_contrast] object is there purely to provide an over-saturated look (try bringing Saturation to a negative number). For BYOB I automated the controls by using random number generators (feeding [random] into [metro]). Here’s a render of what the audience saw:

All that is needed now is some cool audio to go with it! Thanks to all those that came to BYOB to see this and other awesome artworks!

Alpha Glitch

For my performance with Freecode as part of Network Music Festival I wanted to move away from producing visuals that consisted mostly of video playback and move towards generative art. Demos of this were posted on my Flickr site, and the first performance that utilised this new approach happened on 26th January

The feedback from people online and at the performance was really positive, with a lot of people were asking how to do something similar. The patch I made for it was very messy so I (albeit slowly) remade part of the patch that achieves that effect. It’s available for download below

Alpha Glitch

Click to Download

This isn’t strictly a generative patch as it still relies on an source image/video as a texture, but I think it’s more generative than it is video playback. The patch, made in Pure Data, works first by using [repeat] to generate many cubes which are zooming towards the screen. These, then, are textured with an image of your choice. The “magic” comes in the use of [pix_alpha]. The red, green and blue sliders remove a percentage of that colour from the image texturing the cubes, revealing the cube below. The green toggle button randomly removes a different percentage of each colour at different speeds. This, coupled with the constant movement of the cubes I think creates a sort of animated glitch using only a still image.

Sound confusing? Hopefully it’ll become clearer once you dissect the patch and view the help patches of each object. Here’s an example of the output from this patch using this image from my Skin Cells video:

If you know Pure Data well you can modify the patch so that it uses videos or a webcam feed instead of a still image. However, be aware that having that many objects on screen with a video stream can cause the output to be stuttery. This patch was made with Pure Data Extended 0.43 on Ubuntu 11.10.

Making Skin Cells

The making of Skin Cells was quite a long process. It started projecting my Bunnies video onto me and filming this. I then took this and ran it through the What Glitch? sgi script to create a glitched version of the video, leaving me with two versions of the video.

Skin Cells

Skin Cells

When it came to merging the two videos together I took some inspiration from Tidepool by Tabor Robak. Putting the videos on top of each other I wanted to use chromakeying to reveal parts of the video at the bottom at the same time as really oversaturating the video. For this I employed the help of Pure Data:

Skin Cells Pure Data patch

By using [pix_chroma_key] and setting the [range( to random values the patch was constantly hiding and revealing random parts of the videos. Some wizardry in Gridflow gave the videos that oversaturated look.

If you want to try this patch for yourself go ahead and download it. Although it may work on other setups, I used the following:

To use the patch, first load a directory of videos, create the GEM window and then press the big red start button. A video is automatically saved (using PDP), though do be careful as these files get very large very quickly! If, for any reason, saving the video doesn’t work just delete the line going from [#from_pix, colorspace rgb] to [#to_pdp].

If any assistance is required please direct your attention to this thread on the Pure Data forum.

LÖVE Glitches

Whilst I was in Venice for the Laptop Meets Musicians festival with BiLE I had the pleasure of (finally) meeting {rukano} who later showed me this really awesome way of displaying uncleared video memory with LOVE and LICK. I’m using Ubuntu 11.04 with LÖVE version love_0.7.2-0natty2_i386.deb.

LÖVE glitches

Once you have downloaded and installed LÖVE and LICK (instructions for different platforms are provided on their websites) create the following files:

main.lua

[sourcecode language=”bash”]require "LICK"
require "LICK/lib"
lick.reset = true
lick.clearFlag = true

function love.load()
fb = love.graphics.newFramebuffer(800,600)
end

function love.draw()
love.graphics.draw(fb, 0, 0)
end

function love.keypressed (a)
print(a)
if a == " " then
fb = love.graphics.newFramebuffer(800,600)
end
end[/sourcecode]

conf.lua

[sourcecode language=”bash”]function love.conf(t)
t.modules.joystick = true — Enable the joystick module (boolean)
t.modules.audio = true — Enable the audio module (boolean)
t.modules.keyboard = true — Enable the keyboard module (boolean)
t.modules.event = true — Enable the event module (boolean)
t.modules.image = true — Enable the image module (boolean)
t.modules.graphics = true — Enable the graphics module (boolean)
t.modules.timer = true — Enable the timer module (boolean)
t.modules.mouse = true — Enable the mouse module (boolean)
t.modules.sound = true — Enable the sound module (boolean)
t.modules.physics = true — Enable the physics module (boolean)
t.console = false — Attach a console (boolean, Windows only)
t.title = "live_testproject" — The title of the window the game is in (string)
t.author = "Your Name Here" — The author of the game (string)
t.screen.fullscreen = false — Enable fullscreen (boolean)
t.screen.vsync = true — Enable vertical sync (boolean)
t.screen.fsaa = 0 — The number of FSAA-buffers (number)
t.screen.height = 600 — The window height (number)
t.screen.width = 800 — The window width (number)
t.version = 0 — The LÖVE version this game was made for (number)
end[/sourcecode]

Compile all of this code into something like Glitch.love. Instructions for this may be different for different operating systems. Before launching the program be sure to first open lots of videos and images. Once you’ve done that, launch the Glitch.love program and press spacebar to cycle through your uncleared video memory!

Shoutouts go to Tilmann Hars, who first showed this trick to rukano and who maintains the LICK library.

p.s. I’m still trying to find out how to do this kind of stuff using Pure Data. If anyone knows how please let me know!

Adventures in Vector Quantization

Ever since seeing Radio Dada by Rosa Menkman I’ve been forever trying to reproduce the style of compression/glitches it uses.

In my limited knowledge about the production of the video I do know what it uses compression artifacts found in the Cinepak codec. So, I set out to try and find a way of converting a video to a video that uses the Cinepak codec. If you’ve been following me you’ll that I’ve asked for help on many fora and mailing lists for help with initially little success.

Hidden somewhere in the documentation for MEncoder is a page detailing how to use Windows codecs on Linux for encoding. The copy of the Cinepak codec (iccvid.dll) that came with MEncoder/medibuntu was a bit broken so I had to use Google to download a new version.

Once I had that I used MEncoder to convert a video to an avi with the Cinepak codec. (I’m using mencoder version 2:1.0~svn33951~natty):

[sourcecode language=”bash”]mencoder infile.avi -ovc vfw -xvfwopts codec=iccvid.dll -oac mp3lame -o outfile.avi[/sourcecode]

Unfortunately for me this did not produce the compression artifacts that I was after. I tried reencoding the video using the Cinepak codec several times but this only just made the video darker:


(Original video)

Also, my attempt to encode the video using the Cinepak codec but with a low bitrate didn’t work as, at least when using MEncoder, the codec doesn’t have any encoding options. Drats! With that said, if anyone knows of a way of encoding using Cinepak with low/different bitrates on Linux using only freely available/open source software please do let me/the world know.

After this I felt very disheartened until I did a little bit of digging into the actual codec. I discovered that this codec is one of a few is based on Vector Quantization. I don’t know much about this but I felt that this must be the key. The video codecs that are based on Vector Quantization are Sorenson, Indeo and VQA.

I had no luck finding a way of converting to Sorenson and Indeo. However, I’ve had more luck with VQA. Wikipedia has a bit of information on the codec:

Vector Quantized Animation, known by its acronym VQA is a file format originally developed by Westwood Studios for video encoding in their game The Legend of Kyrandia and monopoly.

If you ever came across a Sega Saturn you probably will have come across videos encoded using VQA. As that Wikipedia article states, apart from the one used by Westwood Studios, only one VQA encoder exists. VQA Encoder v0.5 beta 2 by ugordan is the only known VQA encoder and luckily it works perfectly using Wine (I’m using version 1.2.3-0ubuntu1~ppa1) on Ubuntu 11.04. You’ll have to download some additional DLLs. Just do some research to find out which ones.

In order to use the software you need to convert your video to image files. I’ve had luck with converting the video to PCX files using FFMPEG:

[sourcecode language=”bash”]ffmpeg -i infile.avi -sameq outfile_%03d.pcx[/sourcecode]

Then, in the VQA Encoder v0.5 beta 2 copy these options:

VQA encoder options

The program will automatically recognise that there are many images in the folder. After encoding has finished you should have a file called out_.vqa. In FFMPEG execute:

[sourcecode language=”bash”]ffmpeg -i out_.vqa -sameq outfile.avi[/sourcecode]

You should now have a video that has similar compression to the Cinepak codec used with low bitrates:


(Original video)

Brilliant! Well, not so brilliant. The problems with using this software are the following:

  • The software is no long being updated
  • Because of this it could stop working at any time and no support would be offered
  • It can only output video at 640×400, which you can see by the way it crops the video
  • It isn’t open source, though that only matters if you exclusively use open source software

So, is there any other way to achieve these compression artifacts, preferably using open source software?

What Glitch? scripts

For the What is Your Glitch? videos I wanted to build up on some of the extensive work that has already gone into the documentation, deconstruction and glitching of file formats. Rosa Menkman has already done a great job of documenting some of the more well-known file format glitches in the Vernacular of File Formats, which I recommend you all read. For this exercise I wanted to explore some of the more obscure file formats. Using open source software and Ubuntu has given me access to a wealth of programs that can still generate obscure file formats, such as pcx, pix and sgi. Through these experiments I also found inconsistencies in the way that different programs generate files, which is evident through my decision to use GIMP to convert files rather than Imagemagick in some of the scripts. Enough chit-chat, download the scripts!

Code hosted on GitHub

The method of glitching used in most of the scripts is the much-documented find and replace method. If you take a look in the scripts – and I encourage you to do so – you can change the characters that are being searched for and replaced. I’ve simply chosen characters that are sure to get results and are less likely to completely destroy the file.

Required Dependencies

Each script has its own set of dependencies, but to ensure you can run each one you’ll need the following:

  • Sed
  • GIMP – I use 2.71 beta available for Ubuntu from this ppa. Other versions remain untested
  • Imagemagick
  • GlitchSVG
  • FFMPEG
  • Mplayer
  • WebP

Basic Usage

1. Make the file executable: In a terminal type chmod+x [name of script] (e.g. what_glitch_webp.sh)
2. Run ./what_glitch_webp.sh in a terminal window
3. Drop a video file into terminal window and press Enter
4. Get a cup of tea

Notes

  • The scripts have only been tested on Ubuntu 10.10. If you are able to get them working with other operating systems please feel free to share your techniques
  • These scripts seem to work best with avi video files that are 24 or 25 frames per second. Files that are 30 frames per second get out of sync with the audio
  • Make sure the name of the directory containing the video to glitch doesn’t contain spaces e.g. “untitled_folder” instead of “untitled folder”
  • The video needs audio order for this script to work. If you know what you’re doing you can edit parts of this script for it to work on files that have no audio
  • As these scripts processes each frame of a video file it will take a very long time to complete. It is recommended for use only on small video clips!

These scripts by no means even begin to cover all of the image file formats available. There were a few formats that were not as easy to batch-process or were simply too large to process, such as xpm and xbm. For these you’ll have to do it manually or explore other ways of batch processing. They’re also not the most efficient of scripts. Some way into processing 400 video frames the script would slow down a lot. I welcome any bug fixes or suggestions on fixing this 😉

There’s still plenty of undiscovered glitches out there in the wild just waiting to be hunted down and exploited. I encourage anyone, everyone and their mother to pick from this long, but by no means complete list of image file formats and to find a way to glitch them!