1

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.

thang2410199
  • 1,932
  • 2
  • 17
  • 18
  • 1
    about the Resizer http://msdn.microsoft.com/en-us/library/windows/desktop/ff819491(v=vs.85).aspx – thang2410199 Nov 07 '14 at 18:58
  • You should be able to use the Video Resizer DSP for this task. You have to create a topology, and build a Topology Node, to which you attach the resizer. Then use that node in your topology. – Anton Angelov Nov 23 '14 at 19:14
  • So you are trying to do video sample cropping, in NV12 format? Here is a similar question: http://stackoverflow.com/questions/21094502/crop-image-from-yv12-or-nv12-byte-array Does it help you? – Anton Angelov Nov 24 '14 at 15:58
  • I did understand the video pixel data format as well as know how to crop them. The problem is setting the output frame size. I got helped and will post an answer soon – thang2410199 Nov 25 '14 at 12:52

0 Answers0