Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MediaCodec class to decode H.264 streams

I have been asked to display a video stream (the stream is not from HTTP)in android, the stream is raw H.264 which is Recorded and encoded in a PC ,and I get it through WIFI.

When I get the stream, can use the MediaCodec decoder to decode the stream and display it?

like image 999
ljfxmu Avatar asked Nov 04 '22 00:11

ljfxmu


1 Answers

Yes. Configure the MediaCodec as a "video/avc" decoder, and pass an output Surface to the configure() call.

The MediaCodec API is pretty low-level, and there's not a lot of sample code available. It might be easier to use MediaPlayer instead.

Update: There's now a bunch of sample code here. Most of it makes use of Android 4.3 (API 18) features, but if you don't need MediaMuxer or Surface input to MediaCodec it'll work on API 16.

like image 160
fadden Avatar answered Nov 08 '22 16:11

fadden