From fb2206de652e2777b3e0c6621dc3c7d47fc16bdf Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Tue, 12 May 2015 22:28:22 +0900 Subject: [PATCH] * Fix `FFmpegFrameRecorder` not saving the last few frames, especially when encoding with x264 (issue #491) Also fix `NullPointerException` when recording without audio --- CHANGELOG.md | 1 + src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b078573..fdfe7b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Fix `FFmpegFrameRecorder` not saving the last few frames, especially when encoding with x264 ([issue #491](https://code.google.com/p/javacv/issues/detail?id=491)) * Add `FrameConverterTest` and fix a couple of bugs uncovered by it * Make `Frame implements Indexable` for easy and efficient access to image pixels * Fix `AbstractMethodError` thrown from `OpenCVFrameConverter` on some versions of the JDK ([issue #143](https://github.com/bytedeco/javacv/issues/143)) diff --git a/src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java b/src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java index 639fdbe8..099dcab5 100644 --- a/src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java +++ b/src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java @@ -192,11 +192,11 @@ public void releaseUnsafe() throws Exception { av_free(audio_outbuf); audio_outbuf = null; } - if (video_st.metadata() != null) { + if (video_st != null && video_st.metadata() != null) { av_dict_free(video_st.metadata()); video_st.metadata(null); } - if (audio_st.metadata() != null) { + if (audio_st != null && audio_st.metadata() != null) { av_dict_free(audio_st.metadata()); audio_st.metadata(null); } @@ -794,7 +794,7 @@ public boolean recordImage(int width, int height, int depth, int channels, int s } } } - return (video_pkt.flags() & AV_PKT_FLAG_KEY) == 1; + return image != null ? (video_pkt.flags() & AV_PKT_FLAG_KEY) != 0 : got_video_packet[0] != 0; } public boolean recordSamples(Buffer ... samples) throws Exception {