Delphi OpenH264解码

时间:2017-11-30 10:00:39

标签: delphi openh264

我在编码和解码过程中使用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;

非常感谢。

2 个答案:

答案 0 :(得分:0)

您向int dst_stride_frame提供的步幅大小(H264Decoder_decode())必须为width * 3

也就是说,因为您希望转换为24位RGB图像,其中一个像素需要3个字节(24位/ 8)。

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

答案 1 :(得分:0)

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

Image.Picture.Bitmap.PixelFormat := pf24bit;

但是正确的PixelFormat is the pf32bit

相关问题