Can I pauze a movie frame by frame?

edited July 2016 in Library Questions

I am new to this forum but I really hope you can help me out on this one.

I'm trying to blend multiple movies into one. For blending multiple images I already got my code to work quite nicely I think (example below). Now I want to do the same for every frame in multiple movies. I experimented with this somewhat and I can get the movie frames to blend on click. Now I want to blend every frame. So my code is this:

import processing.video.*;

Movie movie1;
Movie movie2;

void setup (){
  size(1280,720);

  movie1 = new Movie(this, "MVI_8256.MOV");
  movie2 = new Movie(this, "MVI_8257.MOV"); 

  movie1.play();
  movie2.play();
}

void movieEvent (Movie m){
  m.pause();
  if (movie1.available() && movie2.available()){
    movie1.read();
    movie2.read();
    blend(); 
    movie1.play();
    movie2.play();
  }
}

void blend(){
  //code to blend
}

void draw (){
  image(movie1, 0, 0, 640, 360);
  image(movie2, 0, 640, 640, 360);
}

To me it looks as though the logic should work but i get a JNA: could not detach thread error. It seems that I can't pause a movie inside the movieEvent().

Hopefully one of you can help me out with some good advice!

result3

Answers

  • edited July 2016

    Indeed you've come across some weird bug. 8-}
    Took a look at pause()'s implementation within "Movie.java':

    https://GitHub.com/processing/processing-video/blob/master/src/processing/video/Movie.java#L459

    public void pause() {
      if (seeking) return;
    
      if (!sinkReady) {
        initSink();
      }
    
      playing = false;
      paused = true;
      playbin.pause();
      playbin.getState();
    }
    

    Callback movieEvent() is synchronized to the Movie object.
    Apparently invoking pause() while under that synchronization can halt the whole program! @-)
    Much probably the unstable statement is this 1: playbin.pause();

    For now I haven't come up w/ some workaround yet. 8-|
    However I've modified the example "Loop.pde" which comes bundled w/ the Video library.

    Notice that even inside draw(), if we invoke pause() while synchronized w/ the Movie object, it eventually halts the sketch as well: :-&

    import processing.video.Movie;
    Movie movie;
    
    void setup() {
      size(640, 360);
      ( movie = new Movie(this, "transit.mov") ).loop();
    }
    
    void draw() {
      set(0, 0, movie);
    
      if (frameCount % 60 == 0)  synchronized (movie) {
        println(frameCount, movie);
        movie.pause();
      }
    }
    
    void mousePressed() {
      movie.play();
    }
    
    void movieEvent(final Movie m) {
      m.read();
    
      //if (frameCount % 60 == 0) {
      //  println(frameCount, m);
      //  m.pause();
      //}
    }
    
  • Answer ✓

    May I suggest instead of pausing the movie, just traverse the movies frame by frame? I have a post done previously where, using provided examples from the video library, I show the concept:

    https://forum.processing.org/two/discussion/comment/72263/#Comment_72263

    In this reference, the sketch shows a movie frame based on the position of the mouse pointer along the width of the sketch. You will need to modify it to suit your needs.

    I hope this helps and you will be able to go around "this" bug.

    Kf

  • Hey GoTo and KF thanks so much for your time and advice. Great to get some good answers so soon! GoTo thanks so much for confirming the bug and KF that looks like that could really work. I will let you guys know how things go!

    Best, Maarten

  • Ok it was actually quite easy to get the movies to do what i want using your post Kfrajer. The first experiment video has just finished uploading. There remains a lot to be done:)

    https://youtu.be/Ix96x9OWfLc

    Thanks again!

  • Great to hear @Marteen! What you are doing is really cool.

    Kf

Sign In or Register to comment.