Skip to content

Commit

Permalink
Fix FFmpegFrameGrabber.grab() not returning buffered frames (issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Aug 2, 2021
1 parent 12cecec commit bf836e0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -1364,22 +1364,26 @@ public synchronized Frame grabFrame(boolean doAudio, boolean doVideo, boolean do
ret = avcodec_send_packet(video_c, pkt);
if (pkt.data() == null && pkt.size() == 0) {
pkt.stream_index(-1);
if (ret < 0) {
return null;
}
}
if (ret < 0) {
throw new Exception("avcodec_send_packet() error " + ret + ": Error sending a video packet for decoding.");
if (ret == AVERROR_EAGAIN() || ret == AVERROR_EOF()) {
// The video codec may have buffered some frames
} else if (ret < 0) {
// Ignore errors to emulate the behavior of the old API
// throw new Exception("avcodec_send_packet() error " + ret + ": Error sending a video packet for decoding.");
}
}

// Did we get a video frame?
got_frame[0] = 0;
while (ret >= 0 && !done) {
while (!done) {
ret = avcodec_receive_frame(video_c, picture);
if (ret == AVERROR_EAGAIN() || ret == AVERROR_EOF()) {
readPacket = true;
break;
if (pkt.data() == null && pkt.size() == 0) {
return null;
} else {
readPacket = true;
break;
}
} else if (ret < 0) {
throw new Exception("avcodec_receive_frame() error " + ret + ": Error during video decoding.");
}
Expand Down Expand Up @@ -1413,7 +1417,7 @@ public synchronized Frame grabFrame(boolean doAudio, boolean doVideo, boolean do

// Did we get an audio frame?
got_frame[0] = 0;
while (ret >= 0 && !done) {
while (!done) {
ret = avcodec_receive_frame(audio_c, samples_frame);
if (ret == AVERROR_EAGAIN() || ret == AVERROR_EOF()) {
readPacket = true;
Expand Down

0 comments on commit bf836e0

Please sign in to comment.