Skip to content

Commit

Permalink
use "re" option add global real time grab
Browse files Browse the repository at this point in the history
like ffmpeg
  • Loading branch information
wangxi3 committed Jun 4, 2021
1 parent 9b6e4ce commit 6838c85
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
import java.io.InputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.DoublePointer;
Expand Down Expand Up @@ -389,6 +386,7 @@ static class SeekCallback extends Seek_Pointer_long_int {
private boolean frameGrabbed;
private Frame frame;
private long startTime;
private boolean globalAtFrameRate;
private volatile boolean started = false;

public boolean isCloseInputStream() {
Expand Down Expand Up @@ -850,6 +848,11 @@ public void startUnsafe() throws Exception {
startUnsafe(true);
}
public synchronized void startUnsafe(boolean findStreamInfo) throws Exception {
String reValue = this.getOption("re");
if (Objects.equals(reValue,"true")) {
this.globalAtFrameRate = true;
}

try (PointerScope scope = new PointerScope()) {

if (oc != null && !oc.isNull()) {
Expand Down Expand Up @@ -1052,7 +1055,7 @@ public synchronized void startUnsafe(boolean findStreamInfo) throws Exception {
samples_buf = new Buffer[] { null };
}
started = true;

}
}

Expand Down Expand Up @@ -1454,7 +1457,7 @@ private synchronized Frame _grabFrame(boolean doAudio, boolean doVideo, boolean
}

// Simulate the "-re" parameter in ffmpeg
if (atFrameRate) {
if (atFrameRate||globalAtFrameRate) {
if (startTime == 0) {
startTime = System.currentTimeMillis();
} else {
Expand Down

0 comments on commit 6838c85

Please sign in to comment.