Chuyển đổi PPT thành video trong C#

API .NET đa nền tảng mạnh mẽ để chuyển đổi PowerPoint thành video bằng mã C# trên Nền tảng NET Framework, .NET Core, Windows Azure, Mono hoặc Xamarin

Chuyển đổi PowerPoint sang video bằng Aspose.Slides

Aspose.Slides for .NET là một thư viện .NET mạnh mẽ được sử dụng để tạo, chỉnh sửa và thao tác với bản trình bày cũng như chuyển đổi bản trình bày PowerPoint sang các tài liệu khác và video. Trong trường hợp này, để chuyển đổi PowerPoint thành video, bạn cần sử dụng Aspose.Slides cùng với ffmpegFFMpegCore (một trình bao bọc ffmpeg NET miễn phí).

Đây là cách hoạt động của quá trình chuyển đổi PPT sang video: Aspose.Slides được sử dụng để tạo một tập hợp các khung (từ các trang trình bày) và sau đó FFMpegCore (ffmpeg) được sử dụng để tạo video dựa trên các khung.

Cách chuyển đổi PPT sang video

  1. Cài đặt Aspose.Slides cho .NETFFMpegcore: Chạy dotnet add package Aspose.Slides.NET --version 22.12.0 rồi chạy dotnet add package FFMpegCore --version 4.8.0

  2. Tải xuống ffmpeg tại đây.

  3. FFMpegCore yêu cầu bạn chỉ định đường dẫn đến ffmpeg đã tải xuống (ví dụ: được trích xuất vào “C:\tools\ffmpeg”): GlobalFFOptions.Configure(FFOptions mới { BinaryFolder = @"c:\tools\ffmpeg\bin",} );

  4. Sao chép, dán, rồi chạy mã PowerPoint sang video.

Chuyển PowerPoint sang video trong C#

Sử dụng mã này để chuyển đổi PPT sang video:

Mã C# để chuyển đổi PowerPoint sang 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());

}

Các chuyển đổi được hỗ trợ khác

Bạn cũng có thể chuyển đổi PowerPoint sang các tệp ở các định dạng khác