MFormats SDK: transitions between sources


With MFormats SDK, it is as easy to implement transitions between video sources, as everything else. This post covers MFTransition, the method that handles this feature:


MFTransition(
MFFrame _pFrameFrom,
out MFFrame _ppFrameRes,
double _dblPos,
string _bsTransition,
string _bsPropsList,
string _bsConverterID
)


Parameters


  • _pFrameFrom - a frame from the transition is used
  • _ppFrameRes - result frame
  • _dblPos - position of the transition (from 0 to 1)
  • _bsTransition - transition type
  • _bsPropsList - additional properties
  • _bsConverterID - converter's ID


Before making the transition we need two MFFrame objects: one as destination (object to which the transition leads) and the other as source (from which the transition starts). We can get these objects in any known way (from MFReader, from MLive, create from still image from file, etc.). With these MFFrame objects a transition looks like this:


MFFrame pFrameRes = null;
pFrameTo.MFTransition(pFrameFrom, out pFrameRes, _dblPos, transitionType, "", "");


Where pFrameTo is the destination frame, pFrameFrom is the source frame, pFrameRes is the result frame. Position (_dblPos) is set by the user (for example, by the slider value). transitionType is the type of transition with certain paramters. It is described below.


If you would like to make a smooth transition, you should change the position within a sertain number of frame pairs: 


//Let's make a transition from source m_objReaderFrom to source m_objReaderTo within 100 frames

// Read frame from the first source.
MFFrame pFrameFrom;
m_objReaderFrom.SourceFrameGet(-1, out pFrameFrom, "");

// Read frame from the second source.
MFFrame pFrameTo;
m_objReaderTo.SourceFrameGet(-1, out pFrameTo, "");

// Calculate the transition position (from 0 to 1).
// We plan to make a transition within 100 frames, so to get the position we just divide the current transition frame number by 100.
double _transitionPosition = transitionFrameCounter / 100;

// Get the transitioned frame transitioned.
MFFrame pFrameResult;
pFrameTo.MFTransition(pFrameFrom, out pFrameResult, _transitionPosition, "fade", "", "");

// Process the frame as required (for example send to the preview)
m_objPrewiev1.ReceiverFramePut(pFrameResult, -1, "");


You can try this feature on File transition sample.


MFormats SDK supports the following transition types.


Barn - reveals new content of the object with a motion that resembles doors opening or closing.


  • Motion - Indicates whether new content is revealed from the outside or the inside first:

out - The transition moves from the center of the object toward the borders of the object;

in - The transition moves from the borders of the object toward the center.

  • Orientation - Indicates whether the filter effect is horizontal or vertical:

horizontal - Transition lines are horizontal;

vertical - Transition lines are vertical.


Blinds - reveals new content of the object with a motion that appears to open or close blinds.


  • Bands - The number of strips into which the content is divided during the transition. Valid range: 1...100.
  • Direction - The direction of motion in the transition (up, down, right, left).


CheckerBoard - reveals new content of the object by uncovering squares placed like a checkerboard over the original content.


  • Direction - The direction of motion in the transition (up, down, right, left).
  • SquaresX - The number of columns. Valid range: 2 or more.
  • SquaresY - The number of rows. Valid range: 2 or more.


Fade - reveals new content of the object by fading out the original content.


  • Overlap - The fraction of the transition duration when both original and new content is displayed. Valid range: 0.0 ... 1.0.


It is also possible to make transitions to colored screen or custom image. To do it you should use file path or color name as a parameter of this transition: fade(c:\temp.jpg) or fade(black).


GradientWipe - reveals new content of the object by passing a gradient band over the original content.


  • GradientSize - Percentage of the object that is covered by the gradient band. Valid range: 0.0 ... 1.0.
  • WipeStyle - Indicates whether the gradient band moves vertically or horizontally. Valid range: 0...1 (horizontally, vertically).
  • Motion - Indicates whether content is revealed as defined by the WipeStyle property setting or in the opposite direction.


Inset - reveals new content of the object diagonally. This transition does not have any options.


Iris - reveals new content of the object with an iris effect, similar to the opening of a camera aperture.


  • irisStyle - The shape of the Iris filter aperture:

DIAMOND - Diamond-shaped aperture,
CIRCLE - Circular aperture,
CROSS - X-shaped aperture,
PLUS - Plus sign-shaped aperture,
SQUARE - Square aperture,
STAR - Star-shaped aperture.

  • Motion - Indicates whether new content is revealed from the outside or the inside first (out, in).


Pixelate - displays the content of the object as colored squares that take the average color value of the pixels they replace.


  • MaxSquare - Maximum width in pixels of a pixelated square. The larger the number, the larger the squares and the coarser the picture. Valid range: 2...50.


The Pixelate transition is a complex visual effect. In the first half of the transition, the content is displayed as expanding pixelated squares. The width of the pixelated squares increases from one pixel to MaxSquare pixels at the halfway point of the transition. The final half of the transition reduces the pixelated squares back to individual pixels, revealing the new content. During this transition, the original content fades into the new content. The fade effect is produced by reducing the opacity of the original content to zero while the opacity of the new content is raised to 100 percent at the same time.


RadialWipe - reveals new content of the object with a radial wipe, like a windshield-wiper blade.


  • WipeStyle - Method used to reveal the new content:

CLOCK - Sweeps around the center, clockwise from the top;
WEDGE - Sweeps around the center in both directions from the top;
RADIAL - Sweeps from the top to the left side, with one end of the sweep anchored on the upper left corner.


RandomBars - reveals new content of the object by exposing random lines of pixels.


  • Orientation - Indicates whether the filter effect is horizontal or vertical:

horizontal - Transition lines are horizontal;
vertical - Transition lines are vertical.


RandomDissolve - reveals new content of the object by exposing random 

pixels. This transition does not have any options.


Slide - reveals new content of the object by sliding sections of the image into place.


  • bands - The number of strips into which the content is divided during the transition. Valid range: 1...100.
  • slideStyle - Method used to reveal the new content:

HIDE - Slides bands of original content out, exposing new content;
PUSH - Slides bands of new content in, pushing original content out;
SWAP - Alternating bands expose new content, or push original content out, at the same time.


Spiral - reveals new content of the object with a spiral motion.


  • gridSizeX - Number of grid columns used for the filter. Valid range: 1...100.
  • gridSizeY - Number of grid rows used for the filter. Valid range: 1...100.


The combination of the GridSizeX and GridSizeY property values divides the content of an object into a grid for the filter to use.


Stretch - reveals new content of the object with a stretching motion to cover the original content.


  • stretchStyle - Method used to reveal the new content:

HIDE - Stretches new content over original content from left to right;
PUSH - Stretches new content in and squeezes original content out, moving from left to right. This motion resembles a cube rotating from one face to another;
SPIN - Stretches new content over original content from the center outward.


Strips - reveals new content of the object by moving successive strips into place, like a diagonal saw blade passing across the original content.


  • Motion - Corner from which new content is revealed during a Strips transition:

leftdown - from the upper left corner to the lower right;
leftup - from the lower left corner to the upper right;
rightdown - from the upper right corner to the lower left;
rightup - from the lower right corner to the upper left.


Wheel - reveals new content of the object with a rotating motion, like spokes of a wheel covering the original content. Options:


  • Spokes - Number of wedges that the content is divided into during the transition. Valid range: 2...20.



ZigZag - reveals new content of the object with a forward and back motion that moves down the object. Options:


  • gridSizeX - number of grid columns used for the filter. Valid range: 1...100.
  • gridSizeY - number of grid rows used for the filter. Valid range: 1...100.


The combination of the GridSizeX and GridSizeY property values divides the content of an object into a grid for the filter to use.


The transitions with parameters are set like this: stretch(stretchStyle=PUSH) or with full description: "type=wheel spokes=10".