Ask Your Question

lansher1985's profile - activity

2018-06-02 05:48:02 -0600 received badge  Notable Question (source)
2016-04-16 00:19:52 -0600 received badge  Popular Question (source)
2014-03-13 04:13:33 -0600 asked a question Android: record video with FFmpegFrameRecorder in onPreviewFrame not working

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;
                    }
                buffer.put(lastSavedframe.getFrameBytesData());
                videoRecorder.setTimestamp(lastSavedframe.getTimeStamp());
                videoRecorder.record(lplImage);
        }
        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)

Thanks!