简体   繁体   English

使用libavcodec for ARGB的Android Encode h264

[英]Android Encode h264 using libavcodec for ARGB

I have a stream of buffer content which actually contains 480x800 sized ARGB image[byte array of size 480*800*4]. 我有一个缓冲区内容流,其中实际上包含480x800大小的ARGB图像[大小为480 * 800 * 4的字节数组]。 i want to encode around 10,000s of similar images into a stream of h.264 at specified fps(12). 我想以指定的fps(12)将大约10,000幅相似的图像编码为h.264流。 this shows how to encode images into encoded video,but requires input to be yuv420. 显示了如何将图像编码为编码的视频,但是要求输入的是yuv420。

Now i have ARGB images, i want to encode into CODEC_ID_H264 How to convert RGB from YUV420p for ffmpeg encoder? 现在我有ARGB图像,我想编码为CODEC_ID_H264 如何将YUV420p的RGB转换为ffmpeg编码器? shows how to do it for rgb24, but how to do it for rgb32,meaning ARGB image data 显示了如何针对rgb24进行操作,但针对rgb32进行操作(表示ARGB图像数据)

how do i use libavcodec for this? 我该如何使用libavcodec?

EDIT: i found How to convert RGB from YUV420p for ffmpeg encoder? 编辑:我发现如何从ffmpeg编码器的YUV420p转换RGB? But i don't understand. 但是我不明白。

From the 1st link, i come to know that AVFrame struct contains data[0],data 1 ,data[2] which are filled with Y, U & V values. 从第一个链接,我知道AVFrame结构包含由Y,U和V值填充的data [0],data 1 ,data [2]。

In 2nd link, they showed how to use sws_scale to convert RGB24 to YUV420 as such 在第二个链接中,他们展示了如何使用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)

Here i assume that rgb24Data is the buffer containing RGB24 image bytes. 在这里,我假设rgb24Data是包含RGB24图像字节的缓冲区。

So how i use this information for ARGB, which is 32 bit? 那么,我如何将这些信息用于32位的ARGB? Do i need manually to strip-off the alpha channel or any other work around ? 我是否需要手动剥离Alpha通道或其他解决方法?

Thank you 谢谢

Just switch out the pixelformat and line stride from RGB24 to ARGB 只需将像素格式和行距从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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM