翻譯|使用教程|編輯:胡濤|2023-06-15 10:36:28.767|閱讀 389 次
概述:在本文中,我們打算引導(dǎo)您完成以編程方式執(zhí)行PPT到MP4轉(zhuǎn)換任務(wù)的操作,歡迎查閱~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.Slides 是一款 PowerPoint管理API,用于讀取,編寫,操作和轉(zhuǎn)換PowerPoint幻燈片的獨(dú)立API,可將PowerPoint轉(zhuǎn)換為PDF,PDF/A,XPS,TIFF,HTML,ODP和其他PowerPoint格式。
Aspose API支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
從 PowerPoint 演示文稿派生的視頻在展示數(shù)據(jù)可視化和營銷產(chǎn)品方面非常有效。它還非常擅長向廣泛的受眾群體傳遞不同類型的信息。鑒于與標(biāo)準(zhǔn)演示文稿相比與真實(shí)視頻播放相關(guān)的好處,在許多情況下將 PPT 轉(zhuǎn)換為視頻是有意義的。
在本文中,我們打算引導(dǎo)您完成以編程方式執(zhí)行PPT到MP4轉(zhuǎn)換任務(wù)的操作。請參閱下面的C# 中如何將 PPT 轉(zhuǎn)換為視頻。
視頻由幀組成,因此 PowerPoint 到視頻的轉(zhuǎn)換過程需要您做兩件事:
根據(jù)演示幻燈片生成一組幀。Aspose.Slides for .NET在這里派上用場。要安裝Aspose.Slides for .NET,請下載軟件
根據(jù)生成的幀創(chuàng)建視頻。這就是 ffmpeg(和 .NET 的 ffmpeg 核心)的用武之地——下載 ffmpeg 。
信息: Aspose 提供免費(fèi)的PowerPoint 到視頻轉(zhuǎn)換器,允許將 PowerPoint 演示文稿轉(zhuǎn)換為視頻。您可能希望看到此轉(zhuǎn)換器,因?yàn)樗谴颂幜鞒痰膶?shí)時(shí)實(shí)現(xiàn)。
通過以下方式將 Aspose.Slides for .NET 和 FFMpegCore 添加到您的項(xiàng)目中dotnet add package command:
以這種方式指定您之前獲得的 ffmpeg 的路徑(例如,您將其解壓縮到“C:\tools\ffmpeg”):GlobalFFOptions.Configure(new FFOptions { BinaryFolder = @"c:\tools\ffmpeg\bin",} );
運(yùn)行將 PowerPoint 轉(zhuǎn)換為視頻的代碼:
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()); }
包含過渡和動(dòng)畫的演示文稿通常比沒有這些效果的演示文稿更具吸引力和趣味性。同樣的原則也適用于視頻——簡單地快速連續(xù)滑動(dòng)的視頻有時(shí)不會(huì)被剪掉。
Aspose.Slides 支持常見的過渡和動(dòng)畫,因此您可以在視頻中應(yīng)用和使用這些效果。假設(shè)我們繼續(xù)使用上一節(jié)中的代碼,我們可以通過這種方式進(jìn)行另一張幻燈片和一個(gè)過渡:
// 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; 除了幻燈片動(dòng)畫,Aspose.Slides 還允許您為文本添加動(dòng)畫。這樣,您就可以為對象上的段落設(shè)置動(dòng)畫,使它們一個(gè)接一個(gè)地出現(xiàn)(例如,將延遲設(shè)置為一秒): 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轉(zhuǎn)換為視頻 ,如您還有關(guān)于產(chǎn)品相關(guān)方面的疑問,可以繼續(xù)瀏覽本系列其他內(nèi)容,也歡迎您加入我們的交流群發(fā)表您遇到的問題。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn