Tạo video trong PowerPoint

Một video bắt nguồn từ bản trình bày PowerPoint khá hiệu quả trong việc hiển thị trực quan hóa dữ liệu và tiếp thị sản phẩm. Nó cũng khá thành thạo trong việc cung cấp các loại thông điệp khác nhau cho nhiều đối tượng. Với những lợi ích liên quan đến việc phát lại video thực so với bản trình bày tiêu chuẩn, việc chuyển đổi PPT thành video trong nhiều tình huống là điều hợp lý.

Chuyển đổi PPT sang Video trong C#

Trong bài viết này, chúng tôi dự định hướng dẫn bạn một thao tác để thực hiện PPT thành MP4 tác vụ chuyển đổi theo chương trình. Xem cách chuyển đổi PPT thành video trong C# bên dưới.

API C# để chuyển đổi PPT thành video

Chuyển đổi PPT thành video

Một video bao gồm các khung, vì vậy quá trình chuyển đổi PowerPoint sang video yêu cầu bạn thực hiện hai việc:

  • Tạo một bộ khung dựa trên các slide thuyết trình. Aspose.Slides for .NET có ích ở đây. Để cài đặt Aspose.Slides for .NET, hãy xem Cài đặt.

  • tạo video dựa trên các khung đã tạo. Đây là lúc ffmpeg (và lõi ffmpeg cho .NET) xuất hiện—tải xuống ffmpeg tại đây.

Thông tin: Aspose cung cấp Bộ chuyển đổi PowerPoint sang video miễn phí cho phép chuyển đổi bản trình bày PowerPoint thành video. Bạn có thể muốn xem trình chuyển đổi này vì đây là quá trình triển khai trực tiếp tại đây.

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

  1. Thêm Aspose.Slides for .NET và FFMpegCore vào dự án của bạn thông qua lệnh dotnet add package:

    • Để thêm Aspose.Slides for .NET, hãy chạy dotnet add package Aspose.Slides.NET --version 22.11.0
    • Để thêm FFMpegCore, hãy chạy dotnet add package FFMpegCore --version 4.8.0
  2. Chỉ định đường dẫn đến ffmpeg mà bạn có trước đó (ví dụ: bạn đã giải nén nó vào “C:\tools\ffmpeg”) theo cách này: GlobalFFOptions.Configure(FFOptions mới { BinaryFolder = @"c:\tools\ffmpeg\bin" ,} );

  3. Chạy mã để 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())

{
    // Thêm hình dạng nụ cười và sau đó tạo hoạt ảnh cho nó
    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);
    }

    // Định cấu hình thư mục nhị phân ffmpeg. Xem trang này: https://github.com/rosenbjerg/FFMpegCore#installation
    GlobalFFOptions.Configure(new FFOptions { BinaryFolder = @"c:\tools\ffmpeg\bin", });
    // Chuyển đổi khung thành video webm
    FFMpeg.JoinImageSequence("smile.webm", Fps, frames.Select(frame => ImageInfo.FromPath(frame)).ToArray());

}

Áp dụng hiệu ứng và hoạt ảnh trong video

Các bài thuyết trình có chứa hiệu ứng chuyển tiếp và hoạt ảnh thường hấp dẫn và thú vị hơn những bài thuyết trình không có các hiệu ứng đó. Nguyên tắc tương tự cũng áp dụng cho video—một video chỉ đơn giản là trượt liên tiếp nhanh chóng đôi khi sẽ không cắt được.

Aspose.Slides hỗ trợ các hiệu ứng chuyển tiếp và hoạt ảnh phổ biến, vì vậy bạn có thể áp dụng và sử dụng các hiệu ứng đó trong video của mình. Giả sử chúng ta tiếp tục với đoạn mã từ phần trước, chúng ta có thể tạo một slide khác và chuyển đổi theo cách này:

// Thêm hình dạng nụ cười và tạo hoạt ảnh cho nó

// ...

// Thêm một trang trình bày mới và chuyển đổi hoạt hình

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;

Bên cạnh hoạt ảnh cho trang chiếu, Aspose.Slides cho phép bạn thêm hoạt ảnh cho văn bản. Bằng cách này, bạn có thể tạo hiệu ứng động cho các đoạn văn trên các đối tượng để làm cho chúng xuất hiện lần lượt (ví dụ: với độ trễ được đặt thành một giây):

using System.Collections.Generic;
using Aspose.Slides.Export;
using Aspose.Slides;
using FFMpegCore;
using Aspose.Slides.Animation;

using (Presentation presentation = new Presentation())
{
    // Thêm văn bản và hình ảnh động
    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;

    // Chuyển đổi khung thành 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);
    }
    // Định cấu hình thư mục nhị phân ffmpeg. Xem trang này: https://github.com/rosenbjerg/FFMpegCore#installation

    GlobalFFOptions.Configure(new FFOptions { BinaryFolder = @"c:\tools\ffmpeg\bin", });
    // Chuyển đổi khung thành video webm
    FFMpeg.JoinImageSequence("text_animation.webm", Fps, frames.Select(frame => ImageInfo.FromPath(frame)).ToArray());

}

Nhận giấy phép miễn phí

Bạn đang tìm cách dùng thử các tính năng của Aspose.Slides mà không bị giới hạn? Nhận giấy phép tạm thời miễn phí.

Phần kết luận

Tại thời điểm này, chúng tôi tin rằng bạn hiện đã biết cách chuyển đổi PowerPoint PPT thành video đơn giản hoặc video phức tạp hơn với hoạt ảnh, hiệu ứng chuyển tiếp và các hiệu ứng khác.

Để tìm hiểu thêm về của Aspose.Slides tính năng, hãy xem của chúng tôi tài liệu. Nếu có câu hỏi, bạn có thể đăng lên diễn đàn của chúng tôi.

Xem thêm