From 53d19bed18731be9e655de7ac96c20753f0f9739 Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Mon, 16 Jan 2023 19:54:08 +0900 Subject: [PATCH] * Fix `FFmpegFrameGrabber.grab()` not returning audio frames buffered by the codec (issue #1971) * Upgrade dependencies for OpenCV 4.7.0, librealsense2 2.53.1, Leptonica 1.83.0, Tesseract 5.3.0 --- CHANGELOG.md | 3 +++ platform/pom.xml | 8 +++---- pom.xml | 8 +++---- .../bytedeco/javacv/FFmpegFrameGrabber.java | 22 ++++++++++++++----- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 911c26af..166f3972 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ + * Fix `FFmpegFrameGrabber.grab()` not returning audio frames buffered by the codec ([issue #1971](https://github.com/bytedeco/javacv/issues/1971)) + * Upgrade dependencies for OpenCV 4.7.0, librealsense2 2.53.1, Leptonica 1.83.0, Tesseract 5.3.0 + ### November 2, 2022 version 1.5.8 * Override `FFmpegFrameGrabber.getVideoCodecName()/getAudioCodecName()` to return names of opened codecs ([pull #1901](https://github.com/bytedeco/javacv/pull/1901)) * Add `FrameGrabber.videoDisposition/audioDisposition` properties to select streams by disposition ([pull #1879](https://github.com/bytedeco/javacv/pull/1879)) diff --git a/platform/pom.xml b/platform/pom.xml index 754c3381..b04137ba 100644 --- a/platform/pom.xml +++ b/platform/pom.xml @@ -33,7 +33,7 @@ org.bytedeco opencv-platform - 4.6.0-${javacpp.version} + 4.7.0-${javacpp.version} org.bytedeco @@ -68,7 +68,7 @@ org.bytedeco librealsense2-platform - 2.50.0-${javacpp.version} + 2.53.1-${javacpp.version} org.bytedeco @@ -88,12 +88,12 @@ org.bytedeco leptonica-platform - 1.82.0-${javacpp.version} + 1.83.0-${javacpp.version} org.bytedeco tesseract-platform - 5.2.0-${javacpp.version} + 5.3.0-${javacpp.version} diff --git a/pom.xml b/pom.xml index 8fa8d167..d3a57d19 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ org.bytedeco opencv - 4.6.0-${javacpp.version} + 4.7.0-${javacpp.version} org.bytedeco @@ -110,7 +110,7 @@ org.bytedeco librealsense2 - 2.50.0-${javacpp.version} + 2.53.1-${javacpp.version} org.bytedeco @@ -130,12 +130,12 @@ org.bytedeco leptonica - 1.82.0-${javacpp.version} + 1.83.0-${javacpp.version} org.bytedeco tesseract - 5.2.0-${javacpp.version} + 5.3.0-${javacpp.version} diff --git a/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java b/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java index 35d0c1ac..977a5715 100644 --- a/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java +++ b/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java @@ -1429,9 +1429,9 @@ public synchronized Frame grabFrame(boolean doAudio, boolean doVideo, boolean do return null; } } - if (doVideo && video_st != null) { - // The video codec may have buffered some frames - pkt.stream_index(video_st.index()); + if ((doVideo && video_st != null) || (doAudio && audio_st != null)) { + // The video or audio codec may have buffered some frames + pkt.stream_index(doVideo && video_st != null ? video_st.index() : audio_st.index()); pkt.flags(AV_PKT_FLAG_KEY); pkt.data(null); pkt.size(0); @@ -1466,6 +1466,12 @@ public synchronized Frame grabFrame(boolean doAudio, boolean doVideo, boolean do ret = avcodec_receive_frame(video_c, picture); if (ret == AVERROR_EAGAIN() || ret == AVERROR_EOF()) { if (pkt.data() == null && pkt.size() == 0) { + pkt.stream_index(-1); + doVideo = false; + if (doAudio) { + readPacket = false; + break; + } return null; } else { readPacket = true; @@ -1511,8 +1517,14 @@ public synchronized Frame grabFrame(boolean doAudio, boolean doVideo, boolean do while (!done) { ret = avcodec_receive_frame(audio_c, samples_frame); if (ret == AVERROR_EAGAIN() || ret == AVERROR_EOF()) { - readPacket = true; - break; + if (pkt.data() == null && pkt.size() == 0) { + pkt.stream_index(-1); + doAudio = false; + return null; + } else { + readPacket = true; + break; + } } else if (ret < 0) { // Ignore errors to emulate the behavior of the old API // throw new Exception("avcodec_receive_frame() error " + ret + ": Error during audio decoding.");