ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Video to ASCII effect

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
jporter313
Video to ASCII effect
on Oct 25, 2007 at 11:11:27 pm

So i posted on the After Effects forum, and thought maybe it would be more apropriate to post here.

I'm trying to create an effect where I can take a video and replace it with ASCII characters.

Kevin Camp came up with this expression which works great, but only renders a single character per text field:

asciiArray = [" ","a","b","c","d","e","f","g","h","i","j"]; // enter characters to range from light to dark values
numCharacters = 10; // enter the total number of ascii characters entered in the array above
imageMap = thisComp.layer("Source Image").sampleImage([position[0], position[1]], [1, 1]);
a = Math.round(linear(imageMap[0], 0, numCharacters));
asciiArray[a]

I tried putting this on a text field and duplicating it in a grid, problem is that it takes a couple thousand layers (all running expressions) to fill the screen area with a sufficient number of ASCII characters and After Effects crashes long before I have enough.

I also found this page:

http://www.creative-workflow-hacks.com/2007/08/27/more-fun-with-sampleimage...

which contains an expression that works for one line of text, so I have fewer layers (I only have to duplicate it per the number of lines), but the problem is it doesn't regulate the width of the text field, so the changing width of the characters change the location of subsequent characters.

I'm really stuck and I've been struggling with this problem for days. Does anyone know how I can achieve this effect?


Return to posts index

Dan Ebberts
Re: Video to ASCII effect
on Oct 26, 2007 at 12:14:09 am

If your video layer is named "target", you can apply an expression like this to a text layer:

density = " .'`,^:" + '";~-_+<>i!lI?/|()1{}[]rcvunxzjftLCJUYXZO0Qoahkbdpqwm*WMB8&%$#@';
target = thisComp.layer("target");
cols = 80;
rows = 60;
w = thisComp.width/cols;
h = thisComp.height/rows;

s = ""

for (var i = 0; i < rows; i++){
for(var j = 0; j < cols; j++){
center = [w/2 + j*w, h/2 + i*h];
sample = target.sampleImage(center,[(w-1)/2,(h-1)/2]);
s += density[Math.round(linear(sample[0],0,1,0,density.length - 1))];
}
s += "r";
}
s


You'll have to fiddle with the font size, tracking, leading, etc. Edit the cols and rows variables to suit your needs

Dan


Return to posts index

jporter313
Re: Video to ASCII effect
on Oct 26, 2007 at 12:56:14 am

Thanks a lot Dan, I'll try that one.


Return to posts index


moldyboot
Re: Video to ASCII effect
on Oct 26, 2007 at 4:00:29 pm

dan, that is quite impressive in it's simplicity (at least to a guy with no scripting knowledge).

in hopes of learning more about scripting...

[Dan Ebberts] "for (var i = 0; i < rows; i++){"

var i = 0, sets the initial value of 'i' to 0. then compares the value of 'i' to the value of rows. and i++ increases the value of 'i' until 'i' exceeds the value of rows, at which point the 'loop' ends (is that correct to call it a loop, or is it like a subroutine).

[Dan Ebberts] "s = """

is this just setting up a variable 's' that initially returns nothing? and it then gets increased (+=) by the value of the density array... until 'i' exceeds the value of rows, at which point 's' is nothing again (and the 'loop' stops).

Kevin Camp
Designer - KCPQ, KMYQ & KRCW


Return to posts index

Dan Ebberts
Re: Video to ASCII effect
on Oct 26, 2007 at 5:31:42 pm

Pretty much. The loop will execute as long as i less than rows. s = "" just establishes s as an empty string. The += appends a new character to the string.

I just noticed that a back slash character got lost when I pasted the code in. I'll try it again, this time using the HTML code tag.



density = " .'`,^:" + '";~-_+<>i!lI?/|()1{}[]rcvunxzjftLCJUYXZO0Qoahkbdpqwm*WMB8&%$#@';
target = thisComp.layer("target");
cols = 80;
rows = 60;
w = thisComp.width/cols;
h = thisComp.height/rows;

s = ""

for (var i = 0; i < rows; i++){
for(var j = 0; j < cols; j++){
center = [w/2 + j*w, h/2 + i*h];
sample = target.sampleImage(center,[(w-1)/2,(h-1)/2]);
s += density[Math.round(linear(sample[0],0,1,0,density.length - 1))];
}
s += "r";
}
s




Dan


Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Oct 30, 2007 at 11:04:52 pm

Dan you make me sick with seemingly easy solutions you come up with!
I was looking for a way to do this before CS3 after seeing the "black tambourines" video by Beck. I long gave up on the idea that I could figure it out myself.

The only thing I would like to add is that when you're experimenting with different video's it's more convenient to use the "layer(index)" attribute (just an other handy thing I learned from Dan)

Setting up the target as "target = thisComp.layer(index -1);"
Now you can just add the video you want to "ascciisize" to the layer above your scripted text layer.

To add a little more depth to my ascii video I made a second text layer with bold type and sampled the same video with crunched levels to limit the bold type to the darkest areas. You do need to adjust the letter-spacing to align the bold and normal type. Beware that adding a second scripted layer really shows that this is a processor intense expression.

asciistuff


Return to posts index


jporter313
Re: Video to ASCII effect
on Nov 5, 2007 at 7:08:27 pm

K, finally got a chance to punch this into After Effects.

I must be doing something wrong though. The result Patrick got is exactly what I'm looking for, so I'm excited to figure out what went wrong and fix it.

I created a text layer above the "target" video layer, put some dummy text in there and pasted the expression into the Source Text attribute of the text layer.

When I do this, my dummy text disappears and is replaced by nothing, only a set of fully retracted bounding box handles. Any idea what I could be doing wrong?

Again, thank you to all of you for your help, there's no way I could have done this project without you guys helping me out with this script.


Return to posts index

jporter313
Re: Video to ASCII effect
on Nov 6, 2007 at 12:08:15 am

I'm trying to deconstruct this expression a little bit so maybe I can troubleshoot it myself.

Is the backslash that got left out in this statement: " s += "r";", should it be " s += "/r";" instead to add a return character to the string?

Also, does the solitary "s" at the end of the expression put the final string into the text box?


Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Nov 6, 2007 at 1:30:39 pm

You've probably set your character size too small if you only see the bounding boxes ;-)

I've commented Dan's expression for you. Hope it helps you to understand it :-)

One other thing, you can make your own set of characters ranging from light to dark. I wasn't really fond of the "@" as the darkest character so I've altered the desity string to suit my taste.

Here's the commented expression;

density = " .'`,^:" + '";~-_+<>i!lI?/|()1{}[]rcvunxzjftLCJUYXZO0Qoahkbdpqwm*WMB8&%$#@';

/* "density" is just a string ordered with characters from light to dark (" " is white and "@" is black).You can access each character from this string as an array. "density[1]" would be "." since array entries start counting by zero (desity[0] = " ") */

target = thisComp.layer(index -1);

/* the target variable will hold the reference to the layer above the texts layer where you've added this expression */

cols = 80; //number of characters/columns that make up the width of the grid
rows = 60; //number of characters/rows that make up the height of the grid

w = thisComp.width/cols;
// dividing the width by the number of columns gives you the width of each "cell" in the grid

h = thisComp.height/rows;
// dividing the height by the number of columns gives you the height of each "cell" in the grid

s = "" // this declares an empty variable to hold the string that makes up your ascii art

// Next comes a nested loop that makes it all happen...

for (var i = 0; i < rows; i++){ // adding the rows

/* the value of "i" is zero, repeat this action while "i" is smaller than the number of rows, increment "i" with one after each execution of the embedded script */

//the real nested loop

for(var j = 0; j < cols; j++){ // adding the columns to the row

/* the value of "j" is zero, repeat this action while "j" is smaller than the number of columns, increment "j" with one after each execution of the script */

center = [w/2 + j*w, h/2 + i*h];

// divide the width/height of the cell in half and add j times the width/height to that value results in the centre-point of each cell

sample = target.sampleImage(center,[(w-1)/2,(h-1)/2]);

// uses the "center" variable for the position and sets the size of the point to be sampled based on the size of your grid-cells. sample will hold an array of three numbers between 0 and 1 (1=white and 0=black)

s += density[Math.round(linear(sample[0],0,1,0,density.length - 1))];

// the variable "s" is incremented with a character from the "desity" string. The expression between the straight brackets uses the first value of the sampled color in the sample variable to produce an integer/rounded number which is used to select the character to add to the string "s"
}
s += "r"; // After a row is completed this adds a new line to the text until all rows are built.
}
s // in the end the completed string is echoed by this simple notation and this is what shows up on the text layer.


Return to posts index

jporter313
Re: Video to ASCII effect
on Nov 6, 2007 at 5:20:56 pm

thanks Patrick, that's a great learning tool.

I'm still having trouble figuring out why my text isn't showing up though. I had dummy text in the field that when the expression is disabled shows up fine, text size is set to 72px so it seems like it should be showing up. Any other ideas? Where should the text field be placed? would that affect the expression?


Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Nov 6, 2007 at 7:07:09 pm

This is probably the easy way... download my source file and see what you did wrong. Please post your findings it might be helpfull to other users... remember "sharing is hapiness" :-)

Download the source here:
http://rapidshare.com/files/67890829/ASCII_EXPERIMENT.aep


Return to posts index

jporter313
Re: Video to ASCII effect
on Nov 6, 2007 at 11:39:30 pm

Ok, thanks Patrick, step in the right direction. I was missing the slash on the return tag.

I now have some text that looks like it's being driven by the video. The issue I'm having now is that it seems to be having problems justifying it. The variable width of the characters make it so the lines come to different lengths.

I thought the way to overcome this would be to set the field to "justify all" in paragraph, however when I do this I get what looks sort of like some weird word wrap which screws up the whole deal.

I thought maybe the cause of this was that the characters were too closely spaced so they were getting pushed onto the next line despite the justification, but this seems to happen until I set the number of collumns down to a ridiculously low number (like 10) and there's huge spaces in between each letter.

You'd think maybe that would be a problem with my tracking being set too high, but it's set to 0.

Any ideas?


Return to posts index

jporter313
Re: Video to ASCII effect
on Nov 6, 2007 at 11:54:24 pm



Here's a picture of what it comes up with. I don't know if I can post the source image, but let me assure you, this in no way replicates it.


Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Nov 7, 2007 at 5:56:10 pm

This expression is set up to use the most dense character to represent black (@) and the most open character for white (space). If you use white type on a black background your image will look inverted. To overcome this you could invert the order of the characters in the density variable or invert your sample image (and use black type on a white background)

I see some outlined characters in your image and extreme variation in the spacing.
I suggest you use a more ascii like character like courier or some typewriter font...

You can't seem to make out what is represented by the ascii art....
I had the same kind of results when I used a colour image.

I made a pre-comp with my video and boosted the contrast with the levels filter. I desaturated the video with the hue/saturation filter and to get a more predictable result I applied a posterize filter to bring it back to six levels of gray... in the main comp I inverted the colour of my pre-comp.

Did you get a chance to use my source file?




Return to posts index

jporter313
Re: Video to ASCII effect
on Nov 7, 2007 at 6:01:00 pm

Yes, got a chance to use your source file. It fixed the text not showing up problem. Thank you again.

I'll try a different font, see if that fixes the weird spacing problem I'm having.

As far as reducing the image to black and white and playing with the contrast, I did that, I'll play with it some more though.


Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Nov 7, 2007 at 6:04:31 pm

Small correction on the setup of this expression:

This expression is set up to use the most dense character to represent white (@) and the most open character for black (space). If you use white type on a black background your ascii art will look inverted. I like ascii art better as black type on white paper.


Return to posts index

jporter313
Re: Video to ASCII effect
on Nov 7, 2007 at 7:30:38 pm

well, I got it working. Thanks a lot to Dan Ebberts, Moldyboot, and Patrick Deen. I know a lot more about After Effects scripting than I did a week ago, and I'm pretty happy with the results.

The trick for the spacing problem was the font. As soon as I set the font to Courier and the justification to left, it solved that problem completely.


Return to posts index

Olivier Vincent
Re: Video to ASCII effect
on Aug 28, 2008 at 2:36:04 am

I am such a beginner here...
Could anyone help me by chance understand what are the step by steps for transforming a short video to ascii?
i have imported by 10 seconds video but the script does not want to run.

I must be missing several big things...

Thanks!
o



Return to posts index

Olivier Vincent
Re: Video to ASCII effect
on Aug 28, 2008 at 5:03:00 pm

I have downloaded your source file. But I can't seem to be able to replace the "REPLACE ME" layer with my to-be-asciied own movie.

Any help welcome!

Thanks, o



Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Aug 28, 2008 at 8:10:01 pm

Well, replacing the layer is the easy part... Just import your video.
Place it in the comp and make sure the layer is just above the text layer with the script. You can delete the "replace me" layer. I you've read the thread you probably have seen my comment on the "index-1".

OK, hope this helps ;-)



Return to posts index

Olivier Vincent
Re: Video to ASCII effect
on Aug 29, 2008 at 1:08:08 am

It works beautifully well!

It took me a while (as a pure beginner to AE) to get it properly working... But now I managed to play with the ascii definition, color, etc...

This is a very elegant script.

Thanks a lot!!!



Return to posts index

Eric Manevy
Re: Video to ASCII effect
on Nov 15, 2008 at 5:52:56 pm

Good evening Patrick
i'm very interesting about your ascii .aep project , i tryed to download it but i think it has been removed from the site.i'm novice with expressions and got the same probleme with syntaxe ( where must i put this code in the text layer ? ) ,Arrgh ! would you be able to join this project again, it woud help me very much in my work !
Thanx a lot for your help
Eric from Paris



Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Nov 15, 2008 at 7:07:10 pm

Hello Eric,

First of all, I can't take credit for the script as it was written by Dan Ebbert but I did upload my source file for everyone to use in their own project. And for you.... I'm uploading it again. I think that all questions that may arise are answered in the previous post. Remember to use a mono-spaced font and have it aligned to the left. If you want to know what everything in the script means you should read the commented version of the script a few posts up...

Good luck with it and enjoy.... and don't forget to thank Dan ;-)

reuploaded ascii file:
http://rapidshare.com/files/164094989/ASCII_EXPERIMENT.aep




Return to posts index

Eric Manevy
Re: Video to ASCII effect
on Nov 15, 2008 at 9:32:18 pm

Merci beaucoup, tanx a lot Patrick and Dan for all this informations ,now i can begin my work on ASCII , i will make a good experience with your project patrick, and it's moving !!
Eric




Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Nov 6, 2007 at 5:27:16 pm

Copy pasting leads to stupid errors ;-{
I missed a backslash in my post (among other type errors but this one is crucial)

s += "r"; // After a row is completed this adds a new line to the text until all rows are bu


Return to posts index

Emmanuel Kowandy
Re: Video to ASCII effect
on Sep 11, 2012 at 7:04:39 pm

Hello Patrick,

I am a new After Effect user, CS5 version.

For a VJing project, I search a ASCII Art effect.
I found this old post, I tried it but with no success.

Your download source (ASCII_EXPERIMENT.aep) does not exist any more.
Can you post a new link?

Thank you for your help.
Emmanuel from Arras


Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Sep 11, 2012 at 7:38:39 pm

Hello Emmanuel,

Sorry to inform you I no longer have the project file. All you really need to know is here in this thread.
You need a comp with a video called target and a textlayer with Dan Ebberts expression in the sourcetext property. (just cop-paste it from the thread)

(Check for my version of the script with comments to get an idea what does what in the script)

Good luck,

Patrick

http://www.localoca.com


Return to posts index

Emmanuel Kowandy
Re: Video to ASCII effect
on Sep 11, 2012 at 8:22:29 pm

Thank a lot for your answer so quickly.

I will try again.

Thank you very much.
Emmanuel


Return to posts index

Patrick Deen
Re: Video to ASCII effect
on Sep 11, 2012 at 8:46:19 pm

I though I'd check if I could recreate this thing. I can't seem to get it to work either. This was made with cs3 or cs4. I might have a backup somewhere. I'll post it if I can find it.

http://www.localoca.com


Return to posts index

Emmanuel Kowandy
Re: Video to ASCII effect
on Sep 11, 2012 at 10:01:39 pm

Ok, thank you Patrick.

I have test your method, a composition with a video called target and a textlayer with Dan Ebberts expression in the sourcetext property.

But without result.

Perhaps I forgot something.

Here a link towards a screenshot of my After Effect : http://lalettrek.com/capture.jpg

This is a french version of AE.

Emmanuel


Return to posts index

Dan Ebberts
Re: Video to ASCII effect
on Sep 11, 2012 at 11:19:34 pm

It works for me once you add the backslash before the "r" in the line

s += "[insert backslash here]r";


Dan



Return to posts index

Dan Ebberts
Re: Video to ASCII effect
on Sep 11, 2012 at 11:29:05 pm

By the way, if you wanted to use luminance, you just need to change a couple of lines:

sample = rgbToHsl(target.sampleImage(center,[(w-1)/2,(h-1)/2]));
s += density[Math.round(linear(sample[2],0,1,0,density.length - 1))];


Dan



Return to posts index

Emmanuel Kowandy
Re: Video to ASCII effect
on Sep 12, 2012 at 7:28:16 am

Thank you a lot for your help Dan and Patrick!

The power of the backslash is magic!!! ;-)

Now I can continue my projet, as I wanted it.

Just by curiosity, do you think that it is possible to interpret the color?

Thank you again!
Emmanuel


Return to posts index

Dan Ebberts
Re: Video to ASCII effect
on Sep 12, 2012 at 5:59:51 pm

>do you think that it is possible to interpret the color?

I'm not sure what you mean. You have access to the R,G,B,A and (with conversion) the H,S,L,A color channels. Did you mean that you wanted to color each character based on the color at that sample point? Unfortunately, when you use an expression to generate a text layer's text, you can't have multiple colors. However, you might be able to use the text as a track matte for a matching mosaic layer. That might work.

Dan



Return to posts index

Emmanuel Kowandy
Re: Video to ASCII effect
on Sep 12, 2012 at 6:12:42 pm

Yes, this is what I mean.

For exemple at this blog link : http://aeportal.blogspot.fr/2010/04/ascii-art-after-effects.html


Return to posts index

Sean Archibald
Re: Video to ASCII effect
on Nov 23, 2016 at 2:08:31 pm

It looks like many people here have been able to make use of Dan's great looking script over the years. I have just tried to use this script in AE CC2015 today, but I get the following error:

After Effects error: unbalanced unlock

( 7 :: 40 )


This is after pasting the text into the Source Text expression of a text layer. There was already a video titled 'target' in my composition. The error remains even after purging my memory and cache (Edit > Purge > All Memory & Disk Cache...)

Please can anybody confirm if this script should work in CC2015? I would be so grateful to start using this kind of ASCII effect for an upcoming project. Thanks!


Return to posts index

Harry Hoag
Re: Video to ASCII effect
on Jul 3, 2014 at 9:07:16 am

Hi Guys,

I havent used this yet but looks like someone is charging to do the same thing:
http://aescripts.com/l3tt3rm4pp3r/

Not sure why you would buy that when you can use this amazing expression!

Has anyone checked to see if they're ripping off Dan's script?


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]