แปลงงานนำเสนอ PowerPoint เป็นวิดีโอด้วย JavaScript
Introduction
โดยการแปลงงานนำเสนอ PowerPoint ของคุณเป็นวิดีโอ คุณจะได้รับ
- เพิ่มการเข้าถึง: อุปกรณ์ทั้งหมด (ไม่ว่าจะเป็นแพลตฟอร์มใด) มีเครื่องเล่นวิดีโอเป็นค่าเริ่มต้นเมื่อเทียบกับแอปพลิเคชันเปิดงานนำเสนอ ทำให้ผู้ใช้เปิดหรือเล่นวิดีโอง่ายขึ้น
- เพิ่มการเข้าถึงกลุ่มเป้าหมาย: ผ่านวิดีโอ คุณสามารถเข้าถึงผู้ชมจำนวนมากและให้ข้อมูลที่อาจดูน่าเบื่อในงานนำเสนอ คนส่วนใหญ่จากการสำรวจและสถิติแสดงว่าผู้คนมักดูและบริโภควิดีโอมากกว่ารูปแบบเนื้อหาอื่น ๆ และพวกเขามักชอบเนื้อหานี้
PowerPoint to Video Conversion in Aspose.Slides
Aspose.Slides รองรับการแปลงงานนำเสนอเป็นวิดีโอ
- ใช้ Aspose.Slides เพื่อสร้างชุดเฟรม (จากสไลด์งานนำเสนอ) ที่สอดคล้องกับ FPS (เฟรมต่อวินาที) ที่กำหนด
- ใช้ยูทิลิตี้ของบุคคลที่สามเช่น ffmpeg (for java) เพื่อสร้างวิดีโอตามเฟรม.
Convert PowerPoint to Video
-
ดาวน์โหลด ffmpeg ที่นี่.
-
เรียกใช้โค้ด JavaScript สำหรับแปลง PowerPoint เป็นวิดีโอ.
โค้ด JavaScript นี้จะแสดงวิธีแปลงงานนำเสนอ (ที่มีรูปภาพและเอฟเฟกต์การเคลื่อนไหวสองรายการ) เป็นวิดีโอ:
var presentation = new aspose.slides.Presentation();
try {
// เพิ่มรูปร่างรอยยิ้มแล้วทำให้เคลื่อนไหว
var smile = presentation.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.SmileyFace, 110, 20, 500, 500);
var mainSequence = presentation.getSlides().get_Item(0).getTimeline().getMainSequence();
var effectIn = mainSequence.addEffect(smile, aspose.slides.EffectType.Fly, aspose.slides.EffectSubtype.TopLeft, aspose.slides.EffectTriggerType.AfterPrevious);
var effectOut = mainSequence.addEffect(smile, aspose.slides.EffectType.Fly, aspose.slides.EffectSubtype.BottomRight, aspose.slides.EffectTriggerType.AfterPrevious);
effectIn.getTiming().setDuration(2.0);
effectOut.setPresetClassType(aspose.slides.EffectPresetClassType.Exit);
final var fps = 33;
var frames = java.newInstanceSync("java.util.ArrayList");
var animationsGenerator = new aspose.slides.PresentationAnimationsGenerator(presentation);
try {
var player = new aspose.slides.PresentationPlayer(animationsGenerator, fps);
try {
player.setFrameTick((sender, arguments) -> {
try {
var frame = java.callStaticMethodSync("java.lang.String", "format", "frame_%04d.png", sender.getFrameIndex());
arguments.getFrame().save(frame, aspose.slides.ImageFormat.Png);
frames.add(frame);
} catch (e) {console.log(e);
throw java.newInstanceSync("java.lang.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
var ffmpeg = java.newInstanceSync("FFmpeg", "path/to/ffmpeg");
var ffprobe = java.newInstanceSync("FFprobe", "path/to/ffprobe");
var builder = java.newInstanceSync("FFmpegBuilder").addExtraArgs("-start_number", "1").setInput("frame_%04d.png").addOutput("output.avi").setVideoFrameRate(java.getStaticFieldValue("FFmpeg", "FPS_24")).setFormat("avi").done();
var executor = java.newInstanceSync("FFmpegExecutor", ffmpeg, ffprobe);
executor.createJob(builder).run();
} catch (e) {console.log(e);
console.log(e);
}
Video Effects
คุณสามารถใส่การเคลื่อนไหวให้กับวัตถุบนสไลด์และใช้การเปลี่ยนฉากระหว่างสไลด์ได้.
การเคลื่อนไหวและการเปลี่ยนฉากทำให้การนำเสนอมีความน่าสนใจและดึงดูดมากขึ้น — และทำเช่นเดียวกันกับวิดีโอ เรามาเพิ่มสไลด์และการเปลี่ยนฉากอีกหนึ่งสไลด์ในโค้ดของงานนำเสนอก่อนหน้า:
// เพิ่มรูปร่างรอยยิ้มและทำให้เคลื่อนไหว
// ...
// เพิ่มสไลด์ใหม่และการเปลี่ยนฉากแบบเคลื่อนไหว
var newSlide = presentation.getSlides().addEmptySlide(presentation.getSlides().get_Item(0).getLayoutSlide());
newSlide.getBackground().setType(aspose.slides.BackgroundType.OwnBackground);
newSlide.getBackground().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
newSlide.getBackground().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "MAGENTA"));
newSlide.getSlideShowTransition().setType(aspose.slides.TransitionType.Push);
Aspose.Slides ยังรองรับการเคลื่อนไหวสำหรับข้อความ เราจึงทำการเคลื่อนไหวย่อหน้าบนวัตถุ ซึ่งจะปรากฎต่อเนื่องกัน (โดยตั้งค่าหน่วงเวลาเป็นหนึ่งวินาที):
var presentation = new aspose.slides.Presentation();
try {
// เพิ่มข้อความและการเคลื่อนไหว
var autoShape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 210, 120, 300, 300);
var para1 = new aspose.slides.Paragraph();
para1.getPortions().add(new aspose.slides.Portion("Aspose Slides for Node.js via Java"));
var para2 = new aspose.slides.Paragraph();
para2.getPortions().add(new aspose.slides.Portion("convert PowerPoint Presentation with text to video"));
var para3 = new aspose.slides.Paragraph();
para3.getPortions().add(new aspose.slides.Portion("paragraph by paragraph"));
var paragraphCollection = autoShape.getTextFrame().getParagraphs();
paragraphCollection.add(para1);
paragraphCollection.add(para2);
paragraphCollection.add(para3);
paragraphCollection.add(new aspose.slides.Paragraph());
var mainSequence = presentation.getSlides().get_Item(0).getTimeline().getMainSequence();
var effect1 = mainSequence.addEffect(para1, aspose.slides.EffectType.Appear, aspose.slides.EffectSubtype.None, aspose.slides.EffectTriggerType.AfterPrevious);
var effect2 = mainSequence.addEffect(para2, aspose.slides.EffectType.Appear, aspose.slides.EffectSubtype.None, aspose.slides.EffectTriggerType.AfterPrevious);
var effect3 = mainSequence.addEffect(para3, aspose.slides.EffectType.Appear, aspose.slides.EffectSubtype.None, aspose.slides.EffectTriggerType.AfterPrevious);
var effect4 = mainSequence.addEffect(para3, aspose.slides.EffectType.Appear, aspose.slides.EffectSubtype.None, aspose.slides.EffectTriggerType.AfterPrevious);
effect1.getTiming().setTriggerDelayTime(1.0);
effect2.getTiming().setTriggerDelayTime(1.0);
effect3.getTiming().setTriggerDelayTime(1.0);
effect4.getTiming().setTriggerDelayTime(1.0);
final var fps = 33;
var frames = java.newInstanceSync("java.util.ArrayList");
var animationsGenerator = new aspose.slides.PresentationAnimationsGenerator(presentation);
try {
var player = new aspose.slides.PresentationPlayer(animationsGenerator, fps);
try {
player.setFrameTick((sender, arguments) -> {
try {
var frame = java.callStaticMethodSync("java.lang.String", "format", "frame_%04d.png", sender.getFrameIndex());
arguments.getFrame().save(frame, aspose.slides.ImageFormat.Png);
frames.add(frame);
} catch (e) {console.log(e);
throw java.newInstanceSync("java.lang.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
var ffmpeg = java.newInstanceSync("FFmpeg", "path/to/ffmpeg");
var ffprobe = java.newInstanceSync("FFprobe", "path/to/ffprobe");
var builder = java.newInstanceSync("FFmpegBuilder").addExtraArgs("-start_number", "1").setInput("frame_%04d.png").addOutput("output.avi").setVideoFrameRate(java.getStaticFieldValue("FFmpeg", "FPS_24")).setFormat("avi").done();
var executor = java.newInstanceSync("FFmpegExecutor", ffmpeg, ffprobe);
executor.createJob(builder).run();
} catch (e) {console.log(e);
console.log(e);
}
Video Conversion Classes
เพื่อให้คุณทำงานแปลง PowerPoint เป็นวิดีโอ Aspose.Slides มีคลาส PresentationAnimationsGenerator และ PresentationPlayer
PresentationAnimationsGenerator ทำให้คุณตั้งค่าขนาดเฟรมสำหรับวิดีโอ (ที่จะสร้างในภายหลัง) ผ่านคอนสตรัคเตอร์ของมัน หากคุณส่งอินสแตนซ์ของงานนำเสนอ Presentation.getSlideSize จะถูกใช้และมันสร้างการเคลื่อนไหวที่ PresentationPlayer ใช้
เมื่อสร้างการเคลื่อนไหว จะสร้างเหตุการณ์ NewAnimation สำหรับแต่ละการเคลื่อนไหวต่อเนื่อง ซึ่งมีพารามิเตอร์ตัวเล่นการเคลื่อนไหวของงานนำเสนอ ตัวหลังเป็นคลาสที่แสดงถึงผู้เล่นสำหรับการเคลื่อนไหวแยกแต่ละรายการ
เพื่อทำงานกับผู้เล่นการเคลื่อนไหวของงานนำเสนอ จะใช้เมธอด getDuration (ระยะเวลาทั้งหมดของการเคลื่อนไหว) และเมธอด setTimePosition แต่ละตำแหน่งการเคลื่อนไหวจะถูกตั้งค่าในช่วง 0 ถึง duration แล้วเมธอด getFrame จะคืนค่า BufferedImage ที่สอดคล้องกับสถานะการเคลื่อนไหวในขณะนั้น:
var presentation = new aspose.slides.Presentation();
try {
// เพิ่มรูปร่างรอยยิ้มและทำให้เคลื่อนไหว
var smile = presentation.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.SmileyFace, 110, 20, 500, 500);
var mainSequence = presentation.getSlides().get_Item(0).getTimeline().getMainSequence();
var effectIn = mainSequence.addEffect(smile, aspose.slides.EffectType.Fly, aspose.slides.EffectSubtype.TopLeft, aspose.slides.EffectTriggerType.AfterPrevious);
var effectOut = mainSequence.addEffect(smile, aspose.slides.EffectType.Fly, aspose.slides.EffectSubtype.BottomRight, aspose.slides.EffectTriggerType.AfterPrevious);
effectIn.getTiming().setDuration(2.0);
effectOut.setPresetClassType(aspose.slides.EffectPresetClassType.Exit);
var animationsGenerator = new aspose.slides.PresentationAnimationsGenerator(presentation);
try {
animationsGenerator.setNewAnimation(animationPlayer -> {
console.log(java.callStaticMethodSync("java.lang.String", "format", "Animation total duration: %f", animationPlayer.getDuration()));
animationPlayer.setTimePosition(0);// สภาพเริ่มต้นของการเคลื่อนไหว
try {
// สภาพบิตแมปเริ่มต้นของการเคลื่อนไหว
animationPlayer.getFrame().save("firstFrame.png", aspose.slides.ImageFormat.Png);
} catch (e) {console.log(e);
throw java.newInstanceSync("java.lang.RuntimeException", e);
}
animationPlayer.setTimePosition(animationPlayer.getDuration());// สภาพสุดท้ายของการเคลื่อนไหว
try {
// เฟรมสุดท้ายของการเคลื่อนไหว
animationPlayer.getFrame().save("lastFrame.png", aspose.slides.ImageFormat.Png);
} catch (e) {console.log(e);
throw java.newInstanceSync("java.lang.RuntimeException", e);
}
});
} finally {
if (animationsGenerator != null) {
animationsGenerator.dispose();
}
}
} finally {
if (presentation != null) {
presentation.dispose();
}
}
เพื่อให้การเคลื่อนไหวทั้งหมดในงานนำเสนอเล่นพร้อมกัน จะใช้คลาส PresentationPlayer. คลาสนี้รับอินสแตนซ์ของ PresentationAnimationsGenerator และ FPS สำหรับเอฟเฟกต์ในคอนสตรัคเตอร์แล้วเรียกเหตุการณ์ FrameTick สำหรับการเคลื่อนไหวทั้งหมดเพื่อให้เล่น:
var presentation = new aspose.slides.Presentation("animated.pptx");
try {
var animationsGenerator = new aspose.slides.PresentationAnimationsGenerator(presentation);
try {
var player = new aspose.slides.PresentationPlayer(animationsGenerator, 33);
try {
player.setFrameTick((sender, arguments) -> {
try {
arguments.getFrame().save(("frame_" + sender.getFrameIndex()) + ".png", aspose.slides.ImageFormat.Png);
} catch (e) {console.log(e);
throw java.newInstanceSync("java.lang.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 รองรับการทำงานกับงานนำเสนอที่มีการป้องกันด้วยรหัสผ่าน เมื่อต้องประมวลผลไฟล์ดังกล่าวคุณต้องระบุรหัสผ่านที่ถูกต้องเพื่อให้ไลบรารีเข้าถึงเนื้อหาของงานนำเสนอได้
Aspose.Slides รองรับการใช้งานในโซลูชันคลาวด์หรือไม่?
ใช่, Aspose.Slides สามารถบูรณาการเข้ากับแอปพลิเคชันและบริการคลาวด์ได้ ไลบรารีถูกออกแบบให้ทำงานในสภาพแวดล้อมเซิร์ฟเวอร์ เพื่อให้มั่นใจในประสิทธิภาพสูงและการขยายตัวสำหรับการประมวลผลไฟล์เป็นชุด
มีข้อจำกัดขนาดของงานนำเสนอระหว่างการแปลงหรือไม่?
Aspose.Slides สามารถจัดการกับงานนำเสนอที่มีขนาดเกือบไม่จำกัดได้ อย่างไรก็ตาม เมื่อต้องทำงานกับไฟล์ขนาดใหญ่มากอาจต้องใช้ทรัพยากรระบบเพิ่มเติม และบางครั้งแนะนำให้ทำการปรับแต่งงานนำเสนอเพื่อเพิ่มประสิทธิภาพ

