/// <summary> /// Function:Get VideoLayerCollection /// Description: /// Author:Kevin /// Date:2008-7-2 /// </summary> /// <param name="layers">collection of layers</param> /// <returns>VideoLayerCollection</returns> public VideoLayerCollection PopulateDataBatchLoad(ShapeLayer[] layers) { _videoLayers = new VideoLayerCollection(); long PlayLength = 0; if (layers == null || layers.Length < 1) { return(_videoLayers); } _level = 0; foreach (ShapeLayer layer in layers) { if (layer.IsVisible) { AppendLayer(layer); if (layer.EndTime > PlayLength) { PlayLength = (long)layer.EndTime; } } } //CheckMarquee(); _videoLayers.PlayLength = PlayLength; return(_videoLayers); }
private VideoLayerCollection PopulateData(ShapeLayer[] layers) { int level = 0; VideoLayerCollection videoLayers = new VideoLayerCollection(); Layer layer; long PlayLength = 0; if (layers == null || layers.Length < 1) { return(videoLayers); } foreach (var item in layers) { if (item.IsVisible) { if (item.Shape.Type != ShapeType.Temperature && item.Shape.Type != ShapeType.Time) { //item.Accept(Visitor); //layer = item.ToVideoLayer(); layer = DESLayerConverter.Instance.Convert(item); layer.Level = level++; videoLayers.Add(layer); } if (item.EndTime > PlayLength) { PlayLength = (long)item.EndTime; } } } videoLayers.PlayLength = PlayLength; return(videoLayers); }
private VideoLayerCollection PopulateData(ShapeLayer[] layers) { var _videoLayers = new VideoLayerCollection(); long PlayLength = 0; if (layers == null || layers.Length < 1) { return(_videoLayers); } _level = 0; foreach (ShapeLayer layer in layers) { if (!layer.IsEmpty) { if (AppendLayer(_videoLayers, layer)) { if (layer.EndTime > PlayLength) { PlayLength = (long)layer.EndTime; } } } } //CheckMarquee(); _videoLayers.PlayLength = PlayLength; return(_videoLayers); }
public Play(VideoLayerCollection myDS, Size VideoSize) { ds = myDS; MoveSize = VideoSize; ds.Sort(new SortComparer <Layer>("Level", false)); des = new DESCombine(DESConsts.FPS, DESConsts.BitCount, MoveSize.Width, MoveSize.Height, ds); DynamicTextDS = ds.FindAll(DynamicTextLayer); }
/// <summary> /// 构造和初始播放视频的数据 /// </summary> /// <param name="ds"></param> /// <param name="myWin"></param> public Play(VideoLayerCollection myDS, DESVideoCallBack pVideoCallback, Control myWin) { hWin = myWin; ds = myDS; pVideo = pVideoCallback; ds.Sort(new SortComparer <Layer>("Level", false)); des = new DESCombine(DESConsts.FPS, DESConsts.BitCount, hWin.Width, hWin.Height, ds); DynamicTextDS = ds.FindAll(DynamicTextLayer); }
public DESGroup(AMMediaType mType, IAMTimeline pTimeline, VideoLayerCollection ds, int hWinWidth, int hWinHeight) { int hr; IAMTimelineObj pGroupObj; IAMTimelineGroup pGroup; m_Width = hWinWidth; m_Height = hWinHeight; m_Length = 0; m_Files = new List <MediaFile>(); m_pTimeline = pTimeline; for (int i = 0; i < ds.Count; i++) { if (ds[i].EndTime > m_MaxLength) { m_MaxLength = ds[i].EndTime; } } m_MaxLength = m_MaxLength == 0 ? ds.PlayLength : m_MaxLength; if (ds.PlayLength <= m_MaxLength) { m_RepeatNums = 1; } else { m_RepeatNums = ds.PlayLength / m_MaxLength + (ds.PlayLength % m_MaxLength == 0 ? 0 : 1); } // make the root group/composition hr = m_pTimeline.CreateEmptyNode(out pGroupObj, TimelineMajorType.Group); DESError.ThrowExceptionForHR(hr); try { 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); List <Layer> ImageDS = ds.FindAll(ImageLayer); m_TrackArr = new IAMTimelineTrack[m_RepeatNums * ImageDS.Count + 2]; m_CompArr = new IAMTimelineComp[m_RepeatNums * ImageDS.Count + 2]; AddCompAndTrack(ds, pGroup); } finally { Marshal.ReleaseComObject(pGroupObj); } }
private bool AppendLayer(VideoLayerCollection layers, ShapeLayer layer) { Layer videoLayer = DESLayerConverter.Instance.Convert(layer); //layer.ToVideoLayer(); if (videoLayer == null) { return(false); } videoLayer.Level = _level++; layers.Add(videoLayer); return(true); }
//add by michael 2008-12-8 private VideoLayerCollection NewLayer(MessageInfo mes, long playLength, string ParentName, bool isNewStart, LibraryType?groupType) { VideoLayerCollection layer = null; foreach (ShapeLayer sl in mes.Items) { //sl.Shape.VirtualBounds = Common.CommonHelper.GetRectangleBySign(sl.Shape.VirtualBounds, sl.Shape.SignSize, _playlistControl._signSize, mes.Zoom); //sl.Shape.DestBounds = Common.CommonHelper.GetRectangleBySign(sl.Shape.DestBounds, sl.Shape.SignSize, _playlistControl._signSize, mes.Zoom); if (sl.Shape.Type == ShapeType.ShapeDraw) { foreach (ShapePaint s in (sl.Shape as ShapeDraw).Childs) { s.VirtualBounds = Common.CommonHelper.GetVirtualBoundsBySign(s, _playlistControl._signSize, _playlistControl._Zoom); s.Populate(s.VirtualLocation, s.VirtualBounds.Size, ControlService.SignCombo.Current.Type, _playlistControl._signSize, _playlistControl._Zoom); } (sl.Shape as ShapeDraw).PopulateSignInfo(ControlService.SignCombo.Current.Type, _playlistControl._signSize, sl.Shape.Zoom); } else { sl.Shape.VirtualBounds = Common.CommonHelper.GetVirtualBoundsBySign(sl.Shape, _playlistControl._signSize, _playlistControl._Zoom); sl.Shape.Populate(sl.Shape.VirtualLocation, sl.Shape.VirtualBounds.Size, ControlService.SignCombo.Current.Type, _playlistControl._signSize, _playlistControl._Zoom); if (sl.Shape.Type == ShapeType.Image) { (sl.Shape as ShapeImage).ComputeDestBoundBatchLoad(); } if (sl.Shape.Type == ShapeType.Video) { (sl.Shape as ShapeVideo).ComputeDestBound(); } //sl.Shape.DestBounds = Common.CommonHelper.GetRectangleBySign(sl.Shape.DestBounds, sl.Shape.SignSize, _playlistControl._signSize, _playlistControl._Zoom); } //sl.Shape.VirtualBounds = Common.CommonHelper.GetRectangleBySign(sl.Shape.VirtualBounds, sl.Shape.SignSize, _playlistControl._signSize, _playlistControl._Zoom); } layer = _desHelper.PopulateData(ReverseLayer(mes.Items)); layer.SignType = ControlService.SignCombo.SignType; //item.VideoSize = new Size(ControlService.SignCombo.Current.Width, ControlService.SignCombo.Current.Height); layer.VideoSize = _playlistControl.playPanel.Size; layer.Name = mes.Name; layer.Zoom = _playlistControl._Zoom; layer.BackColor = mes.BackColor; layer.PlayLength = playLength; layer.ParentName = ParentName; layer.EmphasisEffect = mes.EmphasisEffect; layer.IsNewStart = isNewStart; layer.GroupType = groupType; return(layer); }
/// <summary> /// Time:2008-12-10 /// Author:michael /// Function: Create Video /// </summary> /// <param name="mes"></param> /// <param name="fileurl"></param> public static bool CreateVideo(MessageInfo mes, string fileurl) { bool result = false; VideoLayerCollection video = null; video = PopulateData(mes.Items); video.BackColor = mes.BackColor; video.SignType = SignType.RGB; video.VideoSize = new Size(mes.Size.Width / mes.Zoom, mes.Size.Height / mes.Zoom); video.Name = mes.Name; video.Zoom = 1; video.PlayLength = mes.Length; video.ParentName = ""; video.EmphasisEffect = mes.EmphasisEffect; Play MyPlay = new Play(video, video.VideoSize); result = MyPlay.OutputVideo(fileurl, 0, video.PlayLength); MyPlay.Dispose(); return(result); }
private int getNextNodeId(int oldNodeId, string oldNodeParentName) { TreeListNode oldNode = treeList1.FindNodeByID(oldNodeId); int nodeId = oldNodeId; while (true) { VideoLayerCollection message = treeList1.FindNodeByID(++nodeId).GetValue("Message") as VideoLayerCollection; if (message == null) // for the case parent node { break; } if (message.ParentName != oldNodeParentName) // for the case Message { break; } } if (nodeId == oldNodeId + 1) { return(nodeId); } return(nodeId - 1); }
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)); }
public VideoLayerCollection[] OnPlay() { VideoLayerCollection[] videoArr = new VideoLayerCollection[] { _desHelper.PopulateData(_messageControl) }; return(videoArr); }