翻譯|使用教程|編輯:胡濤|2023-06-15 10:36:28.767|閱讀 375 次
概述:在本文中,我們打算引導您完成以編程方式執行PPT到MP4轉換任務的操作,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Slides 是一款 PowerPoint管理API,用于讀取,編寫,操作和轉換PowerPoint幻燈片的獨立API,可將PowerPoint轉換為PDF,PDF/A,XPS,TIFF,HTML,ODP和其他PowerPoint格式。
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
從 PowerPoint 演示文稿派生的視頻在展示數據可視化和營銷產品方面非常有效。它還非常擅長向廣泛的受眾群體傳遞不同類型的信息。鑒于與標準演示文稿相比與真實視頻播放相關的好處,在許多情況下將 PPT 轉換為視頻是有意義的。
在本文中,我們打算引導您完成以編程方式執行PPT到MP4轉換任務的操作。請參閱下面的C# 中如何將 PPT 轉換為視頻。
視頻由幀組成,因此 PowerPoint 到視頻的轉換過程需要您做兩件事:
根據演示幻燈片生成一組幀。Aspose.Slides for .NET在這里派上用場。要安裝Aspose.Slides for .NET,請下載軟件
根據生成的幀創建視頻。這就是 ffmpeg(和 .NET 的 ffmpeg 核心)的用武之地——下載 ffmpeg 。
信息: Aspose 提供免費的PowerPoint 到視頻轉換器,允許將 PowerPoint 演示文稿轉換為視頻。您可能希望看到此轉換器,因為它是此處流程的實時實現。
通過以下方式將 Aspose.Slides for .NET 和 FFMpegCore 添加到您的項目中dotnet add package command:
以這種方式指定您之前獲得的 ffmpeg 的路徑(例如,您將其解壓縮到“C:\tools\ffmpeg”):GlobalFFOptions.Configure(new FFOptions { BinaryFolder = @"c:\tools\ffmpeg\bin",} );
運行將 PowerPoint 轉換為視頻的代碼:
using System.Collections.Generic; using Aspose.Slides; using FFMpegCore; // Will use FFmpeg binaries we extracted to "c:\tools\ffmpeg" before using Aspose.Slides.Animation; using (Presentation presentation = new Presentation()) { // Adds a smile shape and then animates it IAutoShape smile = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.SmileyFace, 110, 20, 500, 500); IEffect effectIn = presentation.Slides[0].Timeline.MainSequence.AddEffect(smile, EffectType.Fly, EffectSubtype.TopLeft, EffectTriggerType.AfterPrevious); IEffect effectOut = presentation.Slides[0].Timeline.MainSequence.AddEffect(smile, EffectType.Fly, EffectSubtype.BottomRight, EffectTriggerType.AfterPrevious); effectIn.Timing.Duration = 2f; effectOut.PresetClassType = EffectPresetClassType.Exit; const int Fps = 33; List<string> frames = new List<string>(); using (var animationsGenerator = new PresentationAnimationsGenerator(presentation)) using (var player = new PresentationPlayer(animationsGenerator, Fps)) { player.FrameTick += (sender, args) => { string frame = $"frame_{(sender.FrameIndex):D4}.png"; args.GetFrame().Save(frame); frames.Add(frame); }; animationsGenerator.Run(presentation.Slides); } // Configure ffmpeg binaries folder. See this page: //github.com/rosenbjerg/FFMpegCore#installation GlobalFFOptions.Configure(new FFOptions { BinaryFolder = @"c:\tools\ffmpeg\bin", }); // Converts frames to webm video FFMpeg.JoinImageSequence("smile.webm", Fps, frames.Select(frame => ImageInfo.FromPath(frame)).ToArray()); }
包含過渡和動畫的演示文稿通常比沒有這些效果的演示文稿更具吸引力和趣味性。同樣的原則也適用于視頻——簡單地快速連續滑動的視頻有時不會被剪掉。
Aspose.Slides 支持常見的過渡和動畫,因此您可以在視頻中應用和使用這些效果。假設我們繼續使用上一節中的代碼,我們可以通過這種方式進行另一張幻燈片和一個過渡:
// Adds a smile shape and animates it // ... // Adds a new slide and animated transition ISlide newSlide = presentation.Slides.AddEmptySlide(presentation.Slides[0].LayoutSlide); newSlide.Background.Type = BackgroundType.OwnBackground; newSlide.Background.FillFormat.FillType = FillType.Solid; newSlide.Background.FillFormat.SolidFillColor.Color = Color.Indigo; newSlide.SlideShowTransition.Type = TransitionType.Push; 除了幻燈片動畫,Aspose.Slides 還允許您為文本添加動畫。這樣,您就可以為對象上的段落設置動畫,使它們一個接一個地出現(例如,將延遲設置為一秒): using System.Collections.Generic; using Aspose.Slides.Export; using Aspose.Slides; using FFMpegCore; using Aspose.Slides.Animation; using (Presentation presentation = new Presentation()) { // Adds text and animations IAutoShape autoShape = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 210, 120, 300, 300); Paragraph para1 = new Paragraph(); para1.Portions.Add(new Portion("Aspose Slides for .NET")); Paragraph para2 = new Paragraph(); para2.Portions.Add(new Portion("convert PowerPoint Presentation with text to video")); Paragraph para3 = new Paragraph(); para3.Portions.Add(new Portion("paragraph by paragraph")); autoShape.TextFrame.Paragraphs.Add(para1); autoShape.TextFrame.Paragraphs.Add(para2); autoShape.TextFrame.Paragraphs.Add(para3); autoShape.TextFrame.Paragraphs.Add(new Paragraph()); IEffect effect = presentation.Slides[0].Timeline.MainSequence.AddEffect(para1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); IEffect effect2 = presentation.Slides[0].Timeline.MainSequence.AddEffect(para2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); IEffect effect3 = presentation.Slides[0].Timeline.MainSequence.AddEffect(para3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); IEffect effect4 = presentation.Slides[0].Timeline.MainSequence.AddEffect(para3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); effect.Timing.TriggerDelayTime = 1f; effect2.Timing.TriggerDelayTime = 1f; effect3.Timing.TriggerDelayTime = 1f; effect4.Timing.TriggerDelayTime = 1f; // Converts frames to video const int Fps = 33; List<string> frames = new List<string>(); using (var animationsGenerator = new PresentationAnimationsGenerator(presentation)) using (var player = new PresentationPlayer(animationsGenerator, Fps)) { player.FrameTick += (sender, args) => { string frame = $"frame_{(sender.FrameIndex):D4}.png"; args.GetFrame().Save(frame); frames.Add(frame); }; animationsGenerator.Run(presentation.Slides); } // Configure ffmpeg binaries folder. See this page: //github.com/rosenbjerg/FFMpegCore#installation GlobalFFOptions.Configure(new FFOptions { BinaryFolder = @"c:\tools\ffmpeg\bin", }); // Converts frames to webm video FFMpeg.JoinImageSequence("text_animation.webm", Fps, frames.Select(frame => ImageInfo.FromPath(frame)).ToArray()); }
以上便是如何在C#中將PPT轉換為視頻 ,如您還有關于產品相關方面的疑問,可以繼續瀏覽本系列其他內容,也歡迎您加入我們的交流群發表您遇到的問題。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn