/// <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> Read and store the properties </summary> public void SaveSizeInfo(ISampleGrabber sampGrabber, int Width, int Height) { int hr = 0; // Get the media type from the SampleGrabber AMMediaType media = DESHelper.GetVideoMediaType(DESConsts.BitCount, Width, Height); DsError.ThrowExceptionForHR(hr); if ((media.formatType != FormatType.VideoInfo) || (media.formatPtr == IntPtr.Zero)) { throw new NotSupportedException("Unknown Grabber Media Format"); } // Grab the size info VideoInfoHeader videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader)); m_videoWidth = videoInfoHeader.BmiHeader.Width; m_videoHeight = videoInfoHeader.BmiHeader.Height; m_stride = m_videoWidth * (videoInfoHeader.BmiHeader.BitCount / 8); DsUtils.FreeAMMediaType(media); media = null; }
private ShapeLayer MergeVideoLayers(MessageInfo mes, ShapeLayer[] videoLayers) { string fileID = Guid.NewGuid().ToString().Replace("-", ""); string fileName = LocalFilePathMapping.GetFile(FileType.Video, fileID); var layers = new VideoLayerCollection(); Layer layer = null; long minStartTime = 0; long maxEndTime = 0; Array.ForEach <ShapeLayer>(videoLayers, item => { layer = DESLayerConverter.Instance.Convert(item); //comment out by Louis,for change video start time same as video layer's start time //layer.Level++; if (layer.Level == 0) { minStartTime = layer.StartTime; maxEndTime = layer.EndTime; } else { if (layer.StartTime < minStartTime) { minStartTime = layer.StartTime; } if (layer.EndTime > maxEndTime) { maxEndTime = layer.EndTime; } } layer.Rect = new System.Drawing.Rectangle(layer.Rect.X / mes.Zoom, layer.Rect.Y / mes.Zoom, layer.Rect.Width / mes.Zoom, layer.Rect.Height / mes.Zoom); layers.Add(layer); }); layers.BackColor = mes.BackColor; layers.SignType = SignType.RGB; layers.VideoSize = videoLayers[0].Shape.SignSize; layers.Name = mes.Name; layers.Zoom = 1; layers.PlayLength = maxEndTime - minStartTime; layers.ParentName = ""; layers.EmphasisEffect = mes.EmphasisEffect; if (layers.Count > 1) { layers.Sort(new SortComparer <Layer>("Level", false)); } IBaseFilter ibfVideoCompressor = DESHelper.GetVideoCompressor("Indeo?video 5.10 Compression Filter"); PlayState state = ProWrite.Core.PlayState.Stop; var des = new DESCombine(DESConsts.FPS, DESConsts.BitCount, layers.VideoSize.Width, layers.VideoSize.Height, layers); des.Completed += (s, e) => state = PlayState.Stop; des.RenderToVideo(MediaSubType.Mpeg2Video, fileName, ibfVideoCompressor, null, null, null, new List <Layer>(), 0, mes.Length, layers.VideoSize); des.StartRendering(); state = PlayState.Run; while (state == PlayState.Run) { Thread.Sleep(100); } des.Dispose(); des = null; var newLayer = videoLayers[0].Copy(); ShapeVideo shape = newLayer.Shape as ShapeVideo; if (shape == null)//shape.Type == Gif { shape = new ShapeVideo(); shape.FromTo(newLayer.Shape); newLayer.Shape = shape; } shape.VideoFileID = fileID; shape.VideoUrl = fileName; newLayer.EntryEffect = LayerEffect.Empty; newLayer.ExitEffect = LayerEffect.Empty; newLayer.EmphasisEffect = LayerEffect.Empty; newLayer.EmphasisEffect.Left = (int)minStartTime * Constance.Effect.UnitWidth; newLayer.EmphasisEffect.Width = (int)maxEndTime * Constance.Effect.UnitWidth; return(newLayer); }
/// <summary> /// Add Source to video group /// </summary> public void LoadSource(VideoLayerCollection ds) { int i = 1; long lStart; long lEnd; long m_StartTime = 0; List <Layer> ImageDS = ds.FindAll(ImageLayer); for (int m = 0; m < m_RepeatNums; m++) { m_StartTime = DESHelper.FormatTime(m * m_MaxLength); i = m * ImageDS.Count + 1; foreach (Layer layer in ImageDS) { lStart = m_StartTime + DESHelper.FormatTime(layer.StartTime); lEnd = m_StartTime + DESHelper.FormatTime(layer.EndTime); MediaFile mf = new MediaFile(layer.FilePath); m_Files.Add(mf); mf.LengthInFrames = (int)Math.Round(((lEnd - lStart) * DESConsts.FPS) / DESConsts.UNITS); if (layer.LayerType == LayerType.Video) { long m_Len = DESHelper.GetMediaLength(layer.FilePath); if (m_Len >= lEnd - lStart) { AddSource(m_TrackArr[i], layer.FilePath, lStart, lEnd); } else { for (long n = 0; n < (lEnd - lStart) / m_Len; n++) { AddSource(m_TrackArr[i], layer.FilePath, lStart + n * m_Len, lStart + (n + 1) * m_Len); } AddSource(m_TrackArr[i], layer.FilePath, lEnd - (lEnd - lStart) % m_Len, lEnd); } } else { AddSource(m_TrackArr[i], layer.FilePath, lStart, lEnd); } m_Length += lEnd - lStart; //add Transition and Effect if (layer.TextInfo != null) { DESTransition.SetEffect(ref m_pTimeline, m_TrackArr[i], layer.TextInfo.GUID, m_StartTime + DESHelper.FormatTime(layer.TextInfo.StartTime), m_StartTime + DESHelper.FormatTime(layer.TextInfo.EndTime), layer.TextInfo.ToPropertyArray()); //DESTransition.SetPixelate(ref m_pTimeline, m_CompArr[i], m_StartTime + DESHelper.FormatTime(item.StartTime), m_StartTime + DESHelper.FormatTime(item.EndTime), ds.Zoom); } //DESTransition.SetTextTravel(ref m_pTimeline, m_TrackArr[i], lStart, lEnd, item.TextInfo); if (layer.EntryEffect != null) { DESTransition.SetTransition(ref m_pTimeline, m_TrackArr[i], layer.EntryEffect.GUID, layer.EntryEffect.State, m_StartTime + DESHelper.FormatTime(layer.EntryEffect.StartTime), m_StartTime + DESHelper.FormatTime(layer.EntryEffect.EndTime), layer.EntryEffect.ToPropertyArray()); } if (layer.ExitEffect != null) { DESTransition.SetTransition(ref m_pTimeline, m_TrackArr[i], layer.ExitEffect.GUID, layer.ExitEffect.State, m_StartTime + DESHelper.FormatTime(layer.ExitEffect.StartTime), m_StartTime + DESHelper.FormatTime(layer.ExitEffect.EndTime), layer.ExitEffect.ToPropertyArray()); } if (layer.EmphasisEffect != null) { // edit by Louis, playing emphasis effect exactly start at emphasis effect, not include entry effect DESTransition.SetEffect(ref m_pTimeline, m_TrackArr[i], layer.EmphasisEffect.GUID, m_StartTime + DESHelper.FormatTime(layer.EmphasisEffect.StartTime), m_StartTime + DESHelper.FormatTime(layer.EmphasisEffect.EndTime), layer.EmphasisEffect.ToPropertyArray()); } //DESTransition.SetEffect(ref m_pTimeline, m_TrackArr[i], item.EmphasisEffect.GUID.ToString(), m_StartTime + DESHelper.FormatTime(item.EntryEffect != null ? item.EntryEffect.StartTime : item.EmphasisEffect.StartTime), m_StartTime + DESHelper.FormatTime(item.ExitEffect != null ? item.ExitEffect.EndTime : item.EmphasisEffect.EndTime), item.EmphasisEffect.Property); //不需要对所有的层进行像素化 //DESTransition.SetPixelate(ref m_pTimeline, m_CompArr[i], m_StartTime + DESHelper.FormatTime(item.StartTime), m_StartTime + DESHelper.FormatTime(item.EndTime), ds.Zoom); i++; } } #if VERSION_2 if (ds.MasterLayerVisual) { AddColor(m_TrackArr[0], ds.BackColor, 0, DESHelper.FormatTime(ds.PlayLength)); } #else AddColor(m_TrackArr[0], ds.BackColor, 0, DESHelper.FormatTime(ds.PlayLength)); #endif #if VERSION_2 if (ds.EmphasisEffect != null) { if (ds.MasterLayerVisual) { AddColor(m_TrackArr[m_TrackArr.Length - 1], Color.Empty, 0, DESHelper.FormatTime(ds.PlayLength)); DESTransition.SetEffect(ref m_pTimeline, m_TrackArr[m_TrackArr.Length - 1], ds.EmphasisEffect.GUID, 0, DESHelper.FormatTime(ds.PlayLength), ds.EmphasisEffect.ToPropertyArray()); } } #else if (ds.EmphasisEffect != null) { AddColor(m_TrackArr[m_TrackArr.Length - 1], Color.Empty, 0, DESHelper.FormatTime(ds.PlayLength)); DESTransition.SetEffect(ref m_pTimeline, m_TrackArr[m_TrackArr.Length - 1], ds.EmphasisEffect.GUID, 0, DESHelper.FormatTime(ds.PlayLength), ds.EmphasisEffect.ToPropertyArray()); } #endif }
/// <summary> /// Add comp and track to timeline /// </summary> public void AddCompAndTrack(VideoLayerCollection ds, IAMTimelineGroup pGroup) { IAMTimelineObj pCompObj; IAMTimelineObj pTrackObj; int hr = 0; int i = 1; long m_StartTime = 0; // Create a composition object IAMTimelineComp pGroupComp = (IAMTimelineComp)pGroup; List <Layer> ImageDS = ds.FindAll(p => p.Visible == true && p.FilePath != "" && (p.LayerType == LayerType.Image || p.LayerType == LayerType.Video)); //create backcolor item hr = m_pTimeline.CreateEmptyNode(out pCompObj, TimelineMajorType.Composite); hr = pGroupComp.VTrackInsBefore(pCompObj, -1); m_CompArr[0] = (IAMTimelineComp)pCompObj; hr = m_pTimeline.CreateEmptyNode(out pTrackObj, TimelineMajorType.Track); hr = m_CompArr[0].VTrackInsBefore(pTrackObj, -1); m_TrackArr[0] = (IAMTimelineTrack)pTrackObj; for (int m = 0; m < m_RepeatNums; m++) { m_StartTime = DESHelper.FormatTime(m * m_MaxLength); i = m * ImageDS.Count + 1; foreach (Layer layer in ImageDS) { IAMTimelineComp tempComp = null; hr = m_pTimeline.CreateEmptyNode(out pCompObj, TimelineMajorType.Composite); hr = pGroupComp.VTrackInsBefore(pCompObj, -1); m_CompArr[i] = (IAMTimelineComp)pCompObj; DESTransition.SetDxtKey(ref m_pTimeline, m_CompArr[i], m_StartTime + DESHelper.FormatTime(layer.StartTime), m_StartTime + DESHelper.FormatTime(layer.EndTime)); //Set Sign Color if (layer.LayerType == LayerType.Video || (layer.LayerType == LayerType.Image && DESHelper.GetMediaLength(layer.FilePath) > 0)) { DESTransition.SetSign(ref m_pTimeline, m_CompArr[i], m_StartTime + DESHelper.FormatTime(layer.StartTime), m_StartTime + DESHelper.FormatTime(layer.EndTime), ds.SignType); DESTransition.SetPixelate(ref m_pTimeline, m_CompArr[i], m_StartTime + DESHelper.FormatTime(layer.StartTime), m_StartTime + DESHelper.FormatTime(layer.EndTime), ds.Zoom); } //Set Layer Comsitor if (layer.Rect.X != 0 || layer.Rect.Y != 0 || layer.Rect.Height != m_Height || layer.Rect.Width != m_Width) { hr = m_pTimeline.CreateEmptyNode(out pCompObj, TimelineMajorType.Composite); hr = m_CompArr[i].VTrackInsBefore(pCompObj, -1); tempComp = (IAMTimelineComp)pCompObj; DESTransition.SetCompositor(ref m_pTimeline, tempComp, m_StartTime + DESHelper.FormatTime(layer.StartTime), m_StartTime + DESHelper.FormatTime(layer.EndTime), layer.Rect); DESTransition.SetAlpha(ref m_pTimeline, tempComp, m_StartTime + DESHelper.FormatTime(layer.StartTime), m_StartTime + DESHelper.FormatTime(layer.EndTime)); hr = m_pTimeline.CreateEmptyNode(out pTrackObj, TimelineMajorType.Track); hr = tempComp.VTrackInsBefore(pTrackObj, -1); // append to the end of the track list m_TrackArr[i] = (IAMTimelineTrack)pTrackObj; } else { hr = m_pTimeline.CreateEmptyNode(out pTrackObj, TimelineMajorType.Track); hr = m_CompArr[i].VTrackInsBefore(pTrackObj, -1); // append to the end of the track list m_TrackArr[i] = (IAMTimelineTrack)pTrackObj; } i++; } } //create Sign Effect item hr = m_pTimeline.CreateEmptyNode(out pCompObj, TimelineMajorType.Composite); hr = pGroupComp.VTrackInsBefore(pCompObj, -1); m_CompArr[m_CompArr.Length - 1] = (IAMTimelineComp)pCompObj; hr = m_pTimeline.CreateEmptyNode(out pTrackObj, TimelineMajorType.Track); hr = m_CompArr[m_CompArr.Length - 1].VTrackInsBefore(pTrackObj, -1); m_TrackArr[m_TrackArr.Length - 1] = (IAMTimelineTrack)pTrackObj; DESTransition.SetDxtKey(ref m_pTimeline, m_CompArr[m_TrackArr.Length - 1], 0, DESHelper.FormatTime(ds.PlayLength)); }
/// <summary> /// Start PlayList /// </summary> private void StartPlay() { EventArgs ca = new EventArgs(); int RunTime = 0; curNum = 0; PlayState = PlayState.Next; while (curNum >= 0 && curNum < dsArr.Length) { if (PlayState == PlayState.Stop) { if (des != null) { des.Cancel(); } break; } if (PlayState == PlayState.Next) { dsArr[curNum].Sort(new SortComparer <Layer>("Level", false)); des = new DESCombine(DESConsts.FPS, DESConsts.BitCount, hWin.Width, hWin.Height, dsArr[curNum]); DynamicTextDS = dsArr[curNum].FindAll(DynamicTextLayer); des.Completed += new EventHandler(Completed); pVideo = new DESVideoCallBack(RunTime, m_PlayBar, m_MediaTime); des.RenderToFrame(hWin, pVideo, null, DynamicTextDS, DsRect.FromRectangle(hWin.ClientRectangle), 0, dsArr[curNum].PlayLength); des.StartRendering(); PlayState = PlayState.Run; PlayLength = DESHelper.FormatTime(dsArr[curNum].PlayLength); } else { if (PlayState == PlayState.Run) { curLength += 1000000; } if (curLength >= PlayLength) { RunTime += (int)dsArr[curNum].PlayLength; curNum++; curLength = 0; PlayState = PlayState.Next; if (curNum == dsArr.Length) { PlayState = PlayState.Stop; } if (des != null) { des.Stop(); } } Thread.Sleep(100); } } if (des != null) { des.Cancel(); } hWin.Refresh(); if (PlayListCompleted != null) { PlayListCompleted(this, ca); } }