Inverted Image from H264 Encoder in DirectShow

Trying to build a DirectShow H264 encoder using the Codec SDK V9.0. It basically works but when I decode the image it shows as inverted. I’m feeding it an RGB32 stream (using NV_ENC_BUFFER_FORMAT_ARGB). I’ve had inverted image issues in the past with DirectShow and RGB. Is there an easy fix for this that does not involve a line by line memcpy of the image? I could not find any obvious parameter settings. I tried using a negative height which often fixes this in DirectShow but the NVIDIA functions didn’t seem to like that idea.

Hi,

The NVENCODEAPI doesn’t support inversion of the images. You need to do it outside the encode API and that can be done using Cuda kernels.

Thanks,
Ryan Park

Thanks for your reply,
I wrote a simple subroutine to create an inverted RGB buffer and that works - I was hoping there was a way to do it with less overhead but apparently not.
I also assume that there is no way to provide RGB24 data to the encoder without also converting it to RGB32, right?

////////////////////////////////////////////////////////////////////////
// Invert RGB buffer (works for RGB32 or RGB24)
// Caller must provide destination buffer
// Width and Height are Pixels.
// Stride is BYTES (typically w3 for RGB24 or w4 for RGB32)
// but it may also be rounded up to some hardware friendly boundary if DirectShow or D3D are involved
////////////////////////////////////////////////////////////////////////
void InvertRGB24(byte * dest, byte * src, int w, int h, int stride)
{
// set up the row iterator (allowing for possible inversion)
int drow = h - 1; // starting dest row

// for each destination row
int y;
for (y = 0; y < h; y++, drow--)	// y is vertical row
{
	// compute the source row.
	int temp;
	temp = y * stride;	
	DWORD * srp = (DWORD *)(src + temp);	// srp is now base of current source row
	temp = drow * stride;
	DWORD * drp = (DWORD *)(dest + temp);	// drp is now base of current dest row
	memcpy(drp, srp, stride);
}

}

Hi,

Yes that’s correct, That’s right. NVENCODEPAI accepts RGB32. Please refer to the comments in encode API header(nvEncodeAPI.h) located in the SDK package besides “enum NV_ENC_BUFFER_FORMAT”

Thanks,
Ryan Park