تبدیل ارائههای PowerPoint به ویدیو در Java
Introduction
با تبدیل ارائه PowerPoint یا OpenDocument خود به ویدیو، مزایای زیر را به دست میآورید:
دسترسی بیشتر: تمام دستگاهها، صرفنظر از پلتفرم، بهطور پیشفرض دارای پخشکننده ویدیو هستند، بنابراین برای کاربران آسانتر است که ویدیوها را باز یا پخش کنند نسبت به برنامههای ارائه سنتی.
دسترسپذیری گستردهتر: ویدیوها به شما امکان میدهند به مخاطبان بیشتری دسترسی پیدا کنید و اطلاعات را به شکل جذابتری ارائه دهید. نظرسنجیها و آمارها نشان میدهند که مردم ترجیح میدهند محتوای ویدیویی را نسبت به سایر فرمها تماشا و مصرف کنند، که پیام شما را تأثیرگذارتر میکند.
PowerPoint to Video Conversion in Aspose.Slides
در Aspose.Slides 22.11 ما پشتیبانی از تبدیل ارائه به ویدیو را پیادهسازی کردیم.
- از Aspose.Slides برای تولید مجموعهای از فریمها (از اسلایدهای ارائه) استفاده کنید که متناسب با FPS (فریم در ثانیه) معینی باشد
- از یک ابزار شخص ثالث مانند ffmpeg (for java) برای ایجاد ویدیو بر پایه فریمها استفاده کنید.
Convert PowerPoint to Video
- این موارد را به فایل POM خود اضافه کنید:
<dependency>
<groupId>net.bramp.ffmpeg</groupId>
<artifactId>ffmpeg</artifactId>
<version>0.7.0</version>
</dependency>
-
ffmpeg را اینجا دانلود کنید.
-
کد Java تبدیل PowerPoint به ویدیو را اجرا کنید.
این کد Java نشان میدهد چگونه یک ارائه (شامل یک نمودار و دو افکت انیمیشن) را به ویدیو تبدیل کنید:
Presentation presentation = new Presentation();
try {
// یک شکل لبخند اضافه میکند و سپس آن را انیمیشن میدهد
IAutoShape smile = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.SmileyFace, 110, 20, 500, 500);
ISequence mainSequence = presentation.getSlides().get_Item(0).getTimeline().getMainSequence();
IEffect effectIn = mainSequence.addEffect(smile, EffectType.Fly, EffectSubtype.TopLeft, EffectTriggerType.AfterPrevious);
IEffect effectOut = mainSequence.addEffect(smile, EffectType.Fly, EffectSubtype.BottomRight, EffectTriggerType.AfterPrevious);
effectIn.getTiming().setDuration(2f);
effectOut.setPresetClassType(EffectPresetClassType.Exit);
final int fps = 33;
ArrayList<String> frames = new ArrayList<String>();
PresentationAnimationsGenerator animationsGenerator = new PresentationAnimationsGenerator(presentation);
try
{
PresentationPlayer player = new PresentationPlayer(animationsGenerator, fps);
try {
player.setFrameTick((sender, arguments) ->
{
try {
String frame = String.format("frame_%04d.png", sender.getFrameIndex());
arguments.getFrame().save(frame, ImageFormat.Png);
frames.add(frame);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
animationsGenerator.run(presentation.getSlides());
} finally {
if (player != null) player.dispose();
}
} finally {
if (animationsGenerator != null) animationsGenerator.dispose();
}
// پیکربندی پوشه باینریهای ffmpeg. این صفحه را ببینید: https://github.com/rosenbjerg/FFMpegCore#installation
FFmpeg ffmpeg = new FFmpeg("path/to/ffmpeg");
FFprobe ffprobe = new FFprobe("path/to/ffprobe");
FFmpegBuilder builder = new FFmpegBuilder()
.addExtraArgs("-start_number", "1")
.setInput("frame_%04d.png")
.addOutput("output.avi")
.setVideoFrameRate(FFmpeg.FPS_24)
.setFormat("avi")
.done();
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
executor.createJob(builder).run();
} catch (IOException e) {
e.printStackTrace();
}
Video Effects
میتوانید انیمیشنها را بر روی اشیاء در اسلایدها اعمال کنید و از انتقالها بین اسلایدها استفاده کنید.
انیمیشنها و انتقالها نمایش اسلایدها را جذابتر و جالبتر میکنند—و برای ویدیوها نیز همین کار را انجام میدهند. بیایید یک اسلاید دیگر و یک انتقال به کد ارائه قبلی اضافه کنیم:
// یک شکل لبخند اضافه میکند و آن را انیمیشن میدهد
// ...
// یک اسلاید جدید اضافه میکند و انتقال انیمیشنی
ISlide 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(Color.MAGENTA);
newSlide.getSlideShowTransition().setType(TransitionType.Push);
Aspose.Slides همچنین از انیمیشن برای متنها پشتیبانی میکند. بنابراین ما پاراگرافهای روی اشیاء را انیمیشن میکنیم که یکی پس از دیگری ظاهر میشوند (با تاخیر تنظیمشده به یک ثانیه):
Presentation presentation = new Presentation();
try {
// متن و انیمیشنها را اضافه میکند
IAutoShape autoShape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 210, 120, 300, 300);
Paragraph para1 = new Paragraph();
para1.getPortions().add(new Portion("Aspose Slides for Java"));
Paragraph para2 = new Paragraph();
para2.getPortions().add(new Portion("convert PowerPoint Presentation with text to video"));
Paragraph para3 = new Paragraph();
para3.getPortions().add(new Portion("paragraph by paragraph"));
IParagraphCollection paragraphCollection = autoShape.getTextFrame().getParagraphs();
paragraphCollection.add(para1);
paragraphCollection.add(para2);
paragraphCollection.add(para3);
paragraphCollection.add(new Paragraph());
ISequence mainSequence = presentation.getSlides().get_Item(0).getTimeline().getMainSequence();
IEffect effect1 = mainSequence.addEffect(para1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
IEffect effect2 = mainSequence.addEffect(para2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
IEffect effect3 = mainSequence.addEffect(para3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
IEffect effect4 = mainSequence.addEffect(para3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
effect1.getTiming().setTriggerDelayTime(1f);
effect2.getTiming().setTriggerDelayTime(1f);
effect3.getTiming().setTriggerDelayTime(1f);
effect4.getTiming().setTriggerDelayTime(1f);
final int fps = 33;
ArrayList<String> frames = new ArrayList<String>();
PresentationAnimationsGenerator animationsGenerator = new PresentationAnimationsGenerator(presentation);
try
{
PresentationPlayer player = new PresentationPlayer(animationsGenerator, fps);
try {
player.setFrameTick((sender, arguments) ->
{
try {
String frame = String.format("frame_%04d.png", sender.getFrameIndex());
arguments.getFrame().save(frame, ImageFormat.Png);
frames.add(frame);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
animationsGenerator.run(presentation.getSlides());
} finally {
if (player != null) player.dispose();
}
} finally {
if (animationsGenerator != null) animationsGenerator.dispose();
}
// پیکربندی پوشه باینریهای ffmpeg. این صفحه را ببینید: https://github.com/rosenbjerg/FFMpegCore#installation
FFmpeg ffmpeg = new FFmpeg("path/to/ffmpeg");
FFprobe ffprobe = new FFprobe("path/to/ffprobe");
FFmpegBuilder builder = new FFmpegBuilder()
.addExtraArgs("-start_number", "1")
.setInput("frame_%04d.png")
.addOutput("output.avi")
.setVideoFrameRate(FFmpeg.FPS_24)
.setFormat("avi")
.done();
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
executor.createJob(builder).run();
} catch (IOException e) {
e.printStackTrace();
}
Video Conversion Classes
برای انجام وظایف تبدیل PowerPoint به ویدیو، Aspose.Slides کلاسهای PresentationAnimationsGenerator و PresentationPlayer را ارائه میدهد.
PresentationAnimationsGenerator به شما اجازه میدهد اندازه فریم برای ویدیو (که بعداً ساخته میشود) را از طریق سازندهاش تنظیم کنید. اگر نمونهای از ارائه را پاس دهید، Presentation.SlideSize استفاده میشود و انیمیشنهایی تولید میکند که PresentationPlayer استفاده میکند.
هنگامی که انیمیشنها تولید میشوند، یک رویداد NewAnimation برای هر انیمیشن بعدی ایجاد میشود که پارامتر IPresentationAnimationPlayer دارد. این کلاس نماینده یک پلیر برای انیمیشن جداگانه است.
برای کار با IPresentationAnimationPlayer، از ویژگی Duration (مدت کامل انیمیشن) و متد SetTimePosition استفاده میشود. هر موقعیت انیمیشن در بازه ۰ تا مدت تنظیم میشود و سپس متد GetFrame یک BufferedImage بر میگرداند که با وضعیت انیمیشن در آن لحظه مطابقت دارد:
Presentation presentation = new Presentation();
try {
// یک شکل لبخند اضافه میکند و آن را انیمیشن میدهد
IAutoShape smile = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.SmileyFace, 110, 20, 500, 500);
ISequence mainSequence = presentation.getSlides().get_Item(0).getTimeline().getMainSequence();
IEffect effectIn = mainSequence.addEffect(smile, EffectType.Fly, EffectSubtype.TopLeft, EffectTriggerType.AfterPrevious);
IEffect effectOut = mainSequence.addEffect(smile, EffectType.Fly, EffectSubtype.BottomRight, EffectTriggerType.AfterPrevious);
effectIn.getTiming().setDuration(2f);
effectOut.setPresetClassType(EffectPresetClassType.Exit);
PresentationAnimationsGenerator animationsGenerator = new PresentationAnimationsGenerator(presentation);
try {
animationsGenerator.setNewAnimation(animationPlayer ->
{
System.out.println(String.format("Animation total duration: %f", animationPlayer.getDuration()));
animationPlayer.setTimePosition(0); // حالت اولیه انیمیشن
try {
// نقشهبیتی حالت اولیه انیمیشن
animationPlayer.getFrame().save("firstFrame.png", ImageFormat.Png);
} catch (IOException e) {
throw new RuntimeException(e);
}
animationPlayer.setTimePosition(animationPlayer.getDuration()); // حالت نهایی انیمیشن
try {
// آخرین فریم انیمیشن
animationPlayer.getFrame().save("lastFrame.png", ImageFormat.Png);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} finally {
if (animationsGenerator != null) animationsGenerator.dispose();
}
} finally {
if (presentation != null) presentation.dispose();
}
برای پخش همزمان تمام انیمیشنهای یک ارائه، از کلاس PresentationPlayer استفاده میشود. این کلاس یک نمونه از PresentationAnimationsGenerator و FPS برای افکتها را در سازنده میگیرد و سپس برای تمام انیمیشنها رویداد FrameTick را صدا میزند تا آنها اجرا شوند:
Presentation presentation = new Presentation("animated.pptx");
try {
PresentationAnimationsGenerator animationsGenerator = new PresentationAnimationsGenerator(presentation);
try {
PresentationPlayer player = new PresentationPlayer(animationsGenerator, 33);
try {
player.setFrameTick((sender, arguments) ->
{
try {
arguments.getFrame().save("frame_" + sender.getFrameIndex() + ".png", ImageFormat.Png);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
animationsGenerator.run(presentation.getSlides());
} finally {
if (player != null) player.dispose();
}
} finally {
if (animationsGenerator != null) animationsGenerator.dispose();
}
} finally {
if (presentation != null) presentation.dispose();
}
سپس فریمهای تولید شده میتوانند ترکیب شوند تا یک ویدیو ساخته شود. بخش Convert PowerPoint to Video را ببینید.
Supported Animations and Effects
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 | ![]() |
![]() |
FAQ
آیا امکان تبدیل ارائههای دارای رمز عبور وجود دارد؟
بله، Aspose.Slides امکان کار با presentations protected by password را فراهم میکند. هنگام پردازش چنین فایلهایی، باید رمز عبور صحیح را ارائه دهید تا کتابخانه بتواند به محتوای ارائه دسترسی پیدا کند.
آیا Aspose.Slides از استفاده در راهحلهای ابری پشتیبانی میکند؟
بله، Aspose.Slides میتواند در برنامهها و سرویسهای ابری ادغام شود. این کتابخانه برای کار در محیطهای سرور طراحی شده است و عملکرد بالا و مقیاسپذیری را برای پردازش دستهای فایلها تضمین میکند.
آیا محدودیت اندازهای برای ارائهها هنگام تبدیل وجود دارد؟
Aspose.Slides قادر به پردازش ارائههایی با هر اندازهای است. اما هنگام کار با فایلهای بسیار بزرگ، ممکن است به منابع سیستمی بیشتری نیاز باشد و گاهی توصیه میشود برای بهبود عملکرد، ارائه را بهینهسازی کنید.

