Skip to main content

How to add the transition between 2 video fragments?

Product: Video Edit SDK .Net. Engine: VideoEditCore (Windows only).

Sample code

In this article, we add a simple transition between 2 video files (parts of them).

1. Add 2 video fragments from 2 video files, each 5 seconds (5000 ms) long

The first fragment is located in the first 5 seconds on the timeline, and the second fragment is located between 4 and 9 seconds, so the second video overlaps the first video. This 1-second overlap will be used as a transition between videos. Each transition except fade-in/out requires this.

string[] files = { "!video.avi", "!video2.wmv" };
FileSegment[] segments1 = new[] { new FileSegment(TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(5000)) };
var videoFile = new VideoSource(
files[0],
segments1,
VideoEditStretchMode.Letterbox,
0,
1.0);

FileSegment[] segments2 = new[] { new FileSegment(TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(5000)) };

var videoFile2 = new VideoSource(
files[1],
segments2,
VideoEditStretchMode.Letterbox,
0,
1.0);

VideoEdit1.Input_AddVideoFile(
videoFile,
TimeSpan.FromMilliseconds(0));

VideoEdit1.Input_AddVideoFile(
videoFile2,
TimeSpan.FromMilliseconds(4000));

2. Get the ID of the required transition

int id = VideoEdit.Video_Transition_GetIDFromName("Upper right");

3. Add a transition between 4 and 5 seconds on the timeline

 VideoEdit1.Video_Transition_Add(TimeSpan.FromMilliseconds(4000), TimeSpan.FromMilliseconds(5000), id);

Transition names are available using the "VideoEdit.Video_Transition_Names()" call. Also, you can check the IDs list in this article.

Required redists

How can the required redists be installed or deployed to the user's PC?


Visit our GitHub page to get more code samples.