Asomaning / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

rotate IplImage then record frame into video file #473

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
   In my app, I want to record video with opencv, like video record function in app named vine, now I'm in trouble of rotate IplImage, after I record frame from camera onPreviewFrame callback, I found video will display with Counterclockwise rotation of 90 degrees, so after search on internet,I try to use transpose followed by filp method to rotate IplImage, then execute record() in FFmpegFrameRecorder, I write a method as follow to rotate before record:

//in Util.class ...
public static IplImage rotateImage(IplImage img) {
    IplImage img_rotate = IplImage.create(img.height(), img.width(), 
            img.depth(), img.nChannels());
    //acctually, I don't know how to use these two methods properly
    opencv_core.cvTranspose(img, img_rotate);
    opencv_core.cvFlip(img_rotate, img_rotate, 1);   //顺时针旋转90度

    return img_rotate;
}

my recrod logic code in camera onPreviewFrame() as follow:
@Override
public void onPreviewFrame(byte[] data, Camera camera) {

//......
long frameTimeStamp = 0l; 
//revalue frameTimeStamp 
//convert byte[] data to savedFrames
lastSavedframe = new SavedFrames(data, frameTimeStamp);
//......

try {
    yuvIplImage.getByteBuffer().put(lastSavedframe.getFrameBytesData());
    videoRecorder.setTimestamp(lastSavedframe.getTimeStamp());

    IplImage rotateImg = Util.rotateImage(yuvIplImage);
    videoRecorder.record(rotateImg);

} catch (Throwable e) {
    Log.e("recorder", "record frame catch exception" + e.toString());
    e.printStackTrace();
}

when I write like this, I always catch exception as follow:

05-22 19:29:36.814: E/recorder(31701): 
exceptionorg.bytedeco.javacv.FrameRecorder$Exception: avcodec_encode_video2() 
error -1: Could not encode video packet.

05-22 19:29:36.814: W/System.err(31701): 
org.bytedeco.javacv.FrameRecorder$Exception: avcodec_encode_video2() error -1: 
Could not encode video packet.
05-22 19:29:36.818: W/System.err(31701):    at 
com.ifeng.newvideo.videorecorder.opencv.NewFFmpegFrameRecorder.record(NewFFmpegF
rameRecorder.java:941)
05-22 19:29:36.818: W/System.err(31701):    at 
com.ifeng.newvideo.videorecorder.opencv.NewFFmpegFrameRecorder.record(NewFFmpegF
rameRecorder.java:804)
05-22 19:29:36.818: W/System.err(31701):    at 
com.ifeng.newvideo.videorecorder.opencv.ActivityFFmpegRecorder$CameraView.onPrev
iewFrame(ActivityFFmpegRecorder.java:1285)
05-22 19:29:36.818: W/System.err(31701):    at 
android.hardware.Camera$EventHandler.handleMessage(Camera.java:820)
05-22 19:29:36.818: W/System.err(31701):    at 
android.os.Handler.dispatchMessage(Handler.java:99)
05-22 19:29:36.818: W/System.err(31701):    at 
android.os.Looper.loop(Looper.java:137)
05-22 19:29:36.818: W/System.err(31701):    at 
android.app.ActivityThread.main(ActivityThread.java:5106)
05-22 19:29:36.818: W/System.err(31701):    at 
java.lang.reflect.Method.invokeNative(Native Method)
05-22 19:29:36.821: W/System.err(31701):    at 
java.lang.reflect.Method.invoke(Method.java:511)
05-22 19:29:36.821: W/System.err(31701):    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
05-22 19:29:36.821: W/System.err(31701):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:588)
05-22 19:29:36.821: W/System.err(31701):    at 
dalvik.system.NativeStart.main(Native Method)

can somebody tell how to use transpose() and filp() in right way ?  thanks.

Original issue reported on code.google.com by jordan...@gmail.com on 22 May 2014 at 11:35

GoogleCodeExporter commented 8 years ago
Make sure the width and height you give are supported by the codec you want to 
use.

And please ask your questions on the mailing list if possible, thank you

Original comment by samuel.a...@gmail.com on 24 May 2014 at 4:43