تبدیل ارائههای PowerPoint به ویدیو در Android
معرفی
با تبدیل ارائهٔ PowerPoint خود به ویدئو، میتوانید
- افزایش دسترسیپذیری: تمام دستگاهها (صرفنظر از پلتفرم) بهصورت پیشفرض دارای پلیرهای ویدئویی هستند در مقایسه با برنامههای بازکن ارائه، بنابراین کاربران راحتتر میتوانند ویدئوها را باز یا پخش کنند.
- دستیابی بیشتر: از طریق ویدئوها میتوانید به مخاطبان وسیعی دست یابید و اطلاعاتی را به آنها ارائه دهید که در یک ارائه ممکن است خستهکننده به نظر برسد. اکثر نظرسنجیها و آمارها نشان میدهند که مردم ویدئوها را نسبت به سایر انواع محتوا بیشتر تماشا و مصرف میکنند و عموماً این نوع محتوا را ترجیح میدهند.
تبدیل PowerPoint به ویدئو در Aspose.Slides
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>
-
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();
}
افکتهای ویدئویی
میتوانید انیمیشنها را بر روی اشیاء اسلایدها اعمال کنید و از انتقالها بین اسلایدها استفاده کنید.
انیمیشنها و انتقالها نمایش اسلایدها را جذابتر و جالبتر میکنند — و همینطور برای ویدئوها نیز صدق میکند. بیایید اسلاید دیگری و یک انتقال به کد ارائه قبلی اضافه کنیم:
// یک شکل لبخند اضافه میکند و آن را انیمیشن میدهد
// ...
// یک اسلاید جدید اضافه میکند و انتقال انیمیشنشده
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();
}
کلاسهای تبدیل ویدئو
برای انجام وظایف تبدیل 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 {
// bitmap وضعیت اولیه انیمیشن
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();
}
سپس فریمهای تولیدشده میتوانند بهمنظور ساخت یک ویدئو ترکیب شوند. بخش تبدیل PowerPoint به ویدئو را ببینید.
انیمیشنها و افکتهای پشتیبانیشده
ورودی:
| نوع انیمیشن | 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 | ![]() |
![]() |
سوالات متداول
آیا امکان تبدیل ارائههای دارای رمز عبور وجود دارد؟
بله، Aspose.Slides امکان کار با ارائههای دارای رمز عبور را فراهم میکند. هنگام پردازش چنین فایلهایی باید رمز عبور صحیح را ارائه دهید تا کتابخانه بتواند به محتوای ارائه دسترسی پیدا کند.
آیا Aspose.Slides از استفاده در راهحلهای ابری پشتیبانی میکند؟
بله، Aspose.Slides میتواند در برنامهها و سرویسهای ابری یکپارچه شود. این کتابخانه برای کار در محیطهای سروری طراحی شده است و عملکرد بالا و مقیاسپذیری را برای پردازش انبوه فایلها تضمین میکند.
آیا محدودیت اندازهای برای ارائهها هنگام تبدیل وجود دارد؟
Aspose.Slides قادر به پردازش ارائههای با اندازه تقریباً هر چه باشد است. با این حال، هنگام کار با فایلهای بسیار بزرگ ممکن است نیاز به منابع سیستمی بیشتری باشد و گاهی توصیه میشود تا بهبود عملکرد، ارائه را بهینهسازی کنید.

