public void Dispose() { if (_clips != null) { foreach (IClip clip in _clips) { clip.Dispose(); } _clips = null; } if (_effects != null) { foreach (IEffect effect in _effects) { effect.Dispose(); } _effects = null; } if (_transitions != null) { foreach (ITransition transition in _transitions) { transition.Dispose(); } _transitions = null; } if (_track != null) { Marshal.ReleaseComObject(_track); _track = null; } }
private void InitVideo() { int hr; IAMTimelineGroup pVideoGroup = (IAMTimelineGroup)m_pVideoGroupObj; // all we set is the major type. The group will automatically use other defaults AMMediaType VideoGroupType = new AMMediaType(); VideoGroupType.majorType = MediaType.Video; hr = pVideoGroup.SetMediaType(VideoGroupType); DESError.ThrowExceptionForHR(hr); DsUtils.FreeAMMediaType(VideoGroupType); // add the video group to the timeline hr = m_pTimeline.AddGroup(m_pVideoGroupObj); DESError.ThrowExceptionForHR(hr); IAMTimelineObj pTrack1Obj; hr = m_pTimeline.CreateEmptyNode(out pTrack1Obj, TimelineMajorType.Track); DESError.ThrowExceptionForHR(hr); // tell the composition about the track IAMTimelineComp pRootComp = (IAMTimelineComp)m_pVideoGroupObj; hr = pRootComp.VTrackInsBefore(pTrack1Obj, -1); DESError.ThrowExceptionForHR(hr); m_VideoTrack = (IAMTimelineTrack)pTrack1Obj; }
/// <summary> /// Add Color to video group on Layer /// </summary> private void AddColor(IAMTimelineTrack myTrack, Color sColor, long StartTime, long EndTime) { int hr; IAMTimelineObj pSource1Obj; // create the timeline source object hr = m_pTimeline.CreateEmptyNode(out pSource1Obj, TimelineMajorType.Source); DESError.ThrowExceptionForHR(hr); try { // set up source length hr = pSource1Obj.SetStartStop(StartTime, EndTime); DESError.ThrowExceptionForHR(hr); DESTransition.SetColor(pSource1Obj, sColor); // Connect the track to the source hr = myTrack.SrcAdd(pSource1Obj); DESError.ThrowExceptionForHR(hr); } finally { Marshal.ReleaseComObject(pSource1Obj); } }
/// <summary> /// add Source to video group /// </summary> private void AddSource(IAMTimelineTrack myTrack, string SourceFile, long StartTime, long EndTime) { int hr; IAMTimelineObj pSource1Obj; // create the timeline source object hr = m_pTimeline.CreateEmptyNode(out pSource1Obj, TimelineMajorType.Source); DESError.ThrowExceptionForHR(hr); try { // set up source length hr = pSource1Obj.SetStartStop(StartTime, EndTime); DESError.ThrowExceptionForHR(hr); IAMTimelineSrc pSource1Src = (IAMTimelineSrc)pSource1Obj; // Set the file name hr = pSource1Src.SetMediaName(SourceFile); DESError.ThrowExceptionForHR(hr); // Set the start/end hr = pSource1Src.SetMediaLength(EndTime - StartTime); DESError.ThrowExceptionForHR(hr); hr = pSource1Src.SetStretchMode(0); // Set the times, get back the times adjusted to fit the frame rate hr = pSource1Src.FixMediaTimes(ref StartTime, ref EndTime); DESError.ThrowExceptionForHR(hr); // Connect the track to the source hr = myTrack.SrcAdd(pSource1Obj); DESError.ThrowExceptionForHR(hr); } finally { Marshal.ReleaseComObject(pSource1Obj); } }
/// <summary> /// add Transition on IAMTimelineTrack /// 如何把效果加入到层上 /// 进入Direction设置为True,推出false /// </summary> public static int SetTransition(ref IAMTimeline m_pTimeline, IAMTimelineTrack pTrac, Guid EffectGUID, bool Direction, long StartTime, long EndTime, Property[] parArr) { int hr; IAMTimelineObj pTransObj; IAMTimelineTransable pTransable = (IAMTimelineTransable)pTrac; hr = m_pTimeline.CreateEmptyNode(out pTransObj, TimelineMajorType.Transition); hr = pTransable.TransAdd(pTransObj); pTransObj.SetStartStop(StartTime, EndTime); hr = pTransObj.SetSubObjectGUID(EffectGUID); IPropertySetter ipro = (IPropertySetter) new PropertySetter(); if (parArr != null && parArr.Length > 0) { foreach (Property pro in parArr) { if (pro != null) { DESHelper.AddParameter(ipro, pro.Name, pro.Value); } } } DESHelper.AddParameter(ipro, "Duration", EndTime / DESConsts.UNITS - StartTime / DESConsts.UNITS); hr = pTransObj.SetPropertySetter(ipro); //Set transition Direction if (Direction) { IAMTimelineTrans pTrans = (IAMTimelineTrans)pTransObj; pTrans.SetSwapInputs(true); } return(hr); }
private void TestDuration() { int hr; long l; double d; IAMTimelineObj pTrack1Obj; hr = m_pTimeline.CreateEmptyNode(out pTrack1Obj, TimelineMajorType.Track); DESError.ThrowExceptionForHR(hr); // tell the composition about the track IAMTimelineComp pRootComp = (IAMTimelineComp)m_pVideoGroup; hr = pRootComp.VTrackInsBefore(pTrack1Obj, -1); DESError.ThrowExceptionForHR(hr); m_VideoTrack = (IAMTimelineTrack)pTrack1Obj; AddVideo("foo.avi"); AddVideo("foxo.avi"); hr = m_pTimeline.GetDuration(out l); DESError.ThrowExceptionForHR(hr); Debug.Assert(l == 10000000000, "Duration"); hr = m_pTimeline.GetDuration2(out d); DESError.ThrowExceptionForHR(hr); Debug.Assert(d == 1000.0, "GetDuration2"); hr = m_pTimeline.ValidateSourceNames(SFNValidateFlags.Replace | SFNValidateFlags.Check | SFNValidateFlags.Popup, this, IntPtr.Zero); DESError.ThrowExceptionForHR(hr); }
public Track(ITrackContainer container, IAMTimeline timeline, IAMTimelineTrack track, string name, int priority) { _container = container; _timeline = timeline; _track = track; _name = name; _priority = priority; int hr = timeline.GetDefaultFPS(out _fps); DESError.ThrowExceptionForHR(hr); }
/// <summary> /// Set Transition Direction on IAMTimelineTrack /// </summary> public static int SetTransDirection(ref IAMTimeline m_pTimeline, IAMTimelineTrack pTrac, bool Direction, long StartTime, long EndTime) { int hr; IAMTimelineObj pTransObj; IAMTimelineTransable pTransable = (IAMTimelineTransable)pTrac; hr = m_pTimeline.CreateEmptyNode(out pTransObj, TimelineMajorType.Transition); hr = pTransable.TransAdd(pTransObj); pTransObj.SetStartStop(StartTime, EndTime); IAMTimelineTrans pTrans = (IAMTimelineTrans)pTransObj; pTrans.SetSwapInputs(true); return(hr); }
private void TestAreYouBlank() //def ok { bool ret = false; int hr = 0; IAMTimelineObj trackobj; hr = m_pTimeline.CreateEmptyNode(out trackobj, TimelineMajorType.Track); DESError.ThrowExceptionForHR(hr); m_pTrack = (IAMTimelineTrack)trackobj; hr = m_pTrack.AreYouBlank(out ret); DESError.ThrowExceptionForHR(hr); Debug.Assert(ret == true, "AreYouBlank"); }
/// <summary> /// Set BackGround Effect on IAMTimelineTrack /// 显示效果 /// </summary> public static int SetEffect(ref IAMTimeline m_pTimeline, IAMTimelineTrack pTrac, Guid EffectGUID, long starttime, long endtime, Property[] parArr) { IAMTimelineObj pTransObj; int hr = m_pTimeline.CreateEmptyNode(out pTransObj, TimelineMajorType.Effect); IAMTimelineEffectable aEffectable = (IAMTimelineEffectable)pTrac; pTransObj.SetStartStop(starttime, endtime); pTransObj.SetSubObjectGUID(EffectGUID); aEffectable.EffectInsBefore(pTransObj, -1); IPropertySetter ipro = (IPropertySetter) new PropertySetter(); if (parArr != null) { foreach (Property pro in parArr) { DESHelper.AddParameter(ipro, pro.Name, pro.Value); } } DESHelper.AddParameter(ipro, "Duration", endtime / DESConsts.UNITS - starttime / DESConsts.UNITS); hr = pTransObj.SetPropertySetter(ipro); return(hr); }
/// <summary> /// Release everything /// </summary> public void Dispose() { if (m_Track != null) { Marshal.ReleaseComObject(m_Track); m_Track = null; } m_Files = null; m_Length = 0; GC.SuppressFinalize(this); }
/// <summary> /// Constructor /// </summary> /// <param name="mType">Media type of the new group</param> /// <param name="pTimeline">Timeline to use for the group</param> /// <param name="fps">FPS for the group</param> public Group(AMMediaType mType, IAMTimeline pTimeline, double fps) { int hr; IAMTimelineObj pGroupObj; m_Length = 0; m_Files = new ArrayList(); m_FPS = fps; m_pTimeline = pTimeline; // make the root group/composition hr = m_pTimeline.CreateEmptyNode( out pGroupObj, TimelineMajorType.Group); DESError.ThrowExceptionForHR(hr); try { IAMTimelineGroup pGroup = (IAMTimelineGroup)pGroupObj; // Set the media type we just created hr = pGroup.SetMediaType( mType ); DESError.ThrowExceptionForHR(hr); DsUtils.FreeAMMediaType(mType); // add the video group to the timeline hr = m_pTimeline.AddGroup( pGroupObj ); DESError.ThrowExceptionForHR(hr); IAMTimelineObj pTrack1Obj; hr = m_pTimeline.CreateEmptyNode(out pTrack1Obj, TimelineMajorType.Track); DESError.ThrowExceptionForHR(hr); // tell the composition about the track IAMTimelineComp pRootComp = (IAMTimelineComp)pGroupObj; hr = pRootComp.VTrackInsBefore( pTrack1Obj, -1 ); DESError.ThrowExceptionForHR(hr); m_Track = (IAMTimelineTrack)pTrack1Obj; } finally { Marshal.ReleaseComObject(pGroupObj); } //Marshal.ReleaseComObject(pTrack1Obj); // Released as m_VideoTrack in dispose }
/// <summary> /// Add a file to the group /// </summary> /// <param name="sName">File name+path to add</param> /// <param name="lStart">Start point in source file in UNITS</param> /// <param name="lEnd">End point in source file in UNITS or -1 to add entire file</param> public void Add(string sName, long lStart, long lEnd) { int hr; long lLength; // Create a mediafile object to hold the file MediaFile mf = new MediaFile(sName); // Add it to the list of files m_Files.Add(mf); // If the endpoint is -1, find the real file length if (lEnd < 0) { lEnd = mf.Length; } lLength = lEnd - lStart; // create the timeline source object IAMTimelineObj pSource1Obj; hr = m_pTimeline.CreateEmptyNode(out pSource1Obj, TimelineMajorType.Source); DESError.ThrowExceptionForHR(hr); // Create track IAMTimelineObj pTrack1Obj; hr = m_pTimeline.CreateEmptyNode(out pTrack1Obj, TimelineMajorType.Track); DESError.ThrowExceptionForHR(hr); try { // Set start and stop time of the file in the target timeline hr = pSource1Obj.SetStartStop(m_Length, lLength + m_Length); DESError.ThrowExceptionForHR(hr); IAMTimelineSrc pSource1Src = (IAMTimelineSrc)pSource1Obj; // Set the file name hr = pSource1Src.SetMediaName(mf.FileName); DESError.ThrowExceptionForHR(hr); // Set the start/end hr = pSource1Src.SetMediaTimes(lStart, lEnd); DESError.ThrowExceptionForHR(hr); // tell the composition about the track IAMTimelineComp pRootComp = (IAMTimelineComp)m_pGroup; hr = pRootComp.VTrackInsBefore(pTrack1Obj, -1); DESError.ThrowExceptionForHR(hr); IAMTimelineTrack pTrack = (IAMTimelineTrack)pTrack1Obj; // Connect the track to the source hr = pTrack.SrcAdd(pSource1Obj); DESError.ThrowExceptionForHR(hr); // Set the times, get back the times adjusted to fit the frame rate hr = pSource1Src.FixMediaTimes(ref lStart, ref lEnd); DESError.ThrowExceptionForHR(hr); // Calculate the last frame number for the file double d1 = (lEnd - lStart); double d2 = (DESCombine.UNITS / m_FPS); double d3 = d1 / d2; int d4 = (int)Math.Round(d3); // Update the MediaFile (used to see when we've walked past // the end of a file) mf.LengthInFrames = d4; } finally { Marshal.ReleaseComObject(pSource1Obj); Marshal.ReleaseComObject(pTrack1Obj); } m_Length += lLength; }
private void Dispose(bool disposing) { if (disposing) { if (_clips != null) { foreach (IClip clip in _clips) { clip.Dispose(); } _clips = null; } if (_effects != null) { foreach (IEffect effect in _effects) { effect.Dispose(); } _effects = null; } if (_transitions != null) { foreach (ITransition transition in _transitions) { transition.Dispose(); } _transitions = null; } } if (_track != null) { Marshal.ReleaseComObject(_track); _track = null; } }