Progress of Rendering

Topics: Developer Forum
Jul 26, 2011 at 3:49 AM

Hi All,

From the example i got this code

 

 IRenderer renderer;
            const double halfDuration = 0.5;
            using (ITimeline timeline = new DefaultTimeline())
            {

                IGroup group = timeline.AddVideoGroup(32, 160, 100);
                ITrack videoTrack = group.AddTrack();

                videoTrack.AddImage("image1.jpg", 0, 30);
                IClip clip2 = videoTrack.AddImage("image2.jpg", 0, 30); // and the next
                IClip clip3 = videoTrack.AddImage("image3.jpg", 0, 30); // and the next
                IClip clip4 = videoTrack.AddImage("image4.jpg", 0, 30); // and finally the last

                // 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.mp3", 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

                var participant = new PercentageProgressParticipant(timeline);
                renderer = new WindowsMediaRenderer(timeline, OutputFile, WindowsMediaProfiles.HighQualityVideo,
                                                    new ICallbackParticipant[] {participant}, null);
                renderer.Render();
            }

 

Now i need to know how can i get the percentage of progress of rendering.. Can any one help me.

 

Thanks in advance..

Saneesh

Jul 26, 2011 at 3:50 AM

var participant = new PercentageProgressParticipant(timeline);
                renderer = new WindowsMediaRenderer(timeline, OutputFile, WindowsMediaProfiles.HighQualityVideo,
                                                    new ICallbackParticipant[] {participant}, null);

 

How this "participant" give me the percentage of rendering

Jul 26, 2011 at 8:40 AM

Hi all I got it working

 

before calling renderer.Render(); method write the below code

 

participant.ProgressChanged += new EventHandler<ProgressChangedEventArgs>(participant_ProgressChanged);

 

and define the function

 

private void participant_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            Console.WriteLine(e.Progress.ToString());
        }

Aug 19, 2014 at 5:08 AM
I am using C# Visual Studio 2013. To get this to mostly work I had to be more explicit with the names:

participant.ProgressChanged += new EventHandler<Splicer.Renderer.ProgressChangedEventArgs>(participant_ProgressChanged);

And the callback function:
private void participant_ProgressChanged(object sender, Splicer.Renderer.ProgressChangedEventArgs e)
    {
        int iProgress =  (int)(e.Progress * 100);
        toolStripProgressBar1.Value = iProgress;
    }
My problem is that the Renderer seems to be holding the CPU time and not yielding any time as to allow the progressbar to refresh. For now, I just put a progressbar on the right side of the toolstrip menu. It does not show progress, even though can put breakpoints in the callback function and it is being called and e.Progress is a valid double between 0 and 1 (progressing toward 1.

Any idea how to get the Renderer to yield so that my progressbar refreshes?
Sep 16, 2014 at 6:33 AM
I found a solution to the above problem.

First of all, put all of the rendering code into a separate method in your object.

Then call it using tasks to spawn its own thread:
var runningTask = Task.Factory.StartNew(() => MakeMovie());

Next, have the ProgressChanged method simply update a variable that is global to the main class (or form)

Finally put a timer on the form that ticks every 100 milliseconds and updates the progressbar from the global variable.
   private void timerRendering_Tick(object sender, EventArgs e)  // called form timer
    {
        if (iProgressBarValue >= 100)
        {
            tRendering.Enabled = false;
            tRendering.Stop();
        }
        UpdateProgressBar();  // using the current iProgressBarValue
    }


   private void participant_ProgressChanged(object sender, Splicer.Renderer.ProgressChangedEventArgs e) //Callback called from spicer rendering code.
    {
            iProgressBarValue = (int)(e.Progress * 100) + 1;
    }