【问题标题】:Android Encode h264 using libavcodec for ARGBAndroid 使用 libavcodec 为 ARGB 编码 h264
【发布时间】:2013-12-30 11:35:32
【问题描述】:

我有一个缓冲区内容流,它实际上包含 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? 但我不明白。

从第一个链接,我知道 AVFrame 结构包含 data[0],data1,data[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 图像字节的缓冲区。

那么我如何将这些信息用于 32 位的 ARGB?我是否需要手动剥离 Alpha 通道或任何其他解决方法?

谢谢

【问题讨论】:

    标签: android ffmpeg h.264 libavcodec argb


    【解决方案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)
    

    【讨论】:

    • 谢谢,我会试试这个并更新。另外,这意味着如果我的输入是 RGB565,我可以尝试 AV_PIX_FMT_RGB565,sws_scale 是否也支持 RGB565?
    • 在编译期间,我得到了未知类型名称 SwsContext 尽管我包含了 swscale.h
    • 这应该有自己的问题。
    • 结构在纯 C 中不会自动类型。
    • 两者都可以。 RGB 不是平面格式(三个颜色平面是交错的)。所以sws_scale,只使用第一个指针。如果您使用的是 YUV420P 等平面格式,则需要填写其他指针。
    猜你喜欢
    • 2015-03-08
    • 2021-10-26
    • 2018-02-10
    • 2019-01-17
    • 2011-01-25
    • 2011-03-30
    • 2012-11-12
    • 2012-03-31
    • 1970-01-01
    相关资源
    最近更新 更多