Converter apresentações PowerPoint em vídeo em C++
Introdução
Ao converter sua apresentação PowerPoint em vídeo, você obtém
- Aumento da acessibilidade: Todos os dispositivos (independentemente da plataforma) vêm equipados com reprodutores de vídeo por padrão, ao contrário dos aplicativos de abertura de apresentação, portanto os usuários acham mais fácil abrir ou reproduzir vídeos.
- Maior alcance: Por meio de vídeos, você pode alcançar um grande público e direcioná‑lo com informações que de outra forma poderiam parecer cansativas em uma apresentação. A maioria das pesquisas e estatísticas sugere que as pessoas assistem e consomem vídeos mais do que outras formas de conteúdo, e geralmente preferem esse tipo de conteúdo.
No Aspose.Slides 22.11, implementamos suporte à conversão de apresentações em vídeo.
- Use o Aspose.Slides para gerar um conjunto de quadros (a partir dos slides da apresentação) que correspondam a um determinado FPS (quadros por segundo)
- Use um utilitário de terceiros como
ffmpegpara criar um vídeo baseado nos quadros.
Converter uma Apresentação PowerPoint em Vídeo
- Baixe o ffmpeg aqui.
- Adicione o caminho para
ffmpeg.exeà variável de ambientePATH. - Execute o código de conversão de PowerPoint para vídeo.
Este código C++ mostra como converter uma apresentação (contendo uma figura e dois efeitos de animação) em um vídeo:
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);
// Adiciona uma forma de sorriso e então anima-a
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();
}
Efeitos de Vídeo
Você pode aplicar animações a objetos nos slides e usar transições entre os slides.
Animações e transições tornam as apresentações de slides mais envolventes e interessantes — e fazem o mesmo com vídeos. Vamos adicionar outro slide e transição ao código da apresentação anterior:
// Adiciona uma forma de sorriso e a anima
// ...
// Adiciona um novo slide e transição animada
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);
O Aspose.Slides também suporta animação para textos. Assim, animamos parágrafos em objetos, que aparecerão um após o outro (com o atraso definido em um segundo):
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);
// Adiciona texto e animações
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);
// Converte quadros em vídeo
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();
}
Classes de Conversão de Vídeo
Para permitir que você execute tarefas de conversão de PowerPoint para vídeo, o Aspose.Slides fornece as classes PresentationAnimationsGenerator e PresentationPlayer.
PresentationAnimationsGenerator permite definir o tamanho do quadro para o vídeo (que será criado posteriormente) por meio de seu construtor. Se você passar uma instância da apresentação, Presentation.SlideSize será usada e ele gera animações que PresentationPlayer utiliza.
Quando as animações são geradas, um evento NewAnimation é disparado para cada animação subsequente, que tem o parâmetro IPresentationAnimationPlayer. Este último é uma classe que representa um reprodutor para uma animação separada.
Para trabalhar com IPresentationAnimationPlayer, são usados a propriedade get_Duration (a duração total da animação) e o método SetTimePosition. Cada posição de animação é definida dentro da faixa 0 to duration, e então o método GetFrame retornará um Bitmap que corresponde ao estado da animação naquele momento.
void OnNewAnimation(System::SharedPtr<IPresentationAnimationPlayer> animationPlayer)
{
System::Console::WriteLine(u"Total animation duration: {0}", animationPlayer->get_Duration());
animationPlayer->SetTimePosition(0);
// estado inicial da animação
System::SharedPtr<System::Drawing::Bitmap> bitmap = animationPlayer->GetFrame();
// bitmap do estado inicial da animação
animationPlayer->SetTimePosition(animationPlayer->get_Duration());
// estado final da animação
System::SharedPtr<System::Drawing::Bitmap> lastBitmap = animationPlayer->GetFrame();
// último quadro da animação
lastBitmap->Save(u"last.png");
}
void Run()
{
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
// Adiciona uma forma de sorriso e a anima
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);
auto animationsGenerator = System::MakeObject<PresentationAnimationsGenerator>(presentation);
animationsGenerator->NewAnimation += OnNewAnimation;
}
Para fazer com que todas as animações de uma apresentação sejam reproduzidas simultaneamente, usa‑se a classe PresentationPlayer. Essa classe recebe uma instância de PresentationAnimationsGenerator e FPS para os efeitos em seu construtor e, em seguida, chama o evento FrameTick para todas as animações, permitindo que sejam reproduzidas:
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>(u"animated.pptx");
auto animationsGenerator = System::MakeObject<PresentationAnimationsGenerator>(presentation);
auto player = System::MakeObject<PresentationPlayer>(animationsGenerator, 33);
player->FrameTick += OnFrameTick;
animationsGenerator->Run(presentation->get_Slides());
}
Então, os quadros gerados podem ser compilados para produzir um vídeo. Veja a seção Convert PowerPoint to Video.
Animações e Efeitos Compatíveis
Entrada:
| Tipo de Animação | Aspose.Slides | PowerPoint |
|---|---|---|
| Appear | ![]() |
![]() |
| Fade | ![]() |
![]() |
| Fly In | ![]() |
![]() |
| Float In | ![]() |
![]() |
| Split | ![]() |
![]() |
| Wipe | ![]() |
![]() |
| Shape | ![]() |
![]() |
| Wheel | ![]() |
![]() |
| Random Bars | ![]() |
![]() |
| Grow & Turn | ![]() |
![]() |
| Zoom | ![]() |
![]() |
| Swivel | ![]() |
![]() |
| Bounce | ![]() |
![]() |
Ênfase:
| Tipo de Animação | Aspose.Slides | PowerPoint |
|---|---|---|
| Pulse | ![]() |
![]() |
| Color Pulse | ![]() |
![]() |
| Teeter | ![]() |
![]() |
| Spin | ![]() |
![]() |
| Grow/Shrink | ![]() |
![]() |
| Desaturate | ![]() |
![]() |
| Darken | ![]() |
![]() |
| Lighten | ![]() |
![]() |
| Transparency | ![]() |
![]() |
| Object Color | ![]() |
![]() |
| Complementary Color | ![]() |
![]() |
| Line Color | ![]() |
![]() |
| Fill Color | ![]() |
![]() |
Saída:
| Tipo de Animação | Aspose.Slides | PowerPoint |
|---|---|---|
| Disappear | ![]() |
![]() |
| Fade | ![]() |
![]() |
| Fly Out | ![]() |
![]() |
| Float Out | ![]() |
![]() |
| Split | ![]() |
![]() |
| Wipe | ![]() |
![]() |
| Shape | ![]() |
![]() |
| Random Bars | ![]() |
![]() |
| Shrink & Turn | ![]() |
![]() |
| Zoom | ![]() |
![]() |
| Swivel | ![]() |
![]() |
| Bounce | ![]() |
![]() |
Caminhos de Movimento:
| Tipo de Animação | Aspose.Slides | PowerPoint |
|---|---|---|
| Lines | ![]() |
![]() |
| Arcs | ![]() |
![]() |
| Turns | ![]() |
![]() |
| Shapes | ![]() |
![]() |
| Loops | ![]() |
![]() |
| Custom Path | ![]() |
![]() |
FAQ
É possível converter apresentações protegidas por senha?
Sim, o Aspose.Slides permite trabalhar com apresentações protegidas por senha. Ao processar esses arquivos, você precisa fornecer a senha correta para que a biblioteca possa acessar o conteúdo da apresentação.
O Aspose.Slides oferece suporte ao uso em soluções de nuvem?
Sim, o Aspose.Slides pode ser integrado a aplicativos e serviços em nuvem. A biblioteca foi projetada para operar em ambientes de servidor, garantindo alto desempenho e escalabilidade para o processamento em lote de arquivos.
Existem limitações de tamanho para apresentações durante a conversão?
O Aspose.Slides é capaz de lidar com apresentações de praticamente qualquer tamanho. No entanto, ao trabalhar com arquivos muito grandes, recursos adicionais do sistema podem ser necessários, e às vezes é recomendado otimizar a apresentação para melhorar o desempenho.

