Android使用libavcodec为IDGB编码h264

时间:2013-12-12 07:02:28

标签: android ffmpeg h.264 libavcodec argb

我有一个缓冲区内容流,实际上包含480x800大小的ARGB图像[大小为480 * 800 * 4的字节数组]。我想在指定的fps(12)下将大约10,000个相似图像编码成h.264流。 this显示了如何将图像编码为编码视频,但需要输入为yuv420。

现在我有ARGB图像,我想编码成CODEC_ID_H264  How to convert RGB from YUV420p for ffmpeg encoder?显示如何为rgb24执行此操作,但如何为rgb32执行此操作,这意味着ARGB图像数据

我如何使用libavcodec?

编辑:我发现How to convert RGB from YUV420p for ffmpeg encoder? 但我不明白。

从第1个链接开始,我知道AVFrame结构包含数据[0],数据1,数据[2],其中填充了Y,U& V值。

在第二个链接中,他们展示了如何使用sws_scale将RGB24转换为YUV420

SwsContext * ctx = sws_getContext(imgWidth, imgHeight,
                              AV_PIX_FMT_RGB24, imgWidth, imgHeight,
                              AV_PIX_FMT_YUV420P, 0, 0, 0, 0);
uint8_t * inData[1] = { rgb24Data }; // RGB24 have one plane
int inLinesize[1] = { 3*imgWidth }; // RGB stride
sws_scale(ctx, inData, inLinesize, 0, imgHeight, dst_picture.data, dst_picture.linesize)

这里我假设rgb24Data是包含RGB24图像字节的缓冲区。

那么我如何将这个信息用于ARGB,这是32位?我是否需要手动剥离Alpha通道或任何其他工作?

谢谢

1 个答案:

答案 0 :(得分:1)

只需将像素格式和行间距从RGB24切换到ARGB

即可
SwsContext * ctx = sws_getContext(imgWidth, imgHeight,
                              AV_PIX_FMT_ARGB, imgWidth, imgHeight,
                              AV_PIX_FMT_YUV420P, 0, 0, 0, 0);
uint8_t * inData[1] = { rgb24Data }; // RGB24 have one plane
int inLinesize[1] = { 4*imgWidth }; // RGB stride
sws_scale(ctx, inData, inLinesize, 0, imgHeight, dst_picture.data, dst_picture.linesize)