PHP에서 PowerPoint 프레젠테이션을 비디오로 변환
소개
PowerPoint 프레젠테이션을 비디오로 변환하면 다음과 같은 혜택을 얻을 수 있습니다
- 접근성 향상: 프레젠테이션을 여는 애플리케이션에 비해 모든 기기(플랫폼에 관계없이)는 기본적으로 비디오 플레이어가 탑재되어 있어 사용자가 비디오를 열거나 재생하기가 더 쉽습니다.
- 도달 범위 확대: 비디오를 통해 많은 청중에게 도달하고, 프레젠테이션에서는 지루하게 느껴질 수 있는 정보를 전달할 수 있습니다. 대부분의 설문 조사와 통계에 따르면 사람들은 다른 형태의 콘텐츠보다 비디오를 더 많이 시청하고 소비하며, 일반적으로 이러한 콘텐츠를 선호합니다.
Aspose.Slides에서 PowerPoint를 비디오로 변환
Aspose.Slides는 프레젠테이션을 비디오로 변환하는 기능을 지원합니다.
- Aspose.Slides를 사용하여 특정 FPS(초당 프레임 수)에 해당하는 프레임 집합(프레젠테이션 슬라이드에서)을 생성합니다.
- ffmpeg과 같은 타사 유틸리티(for java)를 사용해 프레임을 기반으로 비디오를 생성합니다.
PowerPoint를 비디오로 변환
- POM 파일에 다음을 추가합니다:
<dependency>
<groupId>net.bramp.ffmpeg</groupId>
<artifactId>ffmpeg</artifactId>
<version>0.7.0</version>
</dependency>
```php
-
Download ffmpeg here.
-
Run the PowerPoint to video PHP code.
This PHP code shows you how to convert a presentation (containing a figure and two animation effects) to a video:
$presentation = new Presentation();
try {
# Adds a smile shape and then animates it
$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();
}
}
# Configure ffmpeg binaries folder. See this page: 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();
}
Video Effects
You can apply animations to objects on slides and use transitions between slides.
Animations and transitions make slideshows more engaging and interesting—and they do the same thing for videos. Let’s add another slide and transition to the code for the previous presentation:
# Adds a smile shape and animates it
# ...
# Adds a new slide and animated transition
$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 also supports animation for texts. So we animate paragraphs on objects, which will appear one after the other (with the delay set to a second):
$presentation = new Presentation();
try {
# Adds text and animations
$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();
}
}
# Configure ffmpeg binaries folder. See this page: 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();
}
Video Conversion Classes
To allow you to perform PowerPoint to video conversion tasks, Aspose.Slides provides the PresentationAnimationsGenerator and PresentationPlayer classes.
PresentationAnimationsGenerator allows you to set the frame size for the video (that will be created later) through its constructor. If you pass an instance of the presentation, Presentation::getSlideSize will be used and it generates animations that PresentationPlayer uses.
When animations are generated, a NewAnimation event is generated for each subsequent animation, which has the presentation animation player parameter. The latter is a class that represents a player for a separate animation.
To work with the presentation animation player, the getDuration (the full duration of the animation) and setTimePosition methods are used. Each animation position is set within the 0 to duration range, and then the getFrame method will return a BufferedImage that corresponds to the animation state at that moment:
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);// initial animation state
try {
# initial animation state bitmap
$animationPlayer->getFrame()->save("firstFrame.png", ImageFormat::Png);
} catch (JavaException $e) {
}
$animationPlayer->setTimePosition($animationPlayer->getDuration());// final state of the animation
try {
# last frame of the animation
$animationPlayer->getFrame()->save("lastFrame.png", ImageFormat::Png);
} catch (JavaException $e) {
}
}
}
$presentation = new Presentation();
try {
# Adds a smile shape and animates it
$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();
}
}
To make all animations in a presentation play at once, the PresentationPlayer class is used. This class takes a PresentationAnimationsGenerator instance and FPS for effects in its constructor and then calls the FrameTick event for all the animations to get them played:
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](https://docs.aspose.com/slides/ko/php-java/convert-powerpoint-to-video/#convert-powerpoint-to-video) 섹션을 참조하세요.
## **지원되는 애니메이션 및 효과**
**입장**:
| 애니메이션 유형 | Aspose.Slides | PowerPoint |
|---|---|---|
| **Appear** |  |  |
| **Fade** |  |  |
| **Fly In** |  |  |
| **Float In** |  |  |
| **Split** |  |  |
| **Wipe** |  |  |
| **Shape** |  |  |
| **Wheel** |  |  |
| **Random Bars** |  |  |
| **Grow & Turn** |  |  |
| **Zoom** |  |  |
| **Swivel** |  |  |
| **Bounce** |  |  |
**강조**:
| 애니메이션 유형 | Aspose.Slides | PowerPoint |
|---|---|---|
| **Pulse** |  |  |
| **Color Pulse** |  |  |
| **Teeter** |  |  |
| **Spin** |  |  |
| **Grow/Shrink** |  |  |
| **Desaturate** |  |  |
| **Darken** |  |  |
| **Lighten** |  |  |
| **Transparency** |  |  |
| **Object Color** |  |  |
| **Complementary Color** |  |  |
| **Line Color** |  |  |
| **Fill Color** |  |  |
**퇴장**:
| 애니메이션 유형 | Aspose.Slides | PowerPoint |
|---|---|---|
| **Disappear** |  |  |
| **Fade** |  |  |
| **Fly Out** |  |  |
| **Float Out** |  |  |
| **Split** |  |  |
| **Wipe** |  |  |
| **Shape** |  |  |
| **Random Bars** |  |  |
| **Shrink & Turn** |  |  |
| **Zoom** |  |  |
| **Swivel** |  |  |
| **Bounce** |  |  |
**모션 경로**:
| 애니메이션 유형 | Aspose.Slides | PowerPoint |
|---|---|---|
| **Lines** |  |  |
| **Arcs** |  |  |
| **Turns** |  |  |
| **Shapes** |  |  |
| **Loops** |  |  |
| **Custom Path** |  |  |
## **FAQ**
**비밀번호로 보호된 프레젠테이션을 변환할 수 있나요?**
네, Aspose.Slides를 사용하면 [비밀번호로 보호된 프레젠테이션](/slides/ko/php-java/password-protected-presentation/)을 작업할 수 있습니다. 이러한 파일을 처리할 때는 올바른 비밀번호를 제공해야 라이브러리가 프레젠테이션 내용에 접근할 수 있습니다.
**Aspose.Slides가 클라우드 솔루션에서 사용을 지원하나요?**
네, Aspose.Slides는 클라우드 애플리케이션 및 서비스에 통합될 수 있습니다. 이 라이브러리는 서버 환경에서 작동하도록 설계되어 파일의 일괄 처리에 높은 성능과 확장성을 보장합니다.
**변환 중에 프레젠테이션 크기 제한이 있나요?**
Aspose.Slides는 사실상 모든 크기의 프레젠테이션을 처리할 수 있습니다. 하지만 매우 큰 파일을 다룰 경우 추가 시스템 리소스가 필요할 수 있으며, 성능 향상을 위해 프레젠테이션을 최적화하는 것이 권장되기도 합니다.