0

I'm using MediaCodec to decode the video and using sws_scale(from ffmpeg) to rescale it.I can deal with one special color format,eg. YUV420P, and rescale it to destination size. But I have to do some preparing work, such as getting the linesize and memcpy the output buffer to three plain slices(data[0],data[1],data[2]).And the decoder output color format varies on different devices.If I get the colorformat,is there a method in ffmpeg to rescale it automatically without special dealing(Of course, the color format should be supported by ffmpeg)?

Frank Bush
  • 111
  • 3
  • 11

2 Answers2

1

There's no function in swscale/libavutil for directly taking an OMX (MediaCodec) color format, you need to map the formats manually. But you don't need to memcpy the output buffer into three separate buffer, you can just set the three data pointers data[0], data[1] and data[2] to point into the output buffer from MediaCodec (the same point in the buffer that you otherwise would have memcpied from).

The normal color formats (such as YUV420P and NV12) should work just fine, you just need to set up a mapping between the format constants. But some MediaCodec decoders (qualcomm ones in particular) often use a proprietary, tiled format that requires much more effort to unscramble, and swscale doesn't support that one directly, you need to unscramble it yourself.

mstorsjo
  • 12,983
  • 2
  • 39
  • 62
  • Thanks,mstorsjo.Yes,I know I need to map the MediaCodec color format with pix_fmt in ffmpeg.Besides that, I have to set the data pointers and deal with the dest data pointers.If this can be done automatically by passing the pix_fmt, it will be very wonderful.Because there are too many formats to deal with. I find the linesize which the av_image_alloc passing back may have some help,but the size of other orietation(relation with hight) also veries from different pix_fmt. Do you have any suggestion? – Frank Bush Oct 17 '14 at 07:32
0

This is just an intuitive suggestion based on my experience with OMX on Raspberry Pi, but, you could check out if the Stagefright library provides any OMX like C/C++ interfaces to the NDK - in that case, if there is not only a decoder component but also a resize component (Raspberry Pi has sucha a component), then you could make an OMX pipeline and then the components can automatically negotiate the formats, but this is just an assumption, I've never looked that deep into Stagefright myself and I'm aware that it is meant to be used from the Java level through the MediaCodec and other classes, but still you can have a look. If Stagefright has such API I can provide some OMX wrapper code that eases the use of the components that I made for Raspberry Pi, since building OMX code from scratch is quite a lot of work.

EDIT

I did some more googling on this since it seemed interresting and found an NDK media sample - well it seems that the Broadcom implementation of OMX differs a lot, so still most stuff would be need to built from scracth. Can you explain a little more why you need to do this? If the goal was only to display the decoded stream you could have set the preview surface at Java level, so I assume the purpouse of decoding is some other.

Community
  • 1
  • 1
Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71
  • Thanks,Rudolfs.I before considered using Stagefright,but I just don't know how to start my work.Firstly it needs to build the Stagefright code under android platform.Secondly it needs to study the APIs.And what we want to do is the work for Android dev team.Do you agree it?So I give up the thought. – Frank Bush Oct 17 '14 at 07:49
  • Can you explain a bit more why you need the rescaling? What do you plan to do with the decoded video? – Rudolfs Bundulis Oct 17 '14 at 07:52
  • Because I want to transcode the video file with smaller bitrate and size to upload.So I use MediaCodec,but it can't change the size directly. – Frank Bush Oct 17 '14 at 11:15
  • Thanks for the explanation. I've seen some Java based transcoding exmaples (http://stackoverflow.com/questions/15950610/video-compression-on-android-using-new-mediacodec-library, http://stackoverflow.com/questions/15215636/re-encoding-h-264-content-with-a-different-bit-rate-using-android-mediacodec), but that helps only for bitrate. Another option is to provide a precompiled FFmpeg binary (but then again, license issues with x264) and call that to do the transcoding at file level. Are you targeting H.264? – Rudolfs Bundulis Oct 17 '14 at 11:32