PHP で PowerPoint プレゼンテーションをビデオに変換する
PowerPoint プレゼンテーションをビデオに変換することで、次のメリットが得られます
- アクセシビリティの向上: すべてのデバイス(プラットフォームに関係なく)は、プレゼンテーションを開くアプリケーションに比べてデフォルトでビデオプレーヤーが装備されているため、ユーザーはビデオの開封や再生が容易になります。
- リーチの拡大: ビデオを通じて、多くの視聴者にリーチし、プレゼンテーションでは退屈に感じられる情報を提供できます。ほとんどの調査や統計では、人々は他のコンテンツ形態よりもビデオを見る・消費する傾向があり、一般的にビデオコンテンツを好むことが示されています。
Aspose.Slides の PowerPoint からビデオへの変換
Aspose.Slides 22.11で、プレゼンテーションからビデオへの変換サポートを実装しました。
- Aspose.Slides を使用して、特定の FPS(フレーム/秒)に対応するフレームセット(プレゼンテーションのスライドから)を生成します
- ffmpeg のようなサードパーティユーティリティ(for java)を使用して、フレームからビデオを作成します
PowerPoint をビデオに変換
- POM ファイルに以下を追加します:
<dependency>
<groupId>net.bramp.ffmpeg</groupId>
<artifactId>ffmpeg</artifactId>
<version>0.7.0</version>
</dependency>
```php
-
ffmpeg をhereからダウンロードします。
-
PowerPoint からビデオへの PHP コードを実行します。
この PHP コードは、図と 2 つのアニメーション効果を含むプレゼンテーションをビデオに変換する方法を示しています。
$presentation = new Presentation();
try {
# 笑顔のシェイプを追加し、アニメーションを付けます
$smile = $presentation->getSlides()->get_Item(0)->getShapes()->addAutoShape(ShapeType::SmileyFace, 110, 20, 500, 500);
$mainSequence = $presentation->getSlides()->get_Item(0)->getTimeline()->getMainSequence();
$effectIn = $mainSequence->addEffect($smile, EffectType::Fly, EffectSubType::TopLeft, EffectTriggerType::AfterPrevious);
$effectOut = $mainSequence->addEffect($smile, EffectType::Fly, EffectSubType::BottomRight, EffectTriggerType::AfterPrevious);
$effectIn->getTiming()->setDuration(2.0);
$effectOut->setPresetClassType(EffectPresetClassType::Exit);
$fps = 33;
class FrameTick {
function invoke($sender, $arg) {
try {
$frame = sprintf("frame_%04d.png", $sender->getFrameIndex());
$arguments->getFrame()->save($frame, ImageFormat::Png);
$frames->add($frame);
} catch (JavaException $e) {
}
}
}
$frames = new Java("java.util.ArrayList");
$animationsGenerator = new PresentationAnimationsGenerator($presentation);
try {
$player = new PresentationPlayer($animationsGenerator, $fps);
try {
$frameTick = java_closure(new FrameTick(), null, java("com.aspose.slides.PresentationPlayerFrameTick"));
$player->setFrameTick($frameTick);
$animationsGenerator->run($presentation->getSlides());
} finally {
if (!java_is_null($player)) {
$player->dispose();
}
}
} finally {
if (!java_is_null($animationsGenerator)) {
$animationsGenerator->dispose();
}
}
# ffmpeg バイナリフォルダを設定します。このページをご参照ください: https://github.com/rosenbjerg/FFMpegCore#installation
$ffmpeg = new Java("net.bramp.ffmpeg.builder.FFmpeg", "path/to/ffmpeg");
$ffprobe = new Java("net.bramp.ffmpeg.builder.FFprobe", "path/to/ffprobe");
$builder = (new Java("net.bramp.ffmpeg.builder.FFmpegBuilder"))->addExtraArgs("-start_number", "1")->setInput("frame_%04d.png")->addOutput("output.avi")->setVideoFrameRate(FFmpeg->FPS_24)->setFormat("avi")->done();
$executor = new Java("net.bramp.ffmpeg.builder.FFmpegExecutor", $ffmpeg, $ffprobe);
$executor->createJob($builder)->run();
} catch (JavaException $e) {
$e->printStackTrace();
}
ビデオ エフェクト
スライド上のオブジェクトにアニメーションを適用したり、スライド間の遷移を使用したりできます。
アニメーションと遷移は、スライドショーをより魅力的で面白くし、ビデオでも同様の効果があります。前回のプレゼンテーションのコードにもう一枚のスライドと遷移を追加してみましょう:
# 笑顔のシェイプを追加してアニメーションします
# ...
# 新しいスライドを追加し、アニメーション遷移を設定します
$newSlide = $presentation->getSlides()->addEmptySlide($presentation->getSlides()->get_Item(0)->getLayoutSlide());
$newSlide->getBackground()->setType(BackgroundType::OwnBackground);
$newSlide->getBackground()->getFillFormat()->setFillType(FillType::Solid);
$newSlide->getBackground()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->MAGENTA);
$newSlide->getSlideShowTransition()->setType(TransitionType::Push);
Aspose.Slides はテキストのアニメーションもサポートしています。オブジェクト上の段落をアニメーションさせ、1 秒の遅延で順次表示されるようにします:
$presentation = new Presentation();
try {
# テキストとアニメーションを追加します
$autoShape = $presentation->getSlides()->get_Item(0)->getShapes()->addAutoShape(ShapeType::Rectangle, 210, 120, 300, 300);
$para1 = new Paragraph();
$para1->getPortions()->add(new Portion("Aspose Slides for Java"));
$para2 = new Paragraph();
$para2->getPortions()->add(new Portion("convert PowerPoint Presentation with text to video"));
$para3 = new Paragraph();
$para3->getPortions()->add(new Portion("paragraph by paragraph"));
$paragraphCollection = $autoShape->getTextFrame()->getParagraphs();
$paragraphCollection->add($para1);
$paragraphCollection->add($para2);
$paragraphCollection->add($para3);
$paragraphCollection->add(new Paragraph());
$mainSequence = $presentation->getSlides()->get_Item(0)->getTimeline()->getMainSequence();
$effect1 = $mainSequence->addEffect($para1, EffectType::Appear, EffectSubType::None, EffectTriggerType::AfterPrevious);
$effect2 = $mainSequence->addEffect($para2, EffectType::Appear, EffectSubType::None, EffectTriggerType::AfterPrevious);
$effect3 = $mainSequence->addEffect($para3, EffectType::Appear, EffectSubType::None, EffectTriggerType::AfterPrevious);
$effect4 = $mainSequence->addEffect($para3, EffectType::Appear, EffectSubType::None, EffectTriggerType::AfterPrevious);
$effect1->getTiming()->setTriggerDelayTime(1.0);
$effect2->getTiming()->setTriggerDelayTime(1.0);
$effect3->getTiming()->setTriggerDelayTime(1.0);
$effect4->getTiming()->setTriggerDelayTime(1.0);
$fps = 33;
class FrameTick {
function invoke($sender, $arg) {
try {
$frame = sprintf("frame_%04d.png", $sender->getFrameIndex());
$arguments->getFrame()->save($frame, ImageFormat::Png);
$frames->add($frame);
} catch (JavaException $e) {
}
}
}
$frames = new Java("java.util.ArrayList");
$animationsGenerator = new PresentationAnimationsGenerator($presentation);
try {
$player = new PresentationPlayer($animationsGenerator, $fps);
try {
$frameTick = java_closure(new FrameTick(), null, java("com.aspose.slides.PresentationPlayerFrameTick"));
$player->setFrameTick($frameTick);
$animationsGenerator->run($presentation->getSlides());
} finally {
if (!java_is_null($player)) {
$player->dispose();
}
}
} finally {
if (!java_is_null($animationsGenerator)) {
$animationsGenerator->dispose();
}
}
# ffmpeg バイナリフォルダを設定します。このページをご参照ください: https://github.com/rosenbjerg/FFMpegCore#installation
$ffmpeg = new Java("net.bramp.ffmpeg.builder.FFmpeg", "path/to/ffmpeg");
$ffprobe = new Java("net.bramp.ffmpeg.builder.FFprobe", "path/to/ffprobe");
$builder = (new Java("net.bramp.ffmpeg.builder.FFmpegBuilder"))->addExtraArgs("-start_number", "1")->setInput("frame_%04d.png")->addOutput("output.avi")->setVideoFrameRate(FFmpeg->FPS_24)->setFormat("avi")->done();
$executor = new Java("net.bramp.ffmpeg.builder.FFmpegExecutor", $ffmpeg, $ffprobe);
$executor->createJob($builder)->run();
} catch (JavaException $e) {
$e->printStackTrace();
}
ビデオ変換クラス
PowerPoint からビデオへの変換タスクを実行できるように、Aspose.Slides はPresentationAnimationsGeneratorとPresentationPlayerクラスを提供します。
PresentationAnimationsGenerator は、コンストラクタでビデオのフレームサイズ(後で作成される)を設定できるようにします。プレゼンテーションのインスタンスを渡すと、Presentation.SlideSize が使用され、PresentationPlayer が使用するアニメーションが生成されます。
アニメーションが生成されると、各アニメーションごとに NewAnimation イベントが生成され、IPresentationAnimationPlayer パラメータが渡されます。後者は、個別のアニメーションのプレーヤーを表すクラスです。
IPresentationAnimationPlayer を使用するには、アニメーションの全長を示すDurationプロパティとSetTimePositionメソッドを使用します。各アニメーション位置は0 から durationの範囲で設定され、GetFrame メソッドはその時点のアニメーション状態に対応する BufferedImage を返します:
use aspose\slides\Presentation;
use aspose\slides\PresentationPlayer;
use aspose\slides\PresentationAnimationsGenerator;
use aspose\slides\ImageFormat;
use aspose\slides\ShapeType;
use aspose\slides\EffectType;
use aspose\slides\EffectSubtype;
use aspose\slides\EffectTriggerType;
use aspose\slides\EffectPresetClassType;
class PresentationAnimationPlayer {
function invoke($animationPlayer) {
echo(sprintf("Animation total duration: %f", $animationPlayer->getDuration()));
$animationPlayer->setTimePosition(0);// 初期アニメーション状態
try {
# 初期アニメーション状態ビットマップ
$animationPlayer->getFrame()->save("firstFrame.png", ImageFormat::Png);
} catch (JavaException $e) {
}
$animationPlayer->setTimePosition($animationPlayer->getDuration());// アニメーションの最終状態
try {
# アニメーションの最終フレーム
$animationPlayer->getFrame()->save("lastFrame.png", ImageFormat::Png);
} catch (JavaException $e) {
}
}
}
$presentation = new Presentation();
try {
# 笑顔のシェイプを追加し、アニメーションを付けます
$smile = $presentation->getSlides()->get_Item(0)->getShapes()->addAutoShape(ShapeType::SmileyFace, 110, 20, 500, 500);
$mainSequence = $presentation->getSlides()->get_Item(0)->getTimeline()->getMainSequence();
$effectIn = $mainSequence->addEffect($smile, EffectType::Fly, EffectSubtype::TopLeft, EffectTriggerType::AfterPrevious);
$effectOut = $mainSequence->addEffect($smile, EffectType::Fly, EffectSubtype::BottomRight, EffectTriggerType::AfterPrevious);
$effectIn->getTiming()->setDuration(2.0);
$effectOut->setPresetClassType(EffectPresetClassType::Exit);
$animationsGenerator = new PresentationAnimationsGenerator($presentation);
$presentationAnimation=java_closure(new PresentationAnimationPlayer(), null, java("com.aspose.slides.PresentationAnimationsGeneratorNewAnimation"));
try {
$animationsGenerator->setNewAnimation($presentationAnimation);
} finally {
if (!java_is_null($animationsGenerator)) {
$animationsGenerator->dispose();
}
}
} finally {
if (!java_is_null($presentation)) {
$presentation->dispose();
}
}
プレゼンテーション内のすべてのアニメーションを同時に再生するには、PresentationPlayer クラスを使用します。このクラスは、PresentationAnimationsGenerator のインスタンスとエフェクト用の FPS をコンストラクタに渡し、すべてのアニメーションに対して FrameTick イベントを呼び出して再生させます:
class FrameTick {
function invoke($sender, $arg) {
try {
$arguments->getFrame()->save("frame_" . $sender->getFrameIndex() . ".png", ImageFormat::Png);
} catch (JavaException $e) {
}
}
}
$presentation = new Presentation("animated.pptx");
try {
$animationsGenerator = new PresentationAnimationsGenerator($presentation);
try {
$player = new PresentationPlayer($animationsGenerator, 33);
try {
$frameTick = java_closure(new FrameTick(), null, java("com.aspose.slides.PresentationPlayerFrameTick"));
$player->setFrameTick($frameTick);
$animationsGenerator->run($presentation->getSlides());
} finally {
if (!java_is_null($player)) {
$player->dispose();
}
}
} finally {
if (!java_is_null($animationsGenerator)) {
$animationsGenerator->dispose();
}
}
} finally {
if (!java_is_null($presentation)) {
$presentation->dispose();
}
}
生成されたフレームは、ビデオを作成するためにコンパイルできます。詳細はConvert PowerPoint to Videoセクションをご参照ください。
サポートされているアニメーションとエフェクト
Entrance:
| アニメーションタイプ | Aspose.Slides | PowerPoint |
|---|---|---|
| Appear | ![]() |
![]() |
| Fade | ![]() |
![]() |
| Fly In | ![]() |
![]() |
| Float In | ![]() |
![]() |
| Split | ![]() |
![]() |
| Wipe | ![]() |
![]() |
| Shape | ![]() |
![]() |
| Wheel | ![]() |
![]() |
| Random Bars | ![]() |
![]() |
| Grow & Turn | ![]() |
![]() |
| Zoom | ![]() |
![]() |
| Swivel | ![]() |
![]() |
| Bounce | ![]() |
![]() |
Emphasis:
| アニメーションタイプ | Aspose.Slides | PowerPoint |
|---|---|---|
| Pulse | ![]() |
![]() |
| Color Pulse | ![]() |
![]() |
| Teeter | ![]() |
![]() |
| Spin | ![]() |
![]() |
| Grow/Shrink | ![]() |
![]() |
| Desaturate | ![]() |
![]() |
| Darken | ![]() |
![]() |
| Lighten | ![]() |
![]() |
| Transparency | ![]() |
![]() |
| Object Color | ![]() |
![]() |
| Complementary Color | ![]() |
![]() |
| Line Color | ![]() |
![]() |
| Fill Color | ![]() |
![]() |
Exit:
| アニメーションタイプ | Aspose.Slides | PowerPoint |
|---|---|---|
| Disappear | ![]() |
![]() |
| Fade | ![]() |
![]() |
| Fly Out | ![]() |
![]() |
| Float Out | ![]() |
![]() |
| Split | ![]() |
![]() |
| Wipe | ![]() |
![]() |
| Shape | ![]() |
![]() |
| Random Bars | ![]() |
![]() |
| Shrink & Turn | ![]() |
![]() |
| Zoom | ![]() |
![]() |
| Swivel | ![]() |
![]() |
| Bounce | ![]() |
![]() |
Motion Paths:
| アニメーションタイプ | Aspose.Slides | PowerPoint |
|---|---|---|
| Lines | ![]() |
![]() |
| Arcs | ![]() |
![]() |
| Turns | ![]() |
![]() |
| Shapes | ![]() |
![]() |
| Loops | ![]() |
![]() |
| Custom Path | ![]() |
![]() |
よくある質問
パスワードで保護されたプレゼンテーションを変換できますか?
はい、Aspose.Slides ではpassword-protected presentationsを扱うことができます。このようなファイルを処理する際は、正しいパスワードを提供してライブラリがプレゼンテーションの内容にアクセスできるようにする必要があります。
Aspose.Slides はクラウドソリューションでの使用をサポートしていますか?
はい、Aspose.Slides はクラウドアプリケーションやサービスに統合できます。このライブラリはサーバー環境で動作するよう設計されており、ファイルのバッチ処理において高いパフォーマンスとスケーラビリティを保証します。
変換時にプレゼンテーションのサイズ制限はありますか?
Aspose.Slides は事実上あらゆるサイズのプレゼンテーションを扱うことができます。ただし、非常に大きなファイルを処理する場合は追加のシステムリソースが必要になることがあり、パフォーマンス向上のためにプレゼンテーションを最適化することが推奨される場合があります。

