如何将字节数组(.h264 格式)解码为 android 中的视频?

how to decode the byte array (.h264 format) in to video in android?

在我的应用程序中,我必须将字节数组(即 .h264 格式)解码为视频和来自直播的字节数组。代码如下:

static final int VIDEO_BUF_SIZE = 100000;
static final int FRAME_INFO_SIZE = 16;
byte[] frameInfo = new byte[FRAME_INFO_SIZE];
byte[] videoBuffer = new byte[VIDEO_BUF_SIZE];

File SDFile = android.os.Environment.getExternalStorageDirectory();

File destDir = new File(SDFile.getAbsolutePath() + "/test.h264");


//avRecvFrameData returns the length of the frame and stores it in ret.
int ret = av.avRecvFrameData(avIndex, videoBuffer,
                        VIDEO_BUF_SIZE, frameInfo, FRAME_INFO_SIZE,
                        frameNumber);

fos=new FileOutputStream(destDir,true);
                fos.write(videoBuffer, 0, ret);
                fos.close();

那我现在该怎么办?

感谢大家。

我已经使用 javacv 库对 H.264 直播流进行解码。它相当不错的图书馆。 这是我的 question 及其答案,它可能对您有所帮助。如果您执行与我执行的步骤类似的步骤,它将解码视频,您将能够在设备上播放它。