Condividi tramite


How to add video stabilization effect to captured video (XAML)

[ 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 ]

The VideoStabilization effect can help reduce shakiness in video, such as from a hand-held camera. 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: Add the video stabilization effect during live capture

To add the stabilization effect during live capture, use the MediaCapture.AddEffectAsync method. This method takes the following parameters:

  • MediaStreamType - One of the values of the MediaStreamType enumeration that specifies whether the stream is for video recording, video preview, audio, or photo.
  • effectActivationID - The class identifier of the activatable runtime class that implements the effect. The runtime class must implement the IMediaExtension interface. The Windows.Media namespace provides a VideoEffects class.
  • effectSettings - An IPropertySet that contains additional configuration parameters for the effect. If no additional configuration is needed for the effect, then this parameter should be null.

You can call this method multiple times to add several effects.

This example adds a VideoStabilization effect to the chain of effects that are attached to the source stream coming out of the device source.

MediaCapture captureMgr = new MediaCapture();
await captureMgr.InitializeAsync();

await captureMgr.AddEffectAsync(
    MediaStreamType.VideoRecord,
    Windows.Media.VideoEffects.VideoStabilization,
    null);

Call the ClearEffectsAsync method to clear all of the effects from the stream.

// captureMgr is of type MediaCapture.
await captureMgr.ClearEffectsAsync(MediaStreamType.VideoRecord);

Step 2: Add the video stabilization effect during transcoding

To add the stabilization effect during transcoding, use the MediaTranscoder.AddVideoEffect method and provide the class identifier of the activatable runtime class that implements the effect. You can call AddVideoEffect multiple times to add several effects.

This example adds the VideoStabilization effect to the MediaTranscoder object.

MediaTranscoder transcoder = new MediaTranscoder();

transcoder.AddVideoEffect(
    "Windows.Media.VideoEffects.VideoStabilization");

Call the MediaTranscoder.ClearEffects method to clear all of the effects from the transcoder.

MediaTranscoder transcoder = new MediaTranscoder();

transcoder.AddVideoEffect(
    "Windows.Media.VideoEffects.VideoStabilization");

Roadmaps

Roadmap for Windows Runtime apps using C# and Visual Basic

Roadmap for Windows Runtime apps using C++

Designing UX for apps

Adding multimedia

Samples

Media capture sample

Transcoding Media Sample

Media extension sample

Tasks

Quickstart: video and audio

How to select audio tracks in different languages

Reference

Windows.Media.Capture

CaptureElement

Windows.Media.Transcoding

Other resources

Optimize media resources