Hey everyone.
I’m trying to use Processing for analyzing movement manually in videos. Unfortunately the video library doesn’t appear to have frame-stepping functionality built in, and the suggested example of calculating the frame time and seeking (or jumping) to it often skips frames, which doesn’t work for what I need.
I took some time to learn a little about the GStreamer backend and it seemed that I should be able to put the following in somewhere with a Listener and get it to framestep.
myMovie.playbin.sendEvent(new StepEvent(Format.BUFFERS, 1, 1, true, false));
However I find that in practice it comes up with a lot of unexpected (by me) behavior. In the following example I illustrate a couple of things.
import processing.core.*;
import java.util.EnumSet;
import org.freedesktop.gstreamer.event.SeekFlags;
import org.freedesktop.gstreamer.event.SeekType;
import processing.video.*;
import org.freedesktop.gstreamer.*;
import org.freedesktop.gstreamer.event.*;
Movie myMovie;
float zoom;
void setup() {
size(800,600);
myMovie = new Movie(this, "Slow motion video of vertical jump with synchronized vertical force data.mp4");
myMovie.play();
myMovie.pause();
myMovie.read();
zoom = width*1.0 / myMovie.width;
noLoop();
}
>void draw() {
scale(zoom);
myMovie.play();
myMovie.pause();
myMovie.read();
background (128);
image(myMovie, 0, 0);
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
myMovie.playbin.sendEvent(new StepEvent(Format.BUFFERS, 1, 1, true, false));
redraw();
} else if (keyCode == RIGHT) {
myMovie.playbin.seek(1, Format.TIME, EnumSet.of(SeekFlags.FLUSH, SeekFlags.ACCURATE), SeekType.SET, myMovie.playbin.queryPosition(Format.TIME), SeekType.END, 0);
myMovie.playbin.sendEvent(new StepEvent(Format.BUFFERS, 1, 1, true, false));
redraw();
}
}
}
- If I don´t play-pause before reading after sending the event, no change takes effect. Probably not surprising, but I´m wondering if there is a way around it.
- In my example when I click the LEFT arrow, I send the step event without seeking beforehand. In this case it seems to step over about 5-6 frames. Probably something going on her I´m not seeing.
- For the RIGHT arrow I added a seek event to the present time with rate 1. In this case I only step one frame, although sometimes it doesn’t load and I click twice and on the second press I jump forward two frames. What surprises me is that if I click RIGHT, it steps 1 frame, but then if I click LEFT afterwards it steps 6 frames.
My guess is there is a lot about the way the video library uses GStreamer that I am ignoring. I’d like to know if it is going to be possible to find a way to hack exact frame stepping in (and perhaps a hint at where to start), or if I am in way over my head. Any suggestions or pushes in the right direction will be much appreciated.