Chuyển đổi PPT thành video

So với một bản trình bày PowerPoint (PPT hoặc PPTX), một video ( MP4) là định dạng tệp phổ biến hơn và dễ mở hơn trên đại đa số thiết bị và nền tảng. Do đó, khi bạn chuyển đổi PowerPoint thành video, nội dung của bạn sẽ trở nên dễ tiếp cận và chia sẻ hơn với lượng khán giả lớn hơn.

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

Trong bài viết này, chúng tôi dự định chỉ cho bạn cách chuyển đổi PPT thành video trong C++.

Nhận hai API để chuyển đổi PPT thành video

Tạo video trong PowerPoint

Trước tiên, để chuyển đổi bản trình bày PowerPoint thành video theo chương trình, bạn cần có hai API sau:

  • Aspose.Slides for C++. This API allows you to generate a set of frames based on the slides in your PowerPoint presentation. Aspose.Slides for C++ is a popular API for creating, editing, converting, and manipulating PowerPoint presentations (without Microsoft PowerPoint or Office). See this Installation article to install it.
  • ffmpeg. API này cho phép bạn tạo video dựa trên các trang trình bày đã tạo. Tải xuống tại đây.

Thông tin: Bạn có thể muốn xem Aspose miễn phí Trình chuyển đổi PowerPoint sang video vì đây là triển khai trực tiếp của thao tác PowerPoint sang video được mô tả trong bài viết này. Trình chuyển đổi cho phép người dùng tạo các video tuyệt đẹp từ các bài thuyết trình.

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

  1. Thêm đường dẫn đến ffmpeg.exe vào biến môi trường PATH.
  2. Chạy mã C++ từ PowerPoint sang video.

Mã C++ này chỉ cho bạn cách chuyển đổi PPT thành video:

void OnFrameTick(System::SharedPtr<PresentationPlayer> sender, System::SharedPtr<FrameTickEventArgs> args)
{
    System::String fileName = System::String::Format(u"frame_{0}.png", sender->get_FrameIndex());
    args->GetFrame()->Save(fileName);
}

void Run()
{
    auto presentation = System::MakeObject<Presentation>();
    auto slide = presentation->get_Slide(0);

    // Thêm hình dạng nụ cười và sau đó tạo hoạt ảnh cho nó
    System::SharedPtr<IAutoShape> smile = slide->get_Shapes()->AddAutoShape(ShapeType::SmileyFace, 110.0f, 20.0f, 500.0f, 500.0f);
    auto sequence = slide->get_Timeline()->get_MainSequence();
    System::SharedPtr<IEffect> effectIn = sequence->AddEffect(smile, EffectType::Fly, EffectSubtype::TopLeft, EffectTriggerType::AfterPrevious);
    System::SharedPtr<IEffect> effectOut = sequence->AddEffect(smile, EffectType::Fly, EffectSubtype::BottomRight, EffectTriggerType::AfterPrevious);
    effectIn->get_Timing()->set_Duration(2.0f);
    effectOut->set_PresetClassType(EffectPresetClassType::Exit);

    const int32_t fps = 33;

    auto animationsGenerator = System::MakeObject<PresentationAnimationsGenerator>(presentation);
    auto player = System::MakeObject<PresentationPlayer>(animationsGenerator, fps);
    player->FrameTick += OnFrameTick;
    animationsGenerator->Run(presentation->get_Slides());

    const System::String ffmpegParameters = System::String::Format(
        u"-loglevel {0} -framerate {1} -i {2} -y -c:v {3} -pix_fmt {4} {5}",
        u"warning", m_fps, "frame_%d.png", u"libx264", u"yuv420p", "video.mp4");
    auto ffmpegProcess = System::Diagnostics::Process::Start(u"ffmpeg", ffmpegParameters);
    ffmpegProcess->WaitForExit();
}

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

Hoạt ảnh và hiệu ứng cải thiện mức độ hấp dẫn và tỷ lệ thu hút cho các bài thuyết trình và trình chiếu. Chúng có hiệu ứng tương tự trên video, đặc biệt là những video được tạo từ bản trình bày PowerPoint, vì vậy bạn có thể muốn sử dụng hiệu ứng trong video. Aspose.Slides cho phép bạn thực hiện chính xác điều đó bằng cách cung cấp PresentationAnimationsGenerator, [PresentationPlayer](https:// http://reference.aspose.com/slides/cpp/class/aspose.slides.export.presentationplayer/) và các loại và lớp có liên quan khác.

Ví dụ: nếu bạn quyết định sử dụng hoạt ảnh và hiệu ứng trong video, bạn có thể thêm một trang chiếu khác và chuyển đổi mã cho bản trình bày 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

System::SharedPtr<ISlide> newSlide = presentation->get_Slides()->AddEmptySlide(presentation->get_Slide(0)->get_LayoutSlide());

System::SharedPtr<IBackground> slideBackground = newSlide->get_Background();

slideBackground->set_Type(BackgroundType::OwnBackground);

auto fillFormat = slideBackground->get_FillFormat();

fillFormat->set_FillType(FillType::Solid);

fillFormat->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Indigo());

newSlide->get_SlideShowTransition()->set_Type(TransitionType::Push);

Sau đó, bạn có thể áp dụng cài đặt hoạt ảnh cho các đoạn trên đối tượng để làm cho các đối tượng đó lần lượt xuất hiện (với độ trễ giữa các lần xuất hiện được đặt thành một giây):

void OnFrameTick(System::SharedPtr<PresentationPlayer> sender, System::SharedPtr<FrameTickEventArgs> args)
{
    System::String fileName = System::String::Format(u"frame_{0}.png", sender->get_FrameIndex());
    args->GetFrame()->Save(fileName);
}

void Run()
{
    auto presentation = System::MakeObject<Presentation>();
    auto slide = presentation->get_Slide(0);

    // Thêm văn bản và hình ảnh động
    System::SharedPtr<IAutoShape> autoShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 210.0f, 120.0f, 300.0f, 300.0f);
    System::SharedPtr<Paragraph> para1 = System::MakeObject<Paragraph>();
    para1->get_Portions()->Add(System::MakeObject<Portion>(u"Aspose Slides for C++"));
    System::SharedPtr<Paragraph> para2 = System::MakeObject<Paragraph>();
    para2->get_Portions()->Add(System::MakeObject<Portion>(u"convert PowerPoint Presentation with text to video"));

    System::SharedPtr<Paragraph> para3 = System::MakeObject<Paragraph>();
    para3->get_Portions()->Add(System::MakeObject<Portion>(u"paragraph by paragraph"));
    auto paragraphs = autoShape->get_TextFrame()->get_Paragraphs();
    paragraphs->Add(para1);
    paragraphs->Add(para2);
    paragraphs->Add(para3);
    paragraphs->Add(System::MakeObject<Paragraph>());

    auto sequence = slide->get_Timeline()->get_MainSequence();
    System::SharedPtr<IEffect> effect = sequence->AddEffect(para1, EffectType::Appear, EffectSubtype::None, EffectTriggerType::AfterPrevious);

    System::SharedPtr<IEffect> effect2 = sequence->AddEffect(para2, EffectType::Appear, EffectSubtype::None, EffectTriggerType::AfterPrevious);

    System::SharedPtr<IEffect> effect3 = sequence->AddEffect(para3, EffectType::Appear, EffectSubtype::None, EffectTriggerType::AfterPrevious);

    System::SharedPtr<IEffect> effect4 = sequence->AddEffect(para3, EffectType::Appear, EffectSubtype::None, EffectTriggerType::AfterPrevious);

    effect->get_Timing()->set_TriggerDelayTime(1.0f);
    effect2->get_Timing()->set_TriggerDelayTime(1.0f);
    effect3->get_Timing()->set_TriggerDelayTime(1.0f);
    effect4->get_Timing()->set_TriggerDelayTime(1.0f);

    // Chuyển đổi khung thành video
    const int32_t fps = 33;

    auto animationsGenerator = System::MakeObject<PresentationAnimationsGenerator>(presentation);
    auto player = System::MakeObject<PresentationPlayer>(animationsGenerator, fps);
    
    player->FrameTick += OnFrameTick;
    animationsGenerator->Run(presentation->get_Slides());

    const System::String ffmpegParameters = System::String::Format(
        u"-loglevel {0} -framerate {1} -i {2} -y -c:v {3} -pix_fmt {4} {5}",
        u"warning", m_fps, "frame_%d.png", u"libx264", u"yuv420p", "video.mp4");
    auto ffmpegProcess = System::Diagnostics::Process::Start(u"ffmpeg", ffmpegParameters);
    ffmpegProcess->WaitForExit();
}

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

Nếu bạn đang muốn dùng thử không giới hạn các tính năng của Aspose.Slides, chúng tôi khuyên bạn nên nhận giấy phép tạm thời miễn phí.

Phần kết luận

Sau khi đã hướng dẫn bạn các thao tác trong bài viết này, chúng tôi tin rằng bây giờ bạn đã biết cách chuyển đổi PPT thành video trong C++

Để tìm hiểu thêm về [tính năng] của Aspose.Slides(https://docs.aspose.com/slides/cpp/features-overview/), hãy xem [tài liệu] của chúng tôi(https://docs.aspose.com/slides/cpp/). 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