public IClip AddClip(string name, string fileName, GroupMediaType mediaType, InsertPosition position, double offset, double clipStart, double clipEnd, bool manageLifespan) { IGroup group = null; if (mediaType == GroupMediaType.Audio) { group = FindFirstGroupOfType(GroupType.Audio); } else { group = FindFirstGroupOfType(GroupType.Video); } if (group == null) { throw new SplicerException( string.Format(CultureInfo.InvariantCulture, Resources.ErrorNoGroupForSupportingClipOfType, mediaType)); } if (group.Tracks.Count > 0) { return(group.Tracks[0].AddClip(name, fileName, mediaType, position, offset, clipStart, clipEnd, manageLifespan)); } else { throw new SplicerException( string.Format(CultureInfo.InvariantCulture, Resources.ErrorNoTracksFoundInFirstGroupOfType, group.Type)); } }
public IClip AddClip(string name, string fileName, GroupMediaType groupMediaType, InsertPosition position, double offset, double clipStart, double clipEnd) { IGroup group = null; if (groupMediaType == GroupMediaType.Audio) { group = FindFirstGroupOfType(GroupType.Audio); } else { group = FindFirstGroupOfType(GroupType.Video); } if (group == null) { throw new SplicerException( string.Format("No group found supporting a clip of type \"{0}\"", groupMediaType)); } if (group.Tracks.Count > 0) { return(group.Tracks[0].AddClip(name, fileName, groupMediaType, position, offset, clipStart, clipEnd)); } else { throw new SplicerException( string.Format("No tracks found in the first group of type \"{0}\"", group.Type)); } }
public IClip AddClip(string name, string fileName, GroupMediaType mediaType, InsertPosition position, double offset, double clipStart, double clipEnd, bool manageLifespan) { CheckMediaTypeAgainstGroup(mediaType); OnAddingClip(); if ((clipEnd < 0) && (mediaType == GroupMediaType.Image)) { clipEnd = DefaultImageDisplayDuration + clipStart; } long durationInUnits; var mediaFile = new MediaFile(fileName, manageLifespan); double absoluteOffset = position == InsertPosition.Absolute ? offset : Duration + offset; IList <IDisposable> activeAssistants = null; IAMTimelineSrc timelineSrc = null; try { activeAssistants = FetchAssistants(mediaFile); timelineSrc = CreateMedia(mediaFile, mediaType, TimelineBuilder.ToUnits(absoluteOffset), TimelineBuilder.ToUnits(clipStart), TimelineBuilder.ToUnits(clipEnd), out durationInUnits); } finally { DisposeOfAssistants(activeAssistants); } if (!string.IsNullOrEmpty(name)) { ((IAMTimelineObj)timelineSrc).SetUserName(name); } IClip clip = new Clip(this, _timeline, timelineSrc, name, absoluteOffset, TimelineBuilder.ToSeconds(durationInUnits), clipStart, mediaFile); clip.AddingEffect += clip_BeforeEffectAdded; clip.AddedEffect += clip_AfterEffectAdded; _clips.Add(clip); _virtualClips.AddVirtualClip(clip); OnAddedClip(clip); return(clip); }
private void CheckMediaTypeAgainstGroup(GroupMediaType mediaType) { if (mediaType == GroupMediaType.Audio) { if (Group.Type != GroupType.Audio) { throw new SplicerException(Resources.ErrorCantAddAudioClipsToVideoGroup); } } else { if (Group.Type != GroupType.Video) { throw new SplicerException(Resources.ErrorCantAddVideoClipsToAudioGroup); } } }
private void CheckMediaTypeAgainstGroup(GroupMediaType mediaType) { if (mediaType == GroupMediaType.Audio) { if (Group.Type != GroupType.Audio) { throw new SplicerException( "You can not add audio clips to a track which exists within a non-audio group"); } } else { if (Group.Type != GroupType.Video) { throw new SplicerException( "You can not add video or image clips to a track which exists within a non-video group"); } } }
private IAMTimelineSrc CreateMedia(MediaFile mediaFile, GroupMediaType mediaType, long offset, long start, long end, out long duration) { int hr; IAMTimelineObj sourceObj; IAMTimelineSrc source; // If the endpoint is -1, find the real file length if (end < 0) { end = mediaFile.LengthInUnits; } duration = (end - start); // create the timeline source object hr = _timeline.CreateEmptyNode(out sourceObj, TimelineMajorType.Source); DESError.ThrowExceptionForHR(hr); long absolouteStart = offset; long absolouteEnd = absolouteStart + duration; // set up source length hr = sourceObj.SetStartStop(absolouteStart, absolouteEnd); DESError.ThrowExceptionForHR(hr); try { source = (IAMTimelineSrc)sourceObj; // Set the file name hr = source.SetMediaName(mediaFile.FileName); DESError.ThrowExceptionForHR(hr); // Set the start/end - we fix the Fps at 0 for static media (images) if (mediaType == GroupMediaType.Image) { hr = source.SetDefaultFPS(0.0); DESError.ThrowExceptionForHR(hr); } else { hr = source.SetMediaTimes(start, end); DESError.ThrowExceptionForHR(hr); } // set the stretch mode for non-audio media if (mediaType != GroupMediaType.Audio) { hr = source.SetStretchMode(ResizeFlags.Stretch); DESError.ThrowExceptionForHR(hr); } // Connect the track to the source hr = _track.SrcAdd(sourceObj); DESError.ThrowExceptionForHR(hr); // Set the times, get back the times adjusted to fit the frame rate hr = source.FixMediaTimes(ref start, ref end); DESError.ThrowExceptionForHR(hr); // Calculate the last frame number for the file double d1 = (end - start); double d2 = (TimelineBuilder.Units / _fps); double d3 = d1 / d2; var d4 = (int)Math.Round(d3); // Update the MediaFile (used to see when we've walked past // the end of a file) mediaFile.LengthInFrames = d4; if (absolouteEnd > _length) { _length = absolouteEnd; } return(source); } catch { if (sourceObj != null) { Marshal.ReleaseComObject(sourceObj); } throw; } }
public IClip AddClip(string name, string fileName, GroupMediaType mediaType, InsertPosition position, double offset, double clipStart, double clipEnd) { return(AddClip(name, fileName, mediaType, position, offset, clipStart, clipEnd, false)); }
private IAMTimelineSrc CreateMedia(MediaFile mediaFile, GroupMediaType mediaType, long offset, long start, long end, out long duration) { int hr; IAMTimelineObj sourceObj; IAMTimelineSrc source; // If the endpoint is -1, find the real file length if (end < 0) { end = mediaFile.LengthInUnits; } duration = (end - start); // create the timeline source object hr = _timeline.CreateEmptyNode(out sourceObj, TimelineMajorType.Source); DESError.ThrowExceptionForHR(hr); long absolouteStart = offset; long absolouteEnd = absolouteStart + duration; // set up source length hr = sourceObj.SetStartStop(absolouteStart, absolouteEnd); DESError.ThrowExceptionForHR(hr); try { source = (IAMTimelineSrc) sourceObj; // Set the file name hr = source.SetMediaName(mediaFile.FileName); DESError.ThrowExceptionForHR(hr); // Set the start/end - we fix the Fps at 0 for static media (images) if (mediaType == GroupMediaType.Image) { hr = source.SetDefaultFPS(0.0); DESError.ThrowExceptionForHR(hr); } else { hr = source.SetMediaTimes(start, end); DESError.ThrowExceptionForHR(hr); } // set the stretch mode for non-audio media if (mediaType != GroupMediaType.Audio) { hr = source.SetStretchMode(ResizeFlags.Stretch); DESError.ThrowExceptionForHR(hr); } // Connect the track to the source hr = _track.SrcAdd(sourceObj); DESError.ThrowExceptionForHR(hr); // Set the times, get back the times adjusted to fit the frame rate hr = source.FixMediaTimes(ref start, ref end); DESError.ThrowExceptionForHR(hr); // Calculate the last frame number for the file double d1 = (end - start); double d2 = (TimelineBuilder.Units/_fps); double d3 = d1/d2; var d4 = (int) Math.Round(d3); // Update the MediaFile (used to see when we've walked past // the end of a file) mediaFile.LengthInFrames = d4; if (absolouteEnd > _length) { _length = absolouteEnd; } return source; } catch { if (sourceObj != null) { Marshal.ReleaseComObject(sourceObj); } throw; } }
public IClip AddClip(string name, string fileName, GroupMediaType mediaType, InsertPosition position, double offset, double clipStart, double clipEnd, bool manageLifespan) { CheckMediaTypeAgainstGroup(mediaType); OnAddingClip(); if ((clipEnd < 0) && (mediaType == GroupMediaType.Image)) { clipEnd = DefaultImageDisplayDuration + clipStart; } long durationInUnits; var mediaFile = new MediaFile(fileName, manageLifespan); double absoluteOffset = position == InsertPosition.Absolute ? offset : Duration + offset; IList<IDisposable> activeAssistants = null; IAMTimelineSrc timelineSrc = null; try { activeAssistants = FetchAssistants(mediaFile); timelineSrc = CreateMedia(mediaFile, mediaType, TimelineBuilder.ToUnits(absoluteOffset), TimelineBuilder.ToUnits(clipStart), TimelineBuilder.ToUnits(clipEnd), out durationInUnits); } finally { DisposeOfAssistants(activeAssistants); } if (!string.IsNullOrEmpty(name)) { ((IAMTimelineObj) timelineSrc).SetUserName(name); } IClip clip = new Clip(this, _timeline, timelineSrc, name, absoluteOffset, TimelineBuilder.ToSeconds(durationInUnits), clipStart, mediaFile); clip.AddingEffect += clip_BeforeEffectAdded; clip.AddedEffect += clip_AfterEffectAdded; _clips.Add(clip); _virtualClips.AddVirtualClip(clip); OnAddedClip(clip); return clip; }
public IClip AddClip(string name, string fileName, GroupMediaType mediaType, InsertPosition position, double offset, double clipStart, double clipEnd) { return AddClip(name, fileName, mediaType, position, offset, clipStart, clipEnd, false); }
public IClip AddClip(string name, string fileName, GroupMediaType mediaType, InsertPosition position, double offset, double clipStart, double clipEnd, bool manageLifespan) { IGroup group = null; if (mediaType == GroupMediaType.Audio) { group = FindFirstGroupOfType(GroupType.Audio); } else { group = FindFirstGroupOfType(GroupType.Video); } if (group == null) { throw new SplicerException( string.Format(CultureInfo.InvariantCulture, Resources.ErrorNoGroupForSupportingClipOfType, mediaType)); } if (group.Tracks.Count > 0) { return group.Tracks[0].AddClip(name, fileName, mediaType, position, offset, clipStart, clipEnd, manageLifespan); } else { throw new SplicerException( string.Format(CultureInfo.InvariantCulture, Resources.ErrorNoTracksFoundInFirstGroupOfType, group.Type)); } }
public IClip AddClip(string fileName, GroupMediaType groupMediaType, InsertPosition position, double offset, double clipStart, double clipEnd) { return(AddClip(null, fileName, groupMediaType, position, offset, clipStart, clipEnd)); }