Display video frames within PGraphics

edited March 2015 in How To...

I'm assuming it's possible to display video in PGraphics object?

I can get code working with an image, but video doesn't display. The video loads as I can hear sound, but no video frame image. Am I doing something wrong?

Tagged:

Answers

  • edited March 2015

    import processing.video.*;

    PGraphics pg;
    PImage img;
    Movie movie;
    
    
    void setup() 
    {
      size(661, 726, P2D);
      pg = createGraphics(661, 726);
    
      img = loadImage("iStock_000015044044Small.jpg");
      movie = new Movie(this, "MVI_2686.MOV");
      movie.loop();
    
    }
    
    void movieEvent(Movie m) {
      m.read();
    }
    
    void draw() 
    {
      pg.beginDraw();
      //pg.image(img, 0, 0, width, height);
      pg.image(movie, 0, 0, width, height);
      pg.endDraw();
      image(pg, 0, 0); 
    }
    
  • edited March 2015

    This adapted example works for me: :-\"

    /**
     * Speediest Movie Play (Modified)
     * by GoToLoop (2014/Dec/04)
     *
     * forum.processing.org/two/discussion/8471/
     * processing-and-4k-video-2160p
     */
    
    import processing.video.Movie;
    Movie mv;
    PGraphics pg;
    boolean isPaused;
    
    void setup() {
      if (mv == null) {
        ( mv = new Movie(this, "MVI_2686.MOV") ).loop();
        while (mv.width == 0)  delay(50);
      }
    
      size(mv.width, mv.height, JAVA2D);
    
      noSmooth();
      noLoop();
      frameRate(30);
      imageMode(CORNER);
    
      pg = createGraphics(width, height, JAVA2D);
      pg.beginDraw();
      pg.noSmooth();
      pg.imageMode(CORNER);
      pg.endDraw();
    }
    
    void draw() {
      pg.background(mv);
      pg.endDraw();
      background(pg);
    }
    
    void mousePressed() {
      if (isPaused ^= true)  mv.pause();
      else                   mv.play();
    }
    
    void movieEvent(Movie m) {
      m.read();
      redraw();
    }
    
  • Yep great your example works fine. I can see there are a few differences to mine notably the JAVA2D setting, the delay(50); and redraw(); Will using JAVA2D effect what platforms the sketch can run on? Thanks for the format code link too!

  • edited March 2015 Answer ✓

    JAVA2D is the default renderer. Using size() w/o specifying a 3rd parameter implies JAVA2D!

  • "Thanks for the format code link too!"
    I suggest to read it attentively and to train on the previous message, which you can edit... :-D

  • So it turns out I just had to supply the renderer type in the createGraphic method. Now I can use P2D or P3D if I choose. Which I do, as I'm hoping to use createGraphics as a buffer and do multiple passes, before outputting and thought this should speed things up?

        import processing.video.*;
        
        PGraphics pg;
        PImage img;
        Movie movie;
        
        
        void setup() 
        {
          
          size(640, 480, P3D);
           
          pg = createGraphics(width, height, P3D);
          
          ///img = loadImage("iStock_000015044044Small.jpg");
          movie = new Movie(this, "MVI_2686.MOV");
          movie.loop();
        }
        
        void movieEvent(Movie m) {
          m.read();
        }
        
        void draw() 
        {
          pg.beginDraw();
          //pg.image(img, 0, 0, width, height);
          pg.image(movie, 0, 0, width, height);
          pg.endDraw();
          image(pg, 0, 0); 
        }
     
Sign In or Register to comment.