Existing Video to text with Ascii

edited February 1 in Library Questions

Hello everybody,

I'm a real noob so I would realy apreciate if someone would tell me what's wrong with my code. First I just want to use Ascii code to convert an existing video (not using webcam) to text. So I copy past the script- changing it a litle bit after I had some error with font- Anyway, now I dont have an error message but the sketch is just a black screen ....

Here is the code :

import processing.video.*;
Movie video;
boolean cheatScreen;
String letterOrder =
  " .`-_':,;^=+/\"|)\\<>)iv%xclrs{*}I?!][1taeo7zjLu" +
char[] letters;

float[] bright;
char[] chars;

PFont font;
float fontSize = 1.5;
void setup() {
  size(1440, 1080);
  video = new Movie(this, "Torrent.mts");
 int count = video.width * video.height;
  font = loadFont("ProcessingSansPro-Regular-48.vlw");
    letters = new char[256];
  for (int i = 0; i < 256; i++) {
    int index = int(map(i, 0, 256, 0, letterOrder.length()));
    letters[i] = letterOrder.charAt(index);
    chars = new char[count];
      bright = new float[count];
  for (int i = 0; i < count; i++) {
     bright[i] = 128;
void MovieEvent(Movie m) {

void draw() {


  float hgap = width / float(video.width);
  float vgap = height / float(video.height);

  scale(max(hgap, vgap) * fontSize);
  textFont(font, fontSize);

  int index = 0;
  for (int y = 1; y < video.height; y++) {
     translate(0,  1.0 / fontSize);
    for (int x = 0; x < video.width; x++) {
      int pixelColor = video.pixels[index];
      int r = (pixelColor >> 16) & 0xff;
      int g = (pixelColor >> 8) & 0xff;
      int b = pixelColor & 0xff;
 int pixelBright = max(r, g, b);
 float diff = pixelBright - bright[index];
      bright[index] += diff * 0.1;

      int num = int(bright[index]);
      text(letters[num], 0, 0);
 translate(1.0 / fontSize, 0);

  if (cheatScreen) {
    set(0, height - video.height, video);
void keyPressed() {
  switch (key) {
    case 'g': saveFrame(); break;
    case 'c': cheatScreen = !cheatScreen; break;
    case 'f': fontSize *= 1.1; break;
    case 'F': fontSize *= 0.9; break;

Also, once I resolved this problem I would like to know how to use only a restreign number of letters (in a way that all the parts off the image that uses others letters will deseaper)

And sorry for my broken english, I'm french ;)

Thank you all for the help


  • Did you test that the file plays at all?

    I never saw mts as an ending

  • Yes it plays! I tried it before Damn. An other guess?

  • Does the video play at all in Processing in a simple sketch?

    If not, convert from mts to mov or mp4

  • As i said above, yes it plays en mts as a simple sketch. Of course I checked that first :)

  • @sevc -- good to know! I asked because you only said "it plays" after Chrisr asked if it plays "at all." Both the original question and your answer were ambiguous; that could have meant you were able to play it in Media Player or QuickTime.

    • Use the editor to indent your code correctly -- that will make it easier to read and debug.
    • test the length of chars and letters in draw. What is in them? Is it what should be in them?
    • check your text color. If instead of dynamically calculating brightness, you simply set it to (255), can you see the text?
Sign In or Register to comment.