Пример #1
0
        /// <summary>
        /// Saves the content of this <see cref="CdgFile"/> as video.
        /// </summary>
        /// <param name="path">
        /// A <see cref="string"/> indicating the file to which the video should be saved.
        /// </param>
        /// <returns>
        /// The Task.
        /// </returns>
        public void SaveAsVideo(string path)
        {
            Console.WriteLine("Saving...");
            using (ITimeline timeline = new DefaultTimeline())
            {
                IGroup group      = timeline.AddVideoGroup(32, 300, 300);
                ITrack videoTrack = group.AddTrack();
                Bitmap frame      = this.Next();
                int    frames     = 0;
                while (frame != null && frames < 100)
                {
                    Console.WriteLine("<!--Getting frame-->");
                    videoTrack.AddImage(frame, 0, 0.2D);
                    frame = this.Next();
                    frames++;
                }

                try
                {
                    Console.WriteLine(videoTrack.Duration);
                    Console.WriteLine(this.stream.Name.Replace("cdg", "mp3"));
                    ITrack audioTrack = timeline.AddAudioGroup().AddTrack();
                    ////IClip audio = audioTrack.AddAudio(this.stream.Name.Replace("cdg", "mp3"), 0, videoTrack.Duration);
                    IRenderer renderer = new WindowsMediaRenderer(timeline, path, WindowsMediaProfiles.HighQualityVideo);
                    renderer.Render();
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }

            Console.WriteLine("Saving finished.");
        }
Пример #2
0
        public void JumpVolume()
        {
            // and audible demonstration of the difference between interpolating
            // parameter values for an effect, and jumping directly to them.

            string outputFile = "JumpVolume.wma";

            using (ITimeline timeline = new DefaultTimeline())
            {
                IGroup group = timeline.AddAudioGroup();
                ITrack track = group.AddTrack();
                IClip  clip  = track.AddClip("testinput.mp3", GroupMediaType.Audio, InsertPosition.Relative, 0, 0, 10);

                EffectDefinition effectDefinition = new EffectDefinition(DxtSubObjects.AudioMixer);

                Parameter volumeParameter = new Parameter("Vol", 0.0, 2, 1.0);
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Jump, 2.5, "0.2"));
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Jump, 3.5, "0.8"));
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Jump, 4.5, "0.2"));
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Jump, 5, "1.0"));
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Interpolate, clip.Duration, "0.0"));

                effectDefinition.Parameters.Add(volumeParameter);

                clip.AddEffect(0, clip.Duration, effectDefinition);

                using (
                    IRenderer renderer =
                        new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.MediumQualityAudio))
                {
                    renderer.Render();
                }
            }
        }
Пример #3
0
        public static string renderVideo(this ITimeline timeline, string outputFile)
        {
            try
            {
                if (outputFile.fileExists())
                {
                    Files.deleteFile(outputFile);
                }

                //var renderer = new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.HighQualityVideo);
                var renderer = new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.BiggerHighQualityVideo);

                "[API_Cropper] starting video rendering process".info();
                renderer.Render();
                "[API_Cropper] video rendering complete".debug();
                if (outputFile.fileExists())
                {
                    "[API_Cropper] video saved to {0}".info(outputFile);
                    return(outputFile);
                }

                "[API_Cropper] video file was not created".error();
                return("");
            }
            catch (Exception ex)
            {
                ex.log("in API_Cropper videoTrack renderVideo");
                return("");
            }
        }
Пример #4
0
        public void RenderWmvWithImageWatermark()
        {
            string outputFile = "RenderWmvWithImageWatermark.wmv";

            using (Image waterMarkImage = Image.FromFile("..\\..\\corner_watermark.png"))
                using (ITimeline timeline = new DefaultTimeline())
                {
                    IGroup videoGroup = timeline.AddVideoGroup(32, 320, 240);
                    ITrack videoTrack = videoGroup.AddTrack();

                    IClip videoClip =
                        videoTrack.AddClip("..\\..\\transitions.wmv", GroupMediaType.Video, InsertPosition.Absolute, 0, 0, 2);

                    IGroup audioGroup = timeline.AddAudioGroup();
                    ITrack audioTrack = audioGroup.AddTrack();
                    audioTrack.AddClip("..\\..\\testinput.mp3", GroupMediaType.Audio, InsertPosition.Absolute, 0, 0, 2);

                    ICallbackParticipant[] videoParticipants =
                        new ICallbackParticipant[]
                    { new ImageWatermarkParticipant(32, 320, 240, true, waterMarkImage, new Point(200, 0)) };

                    using (
                        WindowsMediaRenderer renderer =
                            new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.HighQualityVideo,
                                                     videoParticipants, null))
                    {
                        renderer.Render();
                    }
                }
        }
Пример #5
0
        public void PixelateAndIrisBetweenImages()
        {
            string outputFile = "PixelateAndIrisBetweenImages.wmv";

            using (ITimeline timeline = new DefaultTimeline())
            {
                timeline.AddAudioGroup().AddTrack().AddClip("testinput.wav", GroupMediaType.Audio,
                                                            InsertPosition.Relative, 0, 0, 17);

                IGroup group = timeline.AddVideoGroup(32, 160, 100);
                ITrack low   = group.AddTrack();
                ITrack hi    = group.AddTrack();
                hi.AddClip("image1.jpg", GroupMediaType.Image, InsertPosition.Absoloute, 0, 0, 6);
                low.AddClip("image2.jpg", GroupMediaType.Image, InsertPosition.Absoloute, 5, 0, 8);
                hi.AddClip("image3.jpg", GroupMediaType.Image, InsertPosition.Absoloute, 11, 0, 6);

                // notice that we must apply "in" and "out" of the pixelation effect, to get the
                // desired effect, like the fade
                hi.AddTransition(5.0, 1.0, StandardTransitions.CreatePixelate(), true);
                hi.AddTransition(6.0, 1.0, StandardTransitions.CreatePixelate(), false);

                // the iris transition is a one shot
                hi.AddTransition(11.0, 2.0, StandardTransitions.CreateIris(), false);

                using (
                    IRenderer renderer =
                        new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.HighQualityVideo))
                {
                    renderer.Render();
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Render the video from the music file/background image, asynchronously.
        ///
        /// Attach event handlers to audioProgress[0] and videoProgress[0] to monitor
        /// progress, AFTER this function has been called!
        /// </summary>
        public void Render(ProgressBar pbarAudio, ProgressBar pbarVideo)
        {
            Console.WriteLine("\nBegin render...");
            using (ITimeline timeline = new DefaultTimeline())
            {
                Console.Write("Create group...");
                // create our primary group
                IGroup group = timeline.AddVideoGroup("background", 15.0, 32, 720, 480);
                Console.WriteLine("done.");

                Console.Write("Create tracks...");
                // add a video and audio track to the group
                ITrack videoTrack = group.AddTrack();
                ITrack audioTrack = timeline.AddAudioGroup().AddTrack();
                Console.WriteLine("done.");

                // add the audio/bg image
                Console.Write("Create audio track...");
                IClip audio = audioTrack.AddAudio(this.mp3path);
                Console.WriteLine("done.");

                Console.Write("Create video track... length: " + audio.Duration.ToString() + "...");
                IClip clip1 = videoTrack.AddImage(this.backgroundImage, 0, audio.Duration); //videoTrack.AddImage(this.backgroundImage, 0, audio.Duration);

                Console.WriteLine("done.");

                // set up progress indicators
                audioProgress[0] = new PercentageProgressParticipant(timeline);
                videoProgress[0] = new PercentageProgressParticipant(timeline);

                Console.WriteLine("Timeline duration: " + timeline.Duration);
                Console.WriteLine("Audio duration: " + audio.Duration);
                Console.WriteLine("IMG duration: " + videoTrack.Duration);

                // render our video out
                Console.Write("Render Start...");
                using (renderer = new Splicer.Renderer.WindowsMediaRenderer(
                           timeline, videopath, WindowsMediaProfiles.HighQualityVideo,
                           videoProgress, audioProgress))
                {
                    this.pbarA = pbarAudio;
                    this.pbarV = pbarVideo;

                    audioProgress[0].ProgressChanged += new EventHandler <Splicer.Renderer.ProgressChangedEventArgs>(listMusicItem_ProgressChangedAudio);
                    videoProgress[0].ProgressChanged += new EventHandler <Splicer.Renderer.ProgressChangedEventArgs>(listMusicItem_ProgressChangedVideo);

                    renderer.Render();
                }
                Console.WriteLine("Render Completed.");

                //AsyncCallback cb = new AsyncCallback(CallBack);
                //IAsyncResult ar = renderer.BeginRender(cb, renderer.State);
            }
        }
Пример #7
0
        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();
                }
            }
        }
Пример #8
0
        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();
                }
            }
        }
Пример #9
0
        public void AddInMemoryImageClipsToTrack()
        {
            var tempFiles = new StringCollection();

            Action <IClip> addClip =
                delegate(IClip clip)
            {
                if (tempFiles.Contains(clip.File.FileName))
                {
                    Assert.Fail("TempFile: {0} duplicated", clip.File.FileName);
                }
            };

            string outputFile = "AddInMemoryImageClipsToTrack.wmv";

            Image image = Image.FromFile("..\\..\\image1.jpg");

            using (ITimeline timeline = new DefaultTimeline())
            {
                timeline.AddAudioGroup().AddTrack().AddAudio("..\\..\\testinput.wav", 0, 7.5);

                ITrack videoTrack = timeline.AddVideoGroup(24, 320, 200).AddTrack();
                addClip(videoTrack.AddImage(image));                                                  // 0->1
                addClip(videoTrack.AddImage(image, 1));                                               // 2->3
                addClip(videoTrack.AddImage(image, 1, 0.5));                                          // 4->4.5
                addClip(videoTrack.AddImage(image, InsertPosition.Absolute, 5, 0, 1));                // 5->6
                IClip clip = videoTrack.AddImage("named", image, InsertPosition.Absolute, 7, 0.5, 1); // 7->7.5
                addClip(clip);

                Assert.AreEqual("named", clip.Name);
                Assert.AreEqual(7.5, videoTrack.Duration);

                using (
                    var renderer = new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.HighQualityVideo)
                    )
                {
                    renderer.Render();
                }
            }

            foreach (string file in tempFiles)
            {
                Assert.IsFalse(File.Exists(file));
            }
        }
Пример #10
0
        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 async Task MakeVideo(double BPM, double BPM_Multiplier, double offset, string videoTitle, string audioFilePath, double videoDuration = 30)
        {
            string temporaryVideoFileName = tempFilesPath + videoMakerIOUtilities.ReturnNameWithExtension(videoTitle, true);
            string VideoFileName          = finalFilesPath + videoMakerIOUtilities.ReturnNameWithExtension(videoTitle, false);
            double FrameTimeFromBPM       = videoMakerTimingUtilities.ReturnFrameTimeBasedOnBPM(BPM, BPM_Multiplier);
            await Task.Run(() =>
            {
                if (videoMakerIOUtilities.CheckIfImageFilesExist(imageFilesPath: $@"jpg2\", 19))
                {
                    using (ITimeline timeline = new DefaultTimeline())
                    {
                        IGroup group      = timeline.AddVideoGroup(32, 738, 650);
                        ITrack videoTrack = group.AddTrack();
                        videoTrack.AddImage($@"jpg2\1.jpg", 0, offset);
                        int framesNumber = videoMakerTimingUtilities.ReturnNumberOfFrames(videoDuration, offset, FrameTimeFromBPM);
                        for (int i = 1; i <= framesNumber; i++)
                        {
                            int picNumber = i % 18;
                            videoTrack.AddImage($@"jpg2\{picNumber + 1}.jpg", 0, FrameTimeFromBPM);
                        }
                        ITrack audioTrack = timeline.AddAudioGroup().AddTrack();
                        audioTrack.AddAudio(audioFilePath, 0, videoTrack.Duration + 2.75);
                        using (WindowsMediaRenderer renderer = new WindowsMediaRenderer(timeline, temporaryVideoFileName, WindowsMediaProfiles.HighQualityVideo))
                        {
                            renderer.Render();
                        }
                    }
                }
            }
                           );

            if (CutVideo(temporaryVideoFileName, VideoFileName, videoDuration))
            {
                Messaging.ShowMessage($"Your video was generated successfully. Look for your {VideoFileName} file in app folder.", "Success");
            }
        }
Пример #12
0
        private void makeMovie(int imageName)
        {
            int    simpleCount = 0;
            string simpleAudio = "";
            string videoPath   = "";
            string title       = "";
            string description = "";
            string tags        = "";

            foreach (VideoListModel videoItem in vList.getData())
            {
                if (simpleCount == 0)
                {
                    title       = videoItem.VideoName;
                    description = videoItem.VideoDescription;
                    tags        = videoItem.VideoTags;
                    simpleAudio = videoItem.AudioLocation;
                    videoPath   = Application.StartupPath + "\\VideoData\\video\\" + videoItem.VideoName + ".wmv";
                }
                simpleCount++;
            }

            label9.Text = title;

            Console.WriteLine(Application.StartupPath + "\\VideoData\\images\\merged\\" + imageName.ToString() + ".jpg");

            using (ITimeline timeline = new DefaultTimeline(1))
            {
                IGroup group = timeline.AddVideoGroup(32, 1920, 1080);

                ITrack videoTrack = group.AddTrack();
                IClip  clip1      = videoTrack.AddImage(Application.StartupPath + "\\VideoData\\images\\merged\\" + imageName.ToString() + ".jpg", 0, 0);

                ITrack audioTrack = timeline.AddAudioGroup().AddTrack();

                IClip audio = audioTrack.AddAudio(simpleAudio);

                IClip clip2 = videoTrack.AddImage(Application.StartupPath + "\\VideoData\\images\\merged\\" + imageName.ToString() + ".jpg", 0, audio.Duration);


                var participant = new PercentageProgressParticipant(timeline);
                participant.ProgressChanged += new EventHandler <Splicer.Renderer.ProgressChangedEventArgs>(participant_ProgressChanged);
                using (
                    WindowsMediaRenderer renderer = new WindowsMediaRenderer(timeline, videoPath, WindowsMediaProfiles.HighQualityVideo))
                {
                    renderer.Render();
                }
            }



            progressBar1.Value = 0;

            vList.getData().RemoveAt(0);
            vList.saveData();

            refreshList();

            try
            {
                //2. Get credentials and upload the file
                Run(title, description, videoPath, tags);
            }
            catch (AggregateException ex)
            {
                foreach (var exception in ex.InnerExceptions)
                {
                    Console.WriteLine(exception.Message);
                }
            }
        }
Пример #13
0
 private static void RenderVideo(ITimeline timeline, string fileName)
 {
     using (var renderer = new WindowsMediaRenderer(timeline, fileName, WindowsMediaProfiles.HighQualityVideo))
         renderer.Render();
 }