I face a problem when using MFT in WP 8.1 RT: crop video from 480 x 640 to 480 x 480 (remove the left and right area, not stretch them into new ratio). I leaned from Media extension sample and tried to modify the grayscale filter to make it do the work, but failed due to my limitation in C++ and MF programming. Can anyone help me by pointing out the general guide line how to remove the unneeded pixels and change the output video frame size ? I did research and found some tips (not for WP programming) that use Video Processor MFT or Video Resizer DSP. But I have no ideal how to include or use them in a WP project.
Here is my modified code from grayscale filter:
// Convert NV12 image
void TransformImage_NV12(
const D2D_RECT_U &rcDest,
_Inout_updates_(_Inexpressible_(2 * lDestStride * dwHeightInPixels)) BYTE *pDest,
_In_ LONG lDestStride,
_In_reads_(_Inexpressible_(2 * lSrcStride * dwHeightInPixels)) const BYTE *pSrc,
_In_ LONG lSrcStride,
_In_ DWORD dwWidthInPixels,
_In_ DWORD dwHeightInPixels,
_In_ int EffectValue)
{
// NV12 is planar: Y plane, followed by packed U-V plane.
// Y plane
for (DWORD y = 0; y < dwHeightInPixels; y++)
{
if (y < dwHeightInPixels / 2)
CopyMemory(pDest, pSrc, dwWidthInPixels);
pDest += lDestStride;
pSrc += lSrcStride;
}
// U-V plane
// NOTE: The U-V plane has 1/2 the number of lines as the Y plane.
// Lines above the destination rectangle.
DWORD yn = 0;
const DWORD y0 = min(rcDest.bottom, dwHeightInPixels);
// Lines within the destination rectangle.
// 128 = 256/2 => fill this value to memory of U V plane to make grayscale the effect
for (; yn < y0 / 2; yn++)
{
//CopyMemory(pDest, pSrc, rcDest.left);
if (yn < y0 / 4)
CopyMemory(pDest, pSrc, dwWidthInPixels);
//FillMemory(pDest + rcDest.left, rcDest.right - rcDest.left, EffectValue);
//CopyMemory(pDest + rcDest.right, pSrc + rcDest.right, dwWidthInPixels - rcDest.right);
pDest += lDestStride;
pSrc += lSrcStride;
}
}
It products a video with only top haft, with bottom half filled with green.