public void RemoveClipEventHandlers() { int count = 0; EventHandler incrementBefore = delegate { count++; }; EventHandler <AddedEffectEventArgs> incrementAfter = delegate { count++; }; using (ITimeline timeline = new DefaultTimeline()) { IClip clip = timeline.AddAudioGroup().AddTrack().AddClip("testinput.wav", GroupMediaType.Audio, InsertPosition.Absolute, 0, 0, -1); clip.AddedEffect += incrementAfter; clip.AddingEffect += incrementBefore; clip.AddEffect(0, 2, StandardEffects.CreateDefaultBlur()); Assert.AreEqual(2, count); count = 0; clip.AddedEffect -= incrementAfter; clip.AddingEffect -= incrementBefore; clip.AddEffect(0, 2, StandardEffects.CreateDefaultBlur()); Assert.AreEqual(0, count); } }
public void AddEffect() { using (ITimeline timeline = new DefaultTimeline()) { IGroup group = timeline.AddVideoGroup(24, 100, 100); IComposition composition = group.AddComposition(); bool firedBefore = false; bool firedAfter = false; composition.BeforeEffectAdded += new EventHandler(delegate { firedBefore = true; }); composition.AfterEffectAdded += new EventHandler <AfterEffectAddedEventArgs>(delegate { firedAfter = true; }); IEffect effect = composition.AddEffect("test", -1, 1, 2, StandardEffects.CreateBlurEffect(2, 2, 10)); Assert.AreEqual("test", effect.Name); Assert.AreEqual(1, effect.Offset); Assert.AreEqual(2, effect.Duration); Assert.AreEqual(1, composition.Effects.Count); Assert.IsTrue(firedBefore); Assert.IsTrue(firedAfter); } }
public void CreateAudioEnvelopeWithFades() { StandardEffects.CreateAudioEnvelope(0.5, 1, 1, 5); StandardEffects.CreateAudioEnvelope(0.2, 0, 1, 5); StandardEffects.CreateAudioEnvelope(0.7, 1, 0, 5); StandardEffects.CreateAudioEnvelope(0.15, 0, 0, 5); }
public void AddEffectSetsApropriateContainer() { using (ITimeline timeline = new DefaultTimeline()) { EffectDefinition def = StandardEffects.CreateDefaultBlur(); IGroup group = timeline.AddVideoGroup(24, 100, 100); IEffect groupEffect = group.AddEffect(0, 10, def); Assert.AreSame(group, groupEffect.Group); Assert.AreSame(group, groupEffect.Container); ITrack track = group.AddTrack(); IEffect trackEffect = track.AddEffect(0, 10, def); Assert.AreSame(group, trackEffect.Group); Assert.AreSame(track, trackEffect.Container); IComposition composition = group.AddComposition(); IEffect compositionEffect = composition.AddEffect(0, 10, def); Assert.AreSame(group, compositionEffect.Group); Assert.AreSame(composition, compositionEffect.Container); IClip clip = track.AddClip("..\\..\\image1.jpg", GroupMediaType.Image, InsertPosition.Absolute, 0, 0, 10); IEffect clipEffect = clip.AddEffect(0, 10, def); Assert.AreSame(group, clip.Group); Assert.AreSame(clip, clipEffect.Container); } }
public void RemoveEvents() { int count = 0; EventHandler increment = new EventHandler(delegate { count++; }); EventHandler <AfterEffectAddedEventArgs> incrementForAfterEffectAdded = new EventHandler <AfterEffectAddedEventArgs>(delegate { count++; }); EventHandler <AfterTransitionAddedEventArgs> incrementForAfterTransitionAdded = new EventHandler <AfterTransitionAddedEventArgs>(delegate { count++; }); EventHandler <AfterClipAddedEventArgs> incrementForAfterClipAdded = new EventHandler <AfterClipAddedEventArgs>(delegate { count++; }); using (ITimeline timeline = new DefaultTimeline()) { ITrack track = timeline.AddAudioGroup().AddTrack(); track.AfterEffectAdded += incrementForAfterEffectAdded; track.AfterTransitionAdded += incrementForAfterTransitionAdded; track.AfterClipAdded += incrementForAfterClipAdded; track.BeforeEffectAdded += increment; track.BeforeTransitionAdded += increment; track.BeforeClipAdded += increment; track.AddEffect(0, 2, StandardEffects.CreateDefaultBlur()); track.AddClip("testinput.mp3", GroupMediaType.Audio, InsertPosition.Absoloute, 0, 0, 1); track.AddTransition(0, 2, StandardTransitions.CreateFade()); Assert.AreEqual(6, count); count = 0; track.AfterEffectAdded -= incrementForAfterEffectAdded; track.AfterTransitionAdded -= incrementForAfterTransitionAdded; track.AfterClipAdded -= incrementForAfterClipAdded; track.BeforeEffectAdded -= increment; track.BeforeTransitionAdded -= increment; track.BeforeClipAdded -= increment; track.AddEffect(0, 2, StandardEffects.CreateDefaultBlur()); track.AddClip("testinput.mp3", GroupMediaType.Audio, InsertPosition.Relative, 0, 0, 1); track.AddTransition(2, 2, StandardTransitions.CreateFade()); Assert.AreEqual(0, count); } }
public void EnsureClipBubblesBeforeAndAfterEffectAddedUp() { int beforeCount = 0; int afterCount = 0; using (ITimeline timeline = new DefaultTimeline()) { IGroup group = timeline.AddAudioGroup(); ITrack track = group.AddTrack(); track.BeforeEffectAdded += new EventHandler(delegate { beforeCount++; }); track.AfterEffectAdded += new EventHandler <AfterEffectAddedEventArgs>(delegate { afterCount++; }); IClip clip = track.AddClip("testinput.mp3", GroupMediaType.Audio, InsertPosition.Absoloute, 0, 0, -1); clip.AddEffect(0, 1, StandardEffects.CreateDefaultBlur()); Assert.AreEqual(1, beforeCount); Assert.AreEqual(1, afterCount); } }
public void TrackAddEffectBubblesToComposition() { int beforeCount = 0; int afterCount = 0; using (ITimeline timeline = new DefaultTimeline()) { IGroup group = timeline.AddVideoGroup(24, 100, 100); IComposition composition = group.AddComposition(); composition.BeforeEffectAdded += new EventHandler(delegate { beforeCount++; }); composition.AfterEffectAdded += new EventHandler <AfterEffectAddedEventArgs>(delegate { afterCount++; }); ITrack track = composition.AddTrack(); track.AddEffect("test", -1, 1, 2, StandardEffects.CreateBlurEffect(2, 2, 10)); Assert.AreEqual(1, beforeCount); Assert.AreEqual(1, afterCount); } }
public void RemoveEvents() { int count = 0; EventHandler increment = delegate { count++; }; EventHandler <AddedCompositionEventArgs> incrementForAfterCompositionAdded = delegate { count++; }; EventHandler <AddedEffectEventArgs> incrementForAfterEffectAdded = delegate { count++; }; EventHandler <AddedTrackEventArgs> incrementForAfterTrackAdded = delegate { count++; }; EventHandler <AddedTransitionEventArgs> incrementForAfterTransitionAdded = delegate { count++; }; EventHandler <AddedClipEventArgs> incrementForAfterClipAdded = delegate { count++; }; using (ITimeline timeline = new DefaultTimeline()) { IComposition composition = timeline.AddAudioGroup().AddComposition(); composition.AddedComposition += incrementForAfterCompositionAdded; composition.AddedEffect += incrementForAfterEffectAdded; composition.AddedTrack += incrementForAfterTrackAdded; composition.AddedTransition += incrementForAfterTransitionAdded; composition.AddedClip += incrementForAfterClipAdded; composition.AddingComposition += increment; composition.AddingEffect += increment; composition.AddingTrack += increment; composition.AddingTransition += increment; composition.AddingClip += increment; composition.AddComposition(); composition.AddEffect(0, 2, StandardEffects.CreateDefaultBlur()); composition.AddTrack().AddClip("testinput.mp3", GroupMediaType.Audio, InsertPosition.Absolute, 0, 0, 1); composition.AddTransition(0, 2, StandardTransitions.CreateFade()); Assert.AreEqual(10, count); count = 0; composition.AddedComposition -= incrementForAfterCompositionAdded; composition.AddedEffect -= incrementForAfterEffectAdded; composition.AddedTrack -= incrementForAfterTrackAdded; composition.AddedTransition -= incrementForAfterTransitionAdded; composition.AddedClip -= incrementForAfterClipAdded; composition.AddingComposition -= increment; composition.AddingEffect -= increment; composition.AddingTrack -= increment; composition.AddingTransition -= increment; composition.AddingClip -= increment; composition.AddComposition(); composition.AddEffect(0, 2, StandardEffects.CreateDefaultBlur()); composition.AddTrack(); composition.AddTransition(2, 2, StandardTransitions.CreateFade()); Assert.AreEqual(0, count); } }
private static void CreateWatermark(ITrackContainer tracks, string imageName, double duration) { var videoTrack = tracks.AddTrack(); var clip = videoTrack.AddImage(imageName, 0, duration); clip.AddEffect(0, duration, StandardEffects.CreateAlphaSetterRamp(0.5)); videoTrack.AddTransition(0, duration, StandardTransitions.CreateKey(KeyTransitionType.Rgb, null, null, null, 0x00FFFFFF, null), false); }
public void FadeBetweenImages() { // generates a little slide-show, with audio track and fades between images. string outputFile = "FadeBetweenImages.wmv"; using (ITimeline timeline = new DefaultTimeline()) { IGroup group = timeline.AddVideoGroup(32, 160, 100); ITrack videoTrack = group.AddTrack(); IClip clip1 = videoTrack.AddImage("image1.jpg", 0, 2); // play first image for a little while IClip clip2 = videoTrack.AddImage("image2.jpg", 0, 2); // and the next IClip clip3 = videoTrack.AddImage("image3.jpg", 0, 2); // and finally the last IClip clip4 = videoTrack.AddImage("image4.jpg", 0, 2); // and finally the last double halfDuration = 0.5; // fade out and back in group.AddTransition(clip2.Offset - halfDuration, halfDuration, StandardTransitions.CreateFade(), true); group.AddTransition(clip2.Offset, halfDuration, StandardTransitions.CreateFade(), false); // again group.AddTransition(clip3.Offset - halfDuration, halfDuration, StandardTransitions.CreateFade(), true); group.AddTransition(clip3.Offset, halfDuration, StandardTransitions.CreateFade(), false); // and again group.AddTransition(clip4.Offset - halfDuration, halfDuration, StandardTransitions.CreateFade(), true); group.AddTransition(clip4.Offset, halfDuration, StandardTransitions.CreateFade(), false); // add some audio ITrack audioTrack = timeline.AddAudioGroup().AddTrack(); IClip audio = audioTrack.AddAudio("testinput.wav", 0, videoTrack.Duration); // create an audio envelope effect, this will: // fade the audio from 0% to 100% in 1 second. // play at full volume until 1 second before the end of the track // fade back out to 0% volume audioTrack.AddEffect(0, audio.Duration, StandardEffects.CreateAudioEnvelope(1.0, 1.0, 1.0, audio.Duration)); // render our slideshow out to a windows media file using ( IRenderer renderer = new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.HighQualityVideo)) { renderer.Render(); } } }
public void AddEffectToClip() { bool beforeFired = false; bool afterFired = false; using (ITimeline timeline = new DefaultTimeline()) { IGroup group = timeline.AddVideoGroup(24, 64, 64); ITrack track = group.AddTrack(); IClip clip = track.AddClip("transitions.wmv", GroupMediaType.Video, InsertPosition.Absoloute, 0, 0, -1); clip.BeforeEffectAdded += new EventHandler(delegate { beforeFired = true; }); clip.AfterEffectAdded += new EventHandler <AfterEffectAddedEventArgs>(delegate { afterFired = true; }); EffectDefinition defintion = StandardEffects.CreateBlurEffect(2, clip.Duration, 20); IEffect effect = clip.AddEffect("blur", -1, 0, clip.Duration, defintion); Assert.IsTrue(beforeFired); Assert.IsTrue(afterFired); Assert.AreEqual("blur", effect.Name); Assert.AreEqual(0, effect.Priority); Assert.AreEqual(clip.Duration, effect.Duration); Assert.AreEqual(0, clip.Offset); Assert.AreSame(defintion, effect.EffectDefinition); PrepareToExecute(timeline, @"<timeline framerate=""30.0000000""> <group type=""video"" bitdepth=""24"" width=""64"" height=""64"" framerate=""30.0000000"" previewmode=""0""> <track> <clip start=""0"" stop=""7.9990000"" src=""transitions.wmv"" mstart=""0""> <effect start=""0"" stop=""7.9990000"" clsid=""{7312498D-E87A-11D1-81E0-0000F87557DB}"" username=""blur""> <param name=""PixelRadius"" value=""2""> <linear time=""7.9990000"" value=""20"" /> </param> </effect> </clip> </track> </group> </timeline>"); } }
public void WatermarkVideoClip() { // this demonstrates one way of watermarking a video clip... string outputFile = "WatermarkVideoClip.wmv"; using (ITimeline timeline = new DefaultTimeline(15)) { // greate our default audio track timeline.AddAudioGroup().AddTrack(); // add a video group, 32bpp, 320x240 (32bpp required to allow for an alpha channel) IGroup videoGroup = timeline.AddVideoGroup(32, 320, 240); // add our default video track ITrack videoTrack = videoGroup.AddTrack(); // add another video track, this will be used to contain our watermark image ITrack watermarkTrack = videoGroup.AddTrack(); // add the video in "transitions.wmv" to the first video track, and the audio in "transitions.wmv" // to the first audio track. timeline.AddVideoWithAudio("transitions.wmv"); // add the watermark image in, and apply it for the duration of the videoContent // this image will be stretched to fit the video clip, and in this case is a transparent gif. IClip watermarkClip = watermarkTrack.AddImage("testlogo.gif", 0, videoTrack.Duration); // add a alpha setter effect to the image, this will adjust the alpha of the image to be 0.5 // of it's previous value - so the watermark is 50% transparent. watermarkClip.AddEffect(0, watermarkClip.Duration, StandardEffects.CreateAlphaSetterRamp(0.8)); // add a transition to the watermark track, this allows the video clip to "shine through" the watermark, // base on the values present in the alpha channel of the watermark track. watermarkTrack.AddTransition(0, videoTrack.Duration, StandardTransitions.CreateKey(KeyTransitionType.Alpha, null, null, null, null, null), false); using ( // render it to windows media var renderer = new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.HighQualityVideo)) { renderer.Render(); } } }
/// <summary> /// Adds the sound files in a random order /// </summary> /// <param name="tracks">The track container that will hold the new track</param> /// <param name="soundFiles">The list of sound files to add</param> /// <param name="duration"></param> /// <returns>The new track</returns> private ITrack AddBackgroundMusic(ITrackContainer tracks, IList <string> soundFiles, double duration) { var audioTrack = tracks.AddTrack(); if (soundFiles.Any()) { var shuffled = shuffler.Shuffle(soundFiles); foreach (var soundFile in shuffled) { audioTrack.AddAudio(soundFile, 0, duration); } audioTrack.AddEffect(0, audioTrack.Duration, StandardEffects.CreateAudioEnvelope(0.05)); } return(audioTrack); }
public void GroupAddEffectBubblesToTimeline() { int beforeCount = 0; int afterCount = 0; using (ITimeline timeline = new DefaultTimeline(12)) { timeline.AddingEffect += delegate { beforeCount++; }; timeline.AddedEffect += delegate { afterCount++; }; IGroup group = timeline.AddAudioGroup(); group.AddEffect(0, 1, StandardEffects.CreateDefaultBlur()); } Assert.AreEqual(1, beforeCount); Assert.AreEqual(1, afterCount); }
public void EffectPrioirities() { using (ITimeline timeline = new DefaultTimeline()) { EffectDefinition definition = StandardEffects.CreateBlurEffect(2, 10, 2); IGroup group = timeline.AddAudioGroup(); IEffect first = group.AddEffect("first", -1, 0, 10, definition); IEffect second = group.AddEffect("second", 0, 0, 10, definition); IEffect third = group.AddEffect("third", 1, 0, 10, definition); IEffect fourth = group.AddEffect("fourth", -1, 0, 10, definition); IEffect fifth = group.AddEffect("fifth", 2, 0, 10, definition); Assert.AreEqual(3, first.Priority); Assert.AreEqual(0, second.Priority); Assert.AreEqual(1, third.Priority); Assert.AreEqual(4, fourth.Priority); Assert.AreEqual(2, fifth.Priority); } }
static void Main(string[] args) { string folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Pics"); using (ITimeline timeline = new DefaultTimeline(30)) { double halfDuration = 1; IGroup group = timeline.AddVideoGroup("video", 30, 32, 1920, 1080); ITrack videoTrack = group.AddTrack(); List <string> filePaths = Directory.EnumerateFiles(folderPath, "*.jpg").ToList(); for (int i = 0; i < filePaths.Count; i++) { IClip clip = videoTrack.AddImage(filePaths[i], 0, 10); if (i > 0) { group.AddTransition(clip.Offset - halfDuration, halfDuration, StandardTransitions.CreateFade(), true); group.AddTransition(clip.Offset, halfDuration, StandardTransitions.CreateFade(), false); } } string folderPath2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Audio"); string audioPath = Directory.EnumerateFiles(folderPath2, "*.wav").FirstOrDefault(x => x != null); ITrack audioTrack = timeline.AddAudioGroup().AddTrack(); IClip audio = audioTrack.AddAudio(audioPath, 0, videoTrack.Duration); audioTrack.AddEffect(0, audio.Duration, StandardEffects.CreateAudioEnvelope(1.0, 1.0, 1.0, audio.Duration)); using (var renderer = new WindowsMediaRenderer(timeline, "output.wmv", WindowsMediaProfiles.FullHD)) { renderer.Render(); } } Console.WriteLine("Hello World!"); }
public void GroupAddEffectBubblesToTimeline() { int beforeCount = 0; int afterCount = 0; using (ITimeline timeline = new DefaultTimeline(12)) { timeline.BeforeEffectAdded += new EventHandler(delegate { beforeCount++; }); timeline.AfterEffectAdded += new EventHandler <AfterEffectAddedEventArgs>(delegate { afterCount++; }); IGroup group = timeline.AddAudioGroup(); group.AddEffect(0, 1, StandardEffects.CreateDefaultBlur()); } Assert.AreEqual(1, beforeCount); Assert.AreEqual(1, afterCount); }
public void AddEffectsToTrack() { using (ITimeline timeline = new DefaultTimeline()) { IGroup group = timeline.AddVideoGroup(24, 320, 200); ITrack track = group.AddTrack(); IEffect effect = track.AddEffect("test", -1, 1, 3, StandardEffects.CreateBlurEffect(2, 2, 15)); Assert.AreEqual(1, track.Effects.Count); Assert.AreSame(effect, track.Effects[0]); PrepareToExecute(timeline, @"<timeline framerate=""30.0000000""> <group type=""video"" bitdepth=""24"" height=""200"" framerate=""30.0000000"" previewmode=""0""> <track> <effect clsid=""{7312498D-E87A-11D1-81E0-0000F87557DB}"" username=""test""> <param name=""PixelRadius"" value=""2""> <linear time=""2"" value=""15"" /> </param> </effect> </track> </group> </timeline>"); } }
public void CreateAudioEnvelopeVolumeTooLow2() { StandardEffects.CreateAudioEnvelope(-1); }
public void CreateAudioEnvelopeVolumeTooHigh2() { StandardEffects.CreateAudioEnvelope(2, 1, 1, 5); }
public void CreateAudioEnvelope() { StandardEffects.CreateAudioEnvelope(0.5); }
public void CreateAlphaSetterRampLowerThenZero() { StandardEffects.CreateAlphaSetterRamp(-1); }
public void CreateAlphaSetterRampAboveOne() { StandardEffects.CreateAlphaSetterRamp(2); }
public void CreateAlphaSetterRamp() { StandardEffects.CreateAlphaSetterRamp(0.5); }
public void CreateAlphaSetter() { StandardEffects.CreateAlphaSetter(0x99); }
public void CreateAudioEnvelopeWithInvalidFadeDurations() { StandardEffects.CreateAudioEnvelope(0.5, 4, 4, 2); }