How to change Media Foundation Transform output fr

2019-08-07 14:30发布

I am writing a transform and want to change the output size of the frame and video. I inspected the sample and found out the order of function calling:

SetInputType
SetOutputType
    GetInputCurrentType
    SetInputType
            UpdateFormatInfo
                GetOutputCurrentType
                SetOutputType
                        GetOutputStreamInfo
                            SetProperties
                                ProcessOutput (THROW NEED INPUT)
                                ProcessInput
                                ProcessOutput
                                ProcessOutput (THROW
                                ....
                                .... repeat until done

In which step do I need to modify the output size and how?

Example: Input a 640x480 video, output 480x480 video, without stretching.

1条回答
Anthone
2楼-- · 2019-08-07 15:35

There are 2 steps to "changing the output size" in your MFT.

1) You need to modify the SetOutputType and GetOutputAvailableType routines:

  • If SetOutputType currently checks the dimensions to validate that they are the same as the input (which you may or may not be doing), then you need to update that.
  • When asked to enumerate the output types you support via GetOutputAvailableType (assuming you support enumerating types), your output media type must have the correct sizes.

2) You need to modify the processing of the samples in ProcessInput/ProcessOutput to actually DO the resizing. Just changing the media types doesn't perform any kind of automatic resizing. How you change dimensions depends on the actual format of the video data (which you did not provide), and the details of how you want to do the resizing. Did you just want to chop off the extra lines? From the top or the bottom? Do you need to support chopping width too?

I have a c++ class that handles all the overhead of creating MFTs, along with a number of sample MFTs that show how to use that class available at http://www.LimeGreenSocks.com/MFT. It's still in beta as of this writing, but it should give you some ideas.

Probably the closest sample for what you are trying to do is the Rotate. When rotating, an 800x600 video can become a 600x800 video. The Rotate even allows the rotation to be changed while streaming (see Format Changes under Asynchronous MFTs). The c++ rotate mft is a well-commented ~350 lines long.

查看更多
登录 后发表回答