Skip to content

Commit

Permalink
* Fix FFmpegFrameGrabber.grab() not returning audio frames buffere…
Browse files Browse the repository at this point in the history
…d by the codec (issue bytedeco#1971)

 * Upgrade dependencies for OpenCV 4.7.0, librealsense2 2.53.1, Leptonica 1.83.0, Tesseract 5.3.0
  • Loading branch information
saudet committed Jan 16, 2023
1 parent 280053c commit 53d19be
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
8 changes: 4 additions & 4 deletions platform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>opencv-platform</artifactId>
<version>4.6.0-${javacpp.version}</version>
<version>4.7.0-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
Expand Down Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>librealsense2-platform</artifactId>
<version>2.50.0-${javacpp.version}</version>
<version>2.53.1-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
Expand All @@ -88,12 +88,12 @@
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>leptonica-platform</artifactId>
<version>1.82.0-${javacpp.version}</version>
<version>1.83.0-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>tesseract-platform</artifactId>
<version>5.2.0-${javacpp.version}</version>
<version>5.3.0-${javacpp.version}</version>
</dependency>

<dependency>
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>opencv</artifactId>
<version>4.6.0-${javacpp.version}</version>
<version>4.7.0-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
Expand Down Expand Up @@ -110,7 +110,7 @@
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>librealsense2</artifactId>
<version>2.50.0-${javacpp.version}</version>
<version>2.53.1-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
Expand All @@ -130,12 +130,12 @@
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>leptonica</artifactId>
<version>1.82.0-${javacpp.version}</version>
<version>1.83.0-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>tesseract</artifactId>
<version>5.2.0-${javacpp.version}</version>
<version>5.3.0-${javacpp.version}</version>
</dependency>

<dependency>
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit 53d19be

Please sign in to comment.