Ask Your Question

zhaozhixin's profile - activity

2015-11-24 08:06:36 -0500 received badge  Popular Question (source)
2013-07-21 22:20:07 -0500 received badge  Scholar (source)
2013-07-12 00:02:19 -0500 asked a question [Rotate image 90 Degrees] Strange color after using cvTranspose

Hi,

I'm testing the Camera record by using FFmpegFrameRecorder, but the video always in landscape. When I use cvTranspose to rotate image to portrait, the result image have strange color.

Could anybody tell my how to correct this?

Many thanks,

  • Init recorder code:

    if (yuvIplimage == null) {
        yuvIplimage = IplImage.create(imageWidth, imageHeight, IPL_DEPTH_8U, 2);
        yuvIplimage2 = IplImage.create(imageHeight, imageWidth, IPL_DEPTH_8U, 2);
    
    
    Log.i(LOG_TAG, "create yuvIplimage");
    
    } Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link); recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 1); // recorder.setSampleRate(sampleAudioRateInHz); recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC); recorder.setAudioChannels(1); recorder.setAudioBitrate(audioBitrate); recorder.setVideoCodec(avcodec.AV_CODEC_ID_FLV1); // Set in the surface changed method recorder.setFrameRate(frameRate); recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P); recorder.setFormat("flv");
  • OnPreviewFrame function:

public void onPreviewFrame(byte[] data, Camera camera) { /* get video data */ if (yuvIplimage != null && recording) {

            yuvIplimage.getByteBuffer().put(data);

            opencv_core.cvTranspose(yuvIplimage, yuvIplimage2);
            opencv_core.cvFlip(yuvIplimage2, null, 1);

            Log.v(LOG_TAG,"Writing Frame");
            try {
                recorder.setTimestamp(1000 * (System.currentTimeMillis() - startTime));
                recorder.record(yuvIplimage2);

            } catch (FFmpegFrameRecorder.Exception e) {
                Log.v(LOG_TAG,e.getMessage());
                e.printStackTrace();
            }
        }
    }