bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.44k stars 1.57k forks source link

FFmpegFrameRecorder java.nio.BufferOverflowException #784

Open anonym24 opened 6 years ago

anonym24 commented 6 years ago

java.nio.BufferOverflowException

Sometimes this error happens at this line ((ByteBuffer)yuvImage.image[0].position(0)).put(data);

https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java#L552

compile('org.bytedeco:javacv-platform:1.3.3') { exclude group: 'org.bytedeco.javacpp-presets' } 
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-arm
saudet commented 6 years ago

We'll need to reallocate the image buffer then.

anonym24 commented 6 years ago

I found out that this happens when I first installs app and trying to record for the first time when I try second time, it works ok

anonym24 commented 6 years ago
try {
  ((ByteBuffer) frame.image[0].position(0)).put(data);
} catch (BufferOverflowException e) {
  Log.i(TAG, "recordError BufferOverflowException " + e);
  frame = new Frame(previewWidth, previewHeight, frameDepth, frameChannels);
  frameToRecord = new FrameToRecord(timestamp, frame);
  ((ByteBuffer) frame.image[0].position(0)).put(data);
}

this didn't help, error on the second try in try,,,catch block