Android: record video with FFmpegFrameRecorder in onPreviewFrame not working

asked 2014-03-13 04:13:33 -0600

lansher1985 gravatar image

updated 2014-03-13 04:18:58 -0600

berak gravatar image

I have to take video in my application and I use FFmpegFrameRecorder to do that. The video is show correctly in some devices but not on GalaxyS3. I record the video in onPreviewFrame callback function. Like this:

    public void onPreviewFrame(byte[] data, Camera camera) {
    synchronized (mVideoRecordLock) {
        if (recording && lplImage != null) 

            try {
                ByteBuffer buffer;
                buffer = lplImage.getByteBuffer();

                if(buffer.remaining() < lastSavedframe.getFrameBytesData().length){
                    ByteBuffer temp = ByteBuffer.allocate(lastSavedframe.getFrameBytesData().length);

                    buffer = temp;
        lastSavedframe = new SavedFrames(data,frameTimeStamp);

lplImage: IplImage Type lastSavedframe : save frame data in a byte[]. The class file:

   public class SavedFrames implements Parcelable{

       byte[] frameBytesData = null;
       long timeStamp = 0L;
       String cachePath = null;
       int frameSize = 0;


My problem is: with S3, buffer.remaining() < lastSavedframe.getFrameBytesData().length, the video is not recorded correctly, cause I make a preview activity, and the video is green.

I've been struggling with this problem.. Any idea will be appreciated!

Test with galaxy S3, android os 4.0.4. The opencv-core.jar's version is 1.5 (I use a library in my application and the library use opencv-core 1.5)


edit retag flag offensive close merge delete


since this is javacv-specific, i fear you're barking up the wrong tree here ..

berak gravatar imageberak ( 2014-03-13 04:18:14 -0600 )edit