Log in

View Full Version : RGB to yuv420sp


morris_horesh
30th August 2012, 09:18
Hi,
I am trying to encode h264 video in realtime on android. The HW accelerated encoder requires yuv420sp encoded frames. Unfortunately, the input device generates RGB888/RGB565. It takes way too long to make the conversion on the CPU. I need a way to make the conversion on the GPU. I was thinking of a OpenGL shader but I'm not quite sure how to do it. I'm not even sure whether or not it is the best solution.

Help would be appreciated.

Cheers
Morris Horesh

jasonme
30th August 2012, 13:19
Back up a sec, it's possible to call HW video encoder on Android devices using Android APIs or native calls? I mean if I have yuv420 data available on the device, I can call the HW encoder interfaces to encode to a H.264 stream? I wonder how that's done, it would be great if you can point me some materials to read.

Thanks a lot in advance.

morris_horesh
30th August 2012, 15:11
I come here asking questions and I end up giving answers. I wonder if that would cause a Karma endless loop :)

Android has a NDK OMX interface. I am using a rooted device so I can't tell you whether or not you can use it otherwise.

this code may get you started:

// some of these includes may not be required for this sample. I just copied everything
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <media/IMediaPlayerService.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/MediaSource.h>
#include <pthread.h>
#include <media/IOMX.h>
#include <binder/MemoryDealer.h>
#include <OMX_Component.h>


// get omx handle
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder = sm->getService(String16("media.player"));
sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder);
sp<IOMX> iomx = service->getOMX();

List<IOMX::ComponentInfo> list; // list of componentName
List<IOMX::ComponentInfo>::iterator it; // iterator to list through
iomx->listNodes(&list);

// display all supported codecs
for ( it = list.begin(); it != list.end(); ++it)
printf("%s\n",(*it).mName.string());