【问题标题】:Delphi OpenH264 decodeDelphi OpenH264 解码
【发布时间】:2018-05-14 05:08:59
【问题描述】:

我在编码和解码过程中使用的是cisco OpenH264编解码器,编码阶段工作得很好,我可以正确读取我编码的H.264文件,问题在于我的解码过程,主要是从I420到ARGB的转换,请任何人帮助解决这个问题。

这是我的解码函数(来自 OpenH264 包装 DLL):

/*
* [ IN ]   SourceData : the encoded frame(s)
* [ OUT ] pTargetbuffer : the Target buffer 
* [ OUT ] width
* [ OUT ] height
*/
 {

    int iStride[2];
    init();

         ... the decoding routine : pData contains the YUV 

        if (ret != dsErrorFree) {

            return -1;
        }
        if (!m_sBufferInfo.iBufferStatus) {
            return -2;
        }

    LWidth = m_sBufferInfo.UsrData.sSystemBuffer.iWidth;
    LHeight = m_sBufferInfo.UsrData.sSystemBuffer.iHeight;
    *width = LWidth;
    *height = LHeight;

      iStride[0] = m_sBufferInfo.UsrData.sSystemBuffer.iStride[0];
      iStride[1] = m_sBufferInfo.UsrData.sSystemBuffer.iStride[1];



        return 0;
}

这是我的 Delphi 实现:

Image.Picture.Bitmap.PixelFormat := pf24bit;
Image.Picture.Bitmap.Width  := 320;
Image.Picture.Bitmap.Height := 240;
    ...
Result:=H264Decoder_decode(FEncodedBuffer,
                            Image.Picture.Bitmap.ScanLine[Image.Picture.Bitmap.Height-1],
                            EncodedBufferSize,LWidth,LHeight);

 if result=0 then Image.Repaint;

非常感谢。

【问题讨论】:

    标签: delphi openh264


    【解决方案1】:

    你给H264Decoder_decode()的步幅大小(int dst_stride_frame)必须是width * 3

    也就是说,因为要转换成 24-Bit RGB 图像,其中一个像素需要 3 Bytes (24bits / 8)。

    使用width * 2,您转换后的图像将仅包含 2/3 的数据,从而生成您的图像。 width * 4 将生效,如果您想转换为 32 位 RGB。

    【讨论】:

    • 非常感谢,如果我将 width * 2 更改为 width * 3 我也会得到那个 AV。
    【解决方案2】:

    非常感谢,我解决了这个问题;问题只是我设置了:

    Image.Picture.Bitmap.PixelFormat := pf24bit;
    

    但正确的PixelFormat is the pf32bit

    【讨论】:

    • 您能否提供完整的 Delphi 版本的 OpenH264?可以在某个存储库中上传,例如在 GitHub 或其他地方下载吗?我非常需要这个:-)
    • 我正在一个项目示例 Delphi + Android (Java) 中工作,我想接收像 this model 这样的设备屏幕的实时流,但我想在 Delphi 上接收 TImage 之类的你在上面显示的问题。
    猜你喜欢
    • 2017-01-11
    • 2019-10-30
    • 2020-12-25
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多