# Convert video to 1 pixel per frame

**URL:** https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086
**Category:** Libraries
**Created:** [February 25, 2020, 2:00am UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086 "2020-02-25T02:00:14Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![themindfactory](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/themindfactory/32/8177_2.png) [@themindfactory](https://discourse.processing.org/u/themindfactory)
#### Post date: [February 25, 2020, 2:00am UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086/1 "2020-02-25T02:00:14Z")

</div>

Yes you read it correctly I want to convert a video file to a single RGB pixel per frame, so another way to think about it is that this one color per frame is the color you would see on your ceiling when you are watching TV… I am finding it not as easy as you may think… right now it close, but the RGB value when the 1 pixel video is played back I think it “flashes/blinks” too much as the algorithm tried to determine the color…

Anyone?? thanks!

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [February 25, 2020, 10:14pm UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086/2 "2020-02-25T22:14:41Z")

</div>

What would that single frame color be?  
The average of the brightness or what?  
What outcome purpose do you expect?

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [February 28, 2020, 11:07pm UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086/3 "2020-02-28T23:07:34Z")

</div>

> [@themindfactory](#):
>
> right now it close, but the RGB value when the 1 pixel video is played back I think it “flashes/blinks” too much as the algorithm tried to determine the color…

Maybe you should explain what your current approach is? For example, are you computing an average RGB over the pixels array? are you using scaling, or a shader?

> [@themindfactory](#):
>
> the color you would see on your ceiling when you are watching TV

Depending on you area of appliication, you might be interested in bias lighting / ambilight / the adalight – there are privous Processing projects on this, for example:

> [@A universal ambilight](https://discourse.processing.org/t/a-universal-ambilight/1962):
>
> Hi everyone! This project is still a work in progress but I would like to share with you the progress I have made so far, the direction I want to follow and gather some feedback or advice about it. I wanted to build an ambilight system for my TV but the problem I ran into was that I was and still am using only an ethernet cable to get my video feed. So I couldn’t use those solutions you can find online using the HDMI, USB or VGA feed. For those who don’t know what an ambilight system is, here…

---

<div class="post-metadata">

### Author: ![themindfactory](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/themindfactory/32/8177_2.png) [@themindfactory](https://discourse.processing.org/u/themindfactory)
#### Post date: [February 29, 2020, 2:43am UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086/4 "2020-02-29T02:43:34Z")

</div>

averaging gets you a very muddy result!

---

<div class="post-metadata">

### Author: ![themindfactory](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/themindfactory/32/8177_2.png) [@themindfactory](https://discourse.processing.org/u/themindfactory)
#### Post date: [February 29, 2020, 2:50am UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086/5 "2020-02-29T02:50:27Z")

</div>

looks like they are just looking at the perimeter colors and using them on the strip, the result would be OK, its way more complicated trying to get one color for the whole screen…

I tried designing algorithms based on the science of colors and our eyes, like how much each color adds to the overall perception of brightness is approx 60% G 25% R and 15% B, this gets you are good result, but when I calculate it and display it the color seems to change (flicker) too much compared to the video, one moment it picks bright white the next it shows blue… at the flick of a switch as the video pans from the sky down to the water… its a gradual thing but the one led flicks over from one color to another… so its not as easy as it seems…

---

<div class="post-metadata">

### Author: ![themindfactory](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/themindfactory/32/8177_2.png) [@themindfactory](https://discourse.processing.org/u/themindfactory)
#### Post date: [February 29, 2020, 2:59am UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086/6 "2020-02-29T02:59:04Z")

</div>

I expect to shine a very bright RGB led (just one) at the wall and playback the results and have it look like I am watching TV 🙂

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [February 29, 2020, 4:42am UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086/7 "2020-02-29T04:42:06Z")

</div>

If you want to reduce flickering and smooth your color transitions, you can save the current color and lerpColor towards the new (flickering) target color. This will reduce the total possible color difference per frame.

Here is a barely modified Video \> Loop example to illustrate the idea. It resizes each frame of the movie into a single pixel, then extracts color and makes it the target. The current color chases the changing target using lerpColor and a transition rate 0-1.0.

```auto
import processing.video.*;

Movie movie;
PImage img;
color target;
color current;
float transition = 0.5;

void setup() {
  size(560, 406);
  background(0);
  movie = new Movie(this, "launch2.mp4");
  movie.loop();
}

void movieEvent(Movie m) {
  m.read();
  img = m.copy();
  img.resize(1,1);
  img.loadPixels();
  target = img.pixels[0];
}

void draw() {
  current = lerpColor(current, target, transition);
  background(current);
}

```

---

<div class="post-metadata">

### Author: ![themindfactory](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/themindfactory/32/8177_2.png) [@themindfactory](https://discourse.processing.org/u/themindfactory)
#### Post date: [February 29, 2020, 8:15pm UTC](https://discourse.processing.org/t/convert-video-to-1-pixel-per-frame/18086/8 "2020-02-29T20:15:59Z")

</div>

WOW thanks so much, looks like just the conversion to 1x1 resize does the trick, I commented out the lerpColor() and displayed the video as it played with an overlaid patch of color and it behaves nicely!

Processing is very very useful!

Thanks!
