0

I want to get raw data from javacv Frame.

I am using FFmpegFrmaeFilter to rotate Android camera preview. So, I am pulling Frame from the FFmpegFrameFilter and then provides converted byte[] to MediaCodec.

But, while doing so, I am getting wrong data(green picture).I am taking raw data from Frame.Image[0].array();

Is there any other way for fetching raw data from Frame which I can feed to Mediacodec.

Keren Caelen
  • 1,466
  • 3
  • 17
  • 38
Parth
  • 137
  • 8
  • An luck? I too am trying to efficiently get arrays of RGB pixel values out of a Frame, and right now I'm bouncing through a BufferedImage, which is slow. – Benjamin H Nov 01 '18 at 20:10

1 Answers1

1

Green picture most likely means that you pass zeros for chroma components of the image. Android camera usually produces YUV 420 images, where you have width*height array of luminance (Y) followed by U and V, width/2*height/2 each.

FFmpegFrameFilter understands different frame formats, but this depends also on some heuristics that derives the input pixel format from Frame parameters.

MediaCodec can receive frames in flexible YUV 420 format, but it is your responsibility to set up the Image correctly.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Hi Alex, thank you for your response. I am setting FFmpegFrameFilter with Android NV21 image format. But, still I am not getting proper video. When I have used FFmpegFrameRecorder instead of MediaCodec to store video, then the video is proper. I have also tried OpenCV functions for video rotation but in that also same issue is happening and I am not able to find out proper format which is compatible for Android. – Parth May 04 '18 at 05:01
  • As I explained, MediaCodec needs frames wrapped as `CodecCapabilities.COLOR_FormatYUV420Flexible`. You can prepare such wrapper for NV21. – Alex Cohn May 04 '18 at 05:40
  • see https://stackoverflow.com/questions/13703596/mediacodec-and-camera-colorspaces-dont-match – Alex Cohn May 04 '18 at 10:11
  • Hi @Alex, I have tried to get my solution using FFmpegFrameFiter and OpenCV but was not able to do it. Finally, I have rotated YUVImage by converting it to Bitmap and rotating it. Thanks for your help. – Parth May 09 '18 at 09:22
  • … and you feed the Bitmap to MediaCodec? – Alex Cohn May 09 '18 at 09:42
  • Hi @Alex, No.. I am not using MediaCodec, instead I used MJPEG streaming approach and feed rotated bitmap for MJPEG stream. – Parth Jun 08 '18 at 05:06
  • I have to do streaming in LAN so I am also getting low latency using MJPEG. – Parth Jun 08 '18 at 05:06