We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm working on an application that plays multiple HD movies, and it's pretty slow and janky all on the main thread.
I have found a few blog posts about using threads with Processing, but can't find in the documentation where they're described. Google shows a few dead links going to a github wiki?
Does anybody know the canonical location of the documentation for using threads with processing?
Or have any suggestions of how to use threads to speed up the loading and playback multiple HD movies?
Answers
Threads are an advanced Java subject. Since Processing is a Java framework, threads work alright on it too.
AFAIK, processing.video.Movie already runs in a separate Thread.
Notably, each movieEvent() callback happens in a
new
Thread as well.I don't see how more threads would solve your problem.
Playing a bunch of videos at the same time is painfully slow in any situation!
You should stop() or pause() Movie instances when they're not needed!
Take a look at this recent forum question for some examples: (*)
http://forum.processing.org/two/discussion/7852/problem-with-toggling-between-multiple-videos-on-processing-2-2-1
Admittedly my Java is poor, but I don't see anywhere here that shows the movie running in its own thread https://github.com/processing/processing-video/blob/master/src/processing/video/Movie.java
Also doesn't seem that movieEvent runs in its own thread there either.
I can play several (at least 4) HD movies in Quicktime with all of them playing smoothly, so it's possible on my hardware. Just have to figure out how to do it through Processing!
We can make a little test w/
println(Thread.currentThread());
:http://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#currentThread--
If we paste the statement above in setup() or draw(), we're gonna see:
Thread[Animation Thread,5,main]
.While inside movieEvent(), something like:
Thread[Thread-110,5,main]
.We also can see inside
protected void initGStreamer(PApplet parent, String filename) {}
method that it instantiates a buncha imported classes. Who knows which Thread objects happen to be created by them? :-??I dunno which is the secret of those media players either! 8-}
"processing.video." library is a wrapper for "org.gstreamer." library.
Besides dealing w/ all that, we still gotta "stamp" those Movie objects on the canvas via image() or set().
Who knows 1 day some1 creates a much more optimized video library for Processing? (:|