用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 转换为其他格式的文件