Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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!

click to hide/show revision 2
retagged

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

berak gravatar image

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!