Editing files with Encoder


In Encoder V2 we added the ability to edit multiple sections out of a video/audio file and this can also be accomplished with the Expression Encoder SDK. MediaItem has a property called SourceClips which contains the list of clips for that media item. When you create a MediaItem it starts with one clip that encompasses the entire duration of the source. Each clip is represented by the SourceClip class and that contains two properties StartTime and EndTime. These properties indicate the times within the source file that the clip represents. For example, if I wanted to change it so that I only encoded the first 15 seconds of the file I could do something like the following.

MediaItem item = new MediaItem(@"C:\myvideo.wmv");
item.SourceClips[0].EndTime = new TimeSpan(0, 0, 15);

If I wanted to include the time from 0-15 seconds and from 30-45 seconds of the file I could add the following lines.

TimeSpan timeStart = new TimeSpan(0, 0, 30);
TimeSpan timeEnd = new TimeSpan(0, 0, 45);
item.SourceClips.Add(new SourceClip(timeStart, timeEnd));

You can keep added SourceClip’s for as many sections of the source that you wish to add before calling the Encode method.

Comments (8)

  1. Afiqah Azlee says:

    Hello there, I have problems regarding putting an audio/video in Windows Movie Maker. Everytime I try put an audio/video in it, this message will come out;

    "C:UsersmaSMusicMiley Cyrus – Fly  On The Wall.mp3 could not be imported. The specified module could not be found."

    What does it mean? Please help 🙂

    Thank you.

  2. Dean Rowe says:

    Do you get that with every file? Are you running Windows XP or Vista?

  3. CapCrunch says:

    hi, just wanted to say you guys have done a great job with the sdk. i wish there was more c# samples included. thanks and keep up the good work!

  4. Dean Rowe says:

    Thanks for the feedback, always nice to hear from someone using the SDK.

  5. CapCrunch says:

    Hi Dean,

    Can the console encoding sample be incorporated into a simple Windows Form application, without having to setup for threading, etc.?

    My attempt to add the console encoding logic to a Windows Form makes the system hang after the job.encode(); line and the progress event never gets called (or maybe once), but the encoding process seems to be going on in the background. What gives?

    Is there a simple way to make this work without threading?

    Thanks,

    CC

  6. CapCrunch says:

    Hi Dean,

    Can the console encoding sample be incorporated into a simple Windows Form application, without having to setup for threading, etc.?

    My attempt to add the console encoding logic to a Windows Form makes the system hang after the job.encode(); line and the progress event never gets called (or maybe once), but the encoding process seems to be going on in the background. What gives?

    Is there a simple way to make this work without threading?

    Thanks,

    CC

  7. Dean Rowe says:

    If you look at the WPFEncode example in the samples you’ll see an example of how to update the UI during an encode. You do have to create another thread, but it’s fairly straightforward.