用C++將PPT轉成視頻
強大的跨平台 C++ API,用於使用 C++ 代碼將 PowerPoint 轉換為視頻
使用 Aspose.Slides 將 PowerPoint 轉換為視頻
Aspose.Slides for C++ 是一個功能強大的 C++ 庫,用於創建、編輯和操作演示文稿,並將 PowerPoint 演示文稿轉換為其他文檔和視頻.在這種情況下,要將 PowerPoint 轉換為視頻,您需要使用 Aspose.Slides 和 ffmpeg。
這就是 PPT 到視頻轉換過程的工作原理:Aspose.Slides 用於生成一組幀(從演示幻燈片),然後 FFMpegCore (ffmpeg) 用於創建基於幀的視頻。
在 C++ 中將 PowerPoint 轉換為視頻
使用此 C++ 代碼將 PPT 轉換為視頻:
用於將 PowerPoint 轉換為視頻的 C++ 代碼
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);
// Adds a smile shape and then animates it
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();
}
其他支持的轉換
您還可以將 PowerPoint 轉換為其他格式的文件