Konvertera PPT till video i C#

Kraftfullt plattformsoberoende .NET API för att konvertera PowerPoint till video med C#-kod på NET Framework, .NET Core, Windows Azure, Mono eller Xamarin-plattformar

Konvertera PowerPoint till video med Aspose.Slides

Aspose.Slides för .NET är ett kraftfullt .NET-bibliotek som används för att skapa, redigera och manipulera presentationer och även konvertera PowerPoint-presentationer till andra dokument och videor. I det här fallet, för att konvertera PowerPoint till video, måste du använda Aspose.Slides vid sidan av ffmpeg och FFMPegCore (ett gratis NET ffmpeg-omslag).

Så här fungerar PPT till videokonverteringsprocessen: Aspose.Slides används för att generera en uppsättning bildrutor (från presentationsbilderna) och sedan används FFMpegCore (ffmpeg) för att skapa en video baserad på bildrutorna.

Hur man konverterar PPT till video

  1. Installera Aspose.Slides för .NET och FFMpegcore: Kör dotnet add package Aspose.Slides.NET --version 22.12.0 och kör sedan dotnet add package FFMpegCore --version 4.8.0

  2. Ladda ner ffmpeg här.

  3. FFMpegCore kräver att du anger sökvägen till den nedladdade ffmpeg (t.ex. extraherad till “C:\tools\ffmpeg”): GlobalFFOptions.Configure(new FFOptions { BinaryFolder = @"c:\tools\ffmpeg\bin",} );

  4. Kopiera, klistra in och kör sedan PowerPoint till videokod.

Konvertera PowerPoint till video i C#

Använd denna kod för att konvertera PPT till video:

C#-kod för att konvertera PowerPoint till video


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: https://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());

}

Andra omvandlingar som stöds

Du kan också konvertera PowerPoint till filer i andra format