public void AddVideo(SlidePart slidepart, string videoFilePath, string videoCoverPath, D.Transform2D transform) { Slide slide = slidepart.Slide; ShapeTree shapeTree1 = slidepart.Slide.CommonSlideData.ShapeTree; var ptrlid = Doc.PresentationPart.GetIdOfPart(slidepart); var picID = AnalysisHelper.GetMaxId(shapeTree1); string imgEmbedId = string.Format("imgId{0}{1}{2}", ptrlid, picID, 1); string videoEmbedId = string.Format("vidId{0}{1}{2}", ptrlid, picID, 2); string mediaEmbedId = string.Format("medId{0}{1}{2}", ptrlid, picID, 3); Picture picture1 = new Picture(); NonVisualPictureProperties nonVisualPictureProperties1 = new NonVisualPictureProperties(); NonVisualDrawingProperties nonVisualDrawingProperties2 = new NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = videoEmbedId + "" }; D.HyperlinkOnClick hyperlinkOnClick1 = new D.HyperlinkOnClick() { Id = "", Action = "ppaction://media" }; nonVisualDrawingProperties2.Append(hyperlinkOnClick1); NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 = new NonVisualPictureDrawingProperties(); D.PictureLocks pictureLocks1 = new D.PictureLocks() { NoChangeAspect = true }; nonVisualPictureDrawingProperties1.Append(pictureLocks1); ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties2 = new ApplicationNonVisualDrawingProperties(); D.VideoFromFile videoFromFile1 = new D.VideoFromFile() { Link = videoEmbedId }; ApplicationNonVisualDrawingPropertiesExtensionList applicationNonVisualDrawingPropertiesExtensionList1 = new ApplicationNonVisualDrawingPropertiesExtensionList(); ApplicationNonVisualDrawingPropertiesExtension applicationNonVisualDrawingPropertiesExtension1 = new ApplicationNonVisualDrawingPropertiesExtension() { Uri = "{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}" }; P14.Media media1 = new P14.Media() { Embed = mediaEmbedId }; media1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main"); applicationNonVisualDrawingPropertiesExtension1.Append(media1); applicationNonVisualDrawingPropertiesExtensionList1.Append(applicationNonVisualDrawingPropertiesExtension1); applicationNonVisualDrawingProperties2.Append(videoFromFile1); applicationNonVisualDrawingProperties2.Append(applicationNonVisualDrawingPropertiesExtensionList1); nonVisualPictureProperties1.Append(nonVisualDrawingProperties2); nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1); nonVisualPictureProperties1.Append(applicationNonVisualDrawingProperties2); BlipFill blipFill1 = new BlipFill(); D.Blip blip1 = new D.Blip() { Embed = imgEmbedId }; D.Stretch stretch1 = new D.Stretch(); D.FillRectangle fillRectangle1 = new D.FillRectangle(); stretch1.Append(fillRectangle1); blipFill1.Append(blip1); blipFill1.Append(stretch1); ShapeProperties shapeProperties1 = new ShapeProperties(); D.PresetGeometry presetGeometry1 = new D.PresetGeometry() { Preset = D.ShapeTypeValues.Rectangle }; D.AdjustValueList adjustValueList1 = new D.AdjustValueList(); presetGeometry1.Append(adjustValueList1); shapeProperties1.Append(transform); shapeProperties1.Append(presetGeometry1); picture1.Append(nonVisualPictureProperties1); picture1.Append(blipFill1); picture1.Append(shapeProperties1); shapeTree1.Append(picture1); if (!(slide.Timing?.ChildElements?.Count > 0)) { AnalysisHelper.InitTiming(slide); } ImagePart imagePart = slidepart.AddImagePart(AnalysisHelper.GetImagePartType(videoCoverPath), imgEmbedId); using (var data = File.OpenRead(videoCoverPath)) { imagePart.FeedData(data); }; Doc.PartExtensionProvider.AddPartExtension("video/mp4", ".mp4"); MediaDataPart mediaDataPart1 = Doc.CreateMediaDataPart("video/mp4", ".mp4"); using (System.IO.Stream mediaDataPart1Stream = File.OpenRead(videoFilePath)) { mediaDataPart1.FeedData(mediaDataPart1Stream); } slidepart.AddVideoReferenceRelationship(mediaDataPart1, videoEmbedId); slidepart.AddMediaReferenceRelationship(mediaDataPart1, mediaEmbedId); slide.Save(); }