We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone, I'm new to Processing and I've been working on this video-art / installation project for my graduation.
My question is: How can I set a random video to be played next?
I managed to get the videos playing, but I can't set another random video to follow. My intention is to have a sequence of videos (maybe 10 or more) that will play in a shuffled order. I have looked around this and some other forums but couldn't find a specific answer. Hope you guys can help me out. Thanks!
ps. if something doesn't make sense in my code please tell me :)
import processing.video.*;
import processing.sound.*;
AudioIn input;
Amplitude analyzer;
int scale=4;
Movie mov1, mov2;
Capture cam;
int n = 5; //total number of videos
float vidN = random(1, n+1);
int x = int (vidN);
float vidN2 = random(1, n+1);
int x2 = int (vidN2);
void setup() {
//frameRate (30);
size(1280, 720);
colorMode (HSB);
//fullScreen();
//background(0);
mov1 = new Movie(this, nf(x, 2)+".mp4");
mov1.loop();
mov1.volume(100);
mov2 = new Movie(this, nf(x2, 2)+".mp4");
mov2.loop();
mov2.volume(00);
cam = new Capture(this, width, height);
cam.start();
blendMode(DIFFERENCE);
imageMode(CENTER);
//Create an Audio input and grab the 1st channel
input = new AudioIn(this, 0);
// start the Audio Input
input.start();
// create a new Amplitude analyzer
analyzer = new Amplitude(this);
// Patch the input to an volume analyzer
analyzer.input(input);
}
void movieEvent(Movie m) {
if (m == mov1) {
mov1.read();
} else if (m == mov2) {
mov2.read();
}
}
void draw() {
float vol = analyzer.analyze();
noStroke ();
tint (255, 80);
if (cam.available()) {
cam.read();
image(cam, width/2, height/2, width, height); // Draw the webcam cam onto the screen
vol = vol*scale;
tint (255, 100-vol*100);
image(mov1, width/2, height/2, width, height);
tint (255, 100-vol*100);
image(mov2, width/2, height/2, width, height);
}
}
Answers
In the code above, you are playing a camera and a video1 and a video2.
You need to consider you have:
and
These two functions manage the movie and webcam resp. Now, notice above that you have
In this function you are managing all your images (never mind they all overlap and only the last one is shown). What is important to keep in mind is that you show the movie's images only when a new image is available from your webcam device.
Consider these two links for playing multiple videos:
https://forum.processing.org/two/discussion/8109/prepare-a-second-video-to-play-without-slowing-down-the-first-video#latest
https://forum.processing.org/two/discussion/comment/85389/#Comment_85389
I hope this helps,
Kf
Hi there, kfrajer!
Yes, I want 2 videos + the webcam to be playing at the same time, because I like the blending effect. I managed to set 2 random videos at the start, but the point is to have a shuffled sequence of videos, so that it's more varied and doesn't get repetitive.
Anyway, I think what you pointed out was related to performance, am I right? So I disabled this:
and included this:
Apparently playback is smoother now. Thank you!
I will have a look at the links you provided, and hope someone's figured out this - apparently simple - task :) Cheers!
I didn't run your code, but yes... the tint effect will provide a good effect thinking about it. About performance, yes... it happens that you are only refreshing the sketch only when the webcam is available. You should treat them independently as you are doing now.
Kf
kfrajer, I looked at the links you posted, and I got some results by adapting the code by GoToLoop :) https://forum.processing.org/two/discussion/8109/prepare-a-second-video-to-play-without-slowing-down-the-first-video#latest ... As I would like videos to take up the whole screen, as well as to maintain blendMode() and tint(), I used image() instead of set():
Oh, just for the record. At this line
I get a "Dead code" warning. It doesn't stop the sketch from running though :) Is it a problem? I'm also worried about performance in the long run, since I'll leave the installation running for a couple hours. Do you have any tips on that? :B
Thanks again! :)
...
I tried to clean up the code, removing parts that aren't essential. But as I said, I'm new to programming, so if anyone is able to further improve it, either on performance or code logic itself, it'd be greatly appreciated. Comments in the code would be nice as well, explaining what does what ;) Thanks again to kfrajer and GoToLoop.
https://forum.Processing.org/two/discussion/14990/movie-begin-and-end-events#Item_1
Hey GoToLoop! Thanks for showing up! Apparently, the link you posted guides to a simpler way of indicating the end of a video stream. Is it so? - I tried and striped down your new code, removing stuff I don't need (code below). ~ Maybe I'm being too ambitious to do this in Processing, but how can I merge both codes to get a random sequence of videos (from a set) + webcam playing simultaneously?
REFERENCE: https://forum.processing.org/two/discussion/4333/how-can-i-get-multiple-videos-to-play-one-after-another-and-triggered-by-specific-keys
I modify the previous code and provide a demo that should do what you need.
The code does the following:
s
ord
key. When it finishes playing a movie. It comes to a stop showing the last frame. You can press the key again to start playing the movie again.a s d
to reset and play a movie in their respective section.In your case, you want the behavior displayed in the first section: Consecutive and continuous playing of random movies.
Kf