Partilhar via


How to add a slow motion effect to captured video

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

This topic shows you how to add a slow-motion effect to video. This effect can be added during live capture or added as a post-processing step during transcoding.

Roadmap: How does this topic relate to others? See:

Prerequisites

This topic assumes that you can create a basic Windows Store app using C++, C#, or Visual Basic. For help creating your first app, see Create your first Windows Store app using C# or Visual Basic.

Instructions

Step 1: Set up your app to capture video

To set up your app to record video, follow the instructions in Quickstart: capturing video by using the MediaCapture api

Step 2: Create the slow motion effect and add it to the MediaCapture object

Create a new instance of the SlowMotionEffectDefinition class and set the TimeStretchRate to a value of 1.0 or greater. Call your MediaCapture object's AddEffectAsync method to add the effect before you begin capturing video.

public async void AddSlowMotionEffect()
{

    Windows.Media.Effects.SlowMotionEffectDefinition slowMotionEffectDefinition = 
        new Windows.Media.Effects.SlowMotionEffectDefinition();

    // Setter and Getter for TimeStretchRate.
    slowMotionEffectDefinition.TimeStretchRate = 2;


    // Add the effect using the AddEffectAsync overloaded method
    await _mediaCapture.AddEffectAsync(
        MediaStreamType.VideoRecord,
        slowMotionEffectDefinition.ActivatableClassId,
        slowMotionEffectDefinition.Properties);

}

Complete example

Quickstart: capturing video by using the MediaCapture api

Roadmap for Windows Runtime apps using C# or Visual Basic

Roadmap for Windows Runtime apps using C++