I try out different video playback mechanism in the Processing to compare their performance. The digital video is the one I used in the last post. It is the trailer of the film Hugo. The details are: 1280 x 692 H.264 AAC, bitrate 2,093.
The computer I am using is iMac 3.06 GHz Intel Core 2 Duo, 4 GB RAM, ATI Radeon HD 4670 256 MB graphic card. Processing is the latest 1.5.1 version.
For the video playback classes, I tested the default QuickTime Video library, a FasterMovie class, the GSVideo library, and the JMCVideo library with JavaFX 1.2 SDK.
To render the video, I start with the standard image() function, and proceed to test with various OpenGL texturing methods, including the GLGraphics library.
Again, I sample the CPU and Memory usage with the Activity Monitor from the Mac OSX utilities, in an interval of 30 seconds. The results are the average of 5 samples.
Performance with 2D image function
CPU (%) | Memory (Mb) | |
QuickTime | 175 | 221 |
FasterMovie | 137 | 275 |
GSVideo | 151 | 118 |
JMCVideo | 147 | 87 |
The OpenGL and QuickTime video libraries have problem working together. The program stops at the size() statement. I have to either put the first video related command before the size() or a dummy line
println(Capture.list()); size(1280, 692, OPENGL); |
The second batch of tests use the standard OpenGL vertex and texture functions.
Performance with OpenGL texture and vertex functions
CPU (%) | Memory (Mb) | |
QuickTime | 158 | 430 |
FasterMovie | 143 | 610 |
GSVideo | 147 | 315 |
JMCVideo | 142 | 397 |
The third batch of tests involve custom arrangement in OpenGL. Both GSVideo and JMCVideo come with their own functions to write directly to OpenGL texture. For the FasterMovie test, I combine it with the pixel buffer object I have shown in my previous post.
Performance with custom OpenGL texture method
CPU (%) | Memory (Mb) | |
FasterMovie+PBO | 69 | 275 |
GSVideo+GLGraphics | 58 | 120 |
JMCVideo+OpenGL | 57 | 91 |
Sample code for GSVideo and GLGraphics (from codeanticode)
import processing.opengl.*; import codeanticode.glgraphics.*; import codeanticode.gsvideo.*; GSMovie mov; GLTexture tex; void setup() { size(1280, 692, GLConstants.GLGRAPHICS); background(0); mov = new GSMovie(this, "Hugo.mp4"); tex = new GLTexture(this); mov.setPixelDest(tex); mov.loop(); } void draw() { if (tex.putPixelsIntoTexture()) { image(tex, 0, 0); } } void movieEvent(GSMovie _m) { _m.read(); } |
Sample code for JMCVideo (from Angus Forbes)
import jmcvideo.*; import processing.opengl.*; import javax.media.opengl.*; JMCMovieGL mov; PGraphicsOpenGL pgl; void setup() { size(1280, 692, OPENGL); background(0); mov = new JMCMovieGL(this, "Hugo.mp4", ARGB); mov.loop(); pgl = (PGraphicsOpenGL) g; GL gl = pgl.beginGL(); gl.glViewport(0, 0, width, height); pgl.endGL(); } void draw() { GL gl = pgl.beginGL(); mov.image(gl, 0, 0, width, height); pgl.endGL(); } |