Delphi OpenH264 decode

983 Views Asked by At

i'm using the cisco OpenH264 codec in coding and decoding process , the coding stage works very well and i can read my encoded H.264 file correctly , the issue is with my decoding process and mainly the conversion from I420 to ARGB , please can any one helps to fix this .

Here's my Decoding function ( from the OpenH264 wrapper 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;
}

and here's my Delphi implementation :

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;

So many thanks.

2

There are 2 best solutions below

2
On BEST ANSWER

So many thanks , i fixed the issue ; the problem was just i set :

Image.Picture.Bitmap.PixelFormat := pf24bit;

But the correct PixelFormat is the pf32bit

1
On

The stride size (int dst_stride_frame), you give to H264Decoder_decode() has to be width * 3.

That is, because you want to convert into a 24-Bit RGB image, where one pixel takes 3 Bytes (24bits / 8).

With width * 2 your converted image will only contain 2/3 of the data, resulting in your image. width * 4 would come into effect, if you want to convert to 32-Bit RGB.