Monday, 9 July 2018

How to play raw NAL units in Android MediaCodec

I initially tried How to play raw NAL units in Andoid exoplayer? but I noticed I'm gonna have to do things in low level.

I've found this simple MediaCodec example. As you can see, it's a thread that plays a file on a surface passed to it.

Notice the lines

mExtractor = new MediaExtractor();
mExtractor.setDataSource(filePath);

It looks like that I should create my own MediaExtractor which, instead of extracting the video units from a file, it'll use the h264 NAL units from a buffer I'll provide.

I can then call mExtractor.setDataSource(MediaDataSource dataSource), see MediaDataSource

It has readAt(long position, byte[] buffer, int offset, int size)

This is where it reads the NAL units. However, how should I pass them? I have no information on the structure of the buffer that needs to be read.

Should I pass a byte[] buffer with the NAL units in it, and if so, in which format? What is the offset for? If it's a buffer, shouldn't I just erase the lines that were read and thus have no offset or size?

By the way, the h264 NAL units are streaming ones, they come from RTP packets, not files. I'm gonna get them through C++ and store them on a buffer an try to pass to the mediaExtractor.



from How to play raw NAL units in Android MediaCodec

No comments:

Post a Comment