C# で PPTX をビデオに変換する

NET Framework、.NET Core、Windows Azure、Mono、または Xamarin プラットフォームで C# コードを使用して PowerPoint をビデオに変換するための強力なクロスプラットフォーム .NET API

Aspose.Slides を使用して PowerPoint をビデオに変換する

Aspose.Slides for .NET は、プレゼンテーションを作成、編集、操作したり、PowerPoint プレゼンテーションを他のドキュメントに変換したりするために使用される強力な .NET ライブラリです。そしてビデオ。この場合、PowerPoint をビデオに変換するには、ffmpeg および FFMpegCore (無料の NET ffmpeg ラッパー) とともに Aspose.Slides を使用する必要があります。

これは、PPTX からビデオへの変換プロセスの仕組みです。Aspose.Slides を使用して (プレゼンテーション スライドから) 一連のフレームを生成し、次に FFMpegCore (ffmpeg) を使用してフレームに基づいてビデオを作成します。

PPTXをビデオに変換する方法

  1. Aspose.Slides for .NET および FFMpegcore をインストールします。「dotnet add package Aspose.Slides.NET –version 22.12.0」を実行してから、「dotnet add package FFMpegCore –version 4.8.0」を実行します。

  2. ffmpeg をダウンロード こちら

  3. FFMpegCore では、ダウンロードした ffmpeg へのパス (例: 「C:\tools\ffmpeg」に抽出) を指定する必要があります。 GlobalFFOptions.Configure(new FFOptions { BinaryFolder = @"c:\tools\ffmpeg\bin",} );

  4. PowerPoint to video コードをコピーして貼り付け、実行します。

C# で PowerPoint をビデオに変換する

このコードを使用して PPTX をビデオに変換します。

PowerPoint をビデオに変換するための C# コード


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());

}

その他のサポートされている変換

PowerPoint を他の形式のファイルに変換することもできます