Skip to content

Commit

Permalink
Prepared Campera Input method
Browse files Browse the repository at this point in the history
  • Loading branch information
olir committed Mar 16, 2018
1 parent bf56ba5 commit 5f2139b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/main/java/de/screenflow/frankenstein/MovieProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ public void init(ProcessingListener l) {
currentPos = 1;
}

public void processStreamFrame(ProcessingListener l) {
currentPos = 1;

frame = configuration.getSource().getFrame();
if (frame != null && !frame.empty()) {
Mat newFrame = frame;
for (VideoFilter filter : filters) {
// System.out.println("MovieProcessor processStreamFrame " + filter.getClass().getName());
newFrame = filter.process(newFrame, 1);
}
if (l != null)
l.nextFrameProcessed(newFrame, currentPos);

movie_w = newFrame.cols();
movie_h = newFrame.rows();
} else {
if (l != null)
l.prematureEnd(1);
return;
}
}

public boolean process(ProcessingListener l) {
try {
System.out.print("doOutput=" + configuration.doOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public interface ProcessingListener {
void videoStarted(int frames, double fps);
void nextFrameLoaded(Mat frame, int frameId);
void nextFrameLoaded(Mat frame);
void nextFrameProcessed(Mat frame, int frameId);
void seekDone(int frameId);
void seeking(int i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ public void taskError(String errorMessage) {
}

@Override
public void nextFrameLoaded(Mat frame, int frameId) {
public void nextFrameLoaded(Mat frame) {
processor.processStreamFrame(this);
}

@Override
Expand Down Expand Up @@ -738,6 +739,7 @@ public void prematureEnd(int realFrameCount) {
seekingErrorHandling = true;
seekPos = -1;
System.err.println("Warning: Premature end of source at frame " + realFrameCount);
new Error().printStackTrace();
Platform.runLater(() -> {
this.slider.setValue(realFrameCount);
adjustVideoLengthDisplay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package de.screenflow.frankenstein.vf.input;

import java.util.Timer;
import java.util.TimerTask;

import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.Videoio;
Expand All @@ -31,13 +34,15 @@ public class CameraInput implements VideoSource {
private int width;
private int height;

private Timer timer = null;

public CameraInput(int id) {
this.id = id;
}

@Override
public int getFrames() {
return -1;
return 1;
}

@Override
Expand All @@ -56,13 +61,25 @@ public void open(ProcessingListener l) {
currentFrame = retrieve(currentFrame, l);
width = (int) movie.get(Videoio.CAP_PROP_FRAME_WIDTH);
height = (int) movie.get(Videoio.CAP_PROP_FRAME_HEIGHT);

timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
currentFrame = retrieve(currentFrame, l);
l.nextFrameLoaded(currentFrame);
}
}, 0, (int)(1000.0/fps));
}

@Override
public void close() {
if (movie != null)
movie.release();
movie = null;
if (timer != null)
timer.cancel();
timer = null;
}

@Override
Expand Down

0 comments on commit 5f2139b

Please sign in to comment.