ทำตามบทความนี้เพื่อ แปลง PowerPoint เป็น video ด้วย Java REST API คุณจะได้เรียนรู้วิธีพัฒนา ตัวแปลง Power Point เป็นวิดีโอด้วย Java RESTful Service โดยใช้ Cloud SDK ที่ใช้ Java โดย SDK นี้มีการตั้งค่าที่แตกต่างกันสำหรับปรับแต่งวิดีโอเอาต์พุตตามความต้องการของผู้ใช้
ข้อกำหนดเบื้องต้น
ดาวน์โหลด Aspose.Slides Cloud SDK for Java for converting presentations to MP4
ตั้งค่าโครงการ Java ด้วย SDK ข้างต้นเพื่อแปลง PPTX ออนไลน์เป็นวิดีโอ
ขั้นตอนการแปลง PPT เป็นวิดีโอด้วย Java Low Code API
- สร้างวัตถุ SlidesApi เพื่อแปลงงานนำเสนอเป็นวิดีโอ
- สร้างอ็อบเจ็กต์ VideoExportOptions และตั้งค่าแบบกำหนดเองสำหรับการนำเสนอ
- อัปโหลดงานนำเสนอแหล่งที่มาไปยังที่เก็บข้อมูลบนคลาวด์ด้วยชื่อที่ระบุ
- เรียกใช้เมธอด DownloadPresentation() เพื่อแปลงการนำเสนอที่อัปโหลดเป็นวิดีโอโดยใช้การตั้งค่าแบบกำหนดเอง
- บันทึกสตรีมการตอบสนองการเรียก API เป็นไฟล์ MP4 บนพื้นที่จัดเก็บข้อมูลภายใน
ขั้นตอนเหล่านี้จะอธิบายกระบวนการ เปลี่ยน PowerPoint ให้เป็นวิดีโอด้วย Java Low Code API สร้างอ็อบเจ็กต์ SlidesApi อัปโหลดไฟล์งานนำเสนอต้นฉบับไปยังที่จัดเก็บข้อมูลบนคลาวด์ และสร้างอ็อบเจ็กต์ VideoExportOptions เพื่อตั้งค่าคุณสมบัติแบบกำหนดเองสำหรับวิดีโอเอาต์พุต ในที่สุด วิธี DownloadPresentation() จะถูกใช้เพื่อดึงงานนำเสนอจากที่จัดเก็บข้อมูลบนคลาวด์ในรูปแบบและการตั้งค่าที่ระบุ
รหัสสำหรับ PowerPoint Slide to Video Converter ที่มี API ที่ใช้ Java
import com.aspose.slides.ApiException; | |
import com.aspose.slides.api.SlidesApi; | |
import com.aspose.slides.model.ExportFormat; | |
import com.aspose.slides.model.VideoExportOptions; | |
import java.io.File; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.StandardCopyOption; | |
public class Example_PresentationToVideo { | |
protected static SlidesApi presentationApi; | |
public Example_PresentationToVideo() { | |
if (presentationApi == null) { | |
presentationApi = new SlidesApi("appSid", "appKey"); | |
} | |
} | |
public void PresentationToVideo() throws ApiException, IOException { | |
String localPath = "/home/downloads/"; | |
String fileName = "Sample.pptx"; | |
String outputPdfName = "Sample.mp4"; | |
String storageFolderName = "TempTests"; | |
presentationApi.uploadFile(storageFolderName+"/"+fileName, readFileToByteArray(localPath + fileName),null); | |
VideoExportOptions videoExportOptions = new VideoExportOptions(); | |
videoExportOptions.setSlidesTransitionDuration(5); | |
videoExportOptions.setVideoResolutionType(VideoExportOptions.VideoResolutionTypeEnum.SD); | |
videoExportOptions.setTransitionType(VideoExportOptions.TransitionTypeEnum.DISSOLVE); | |
videoExportOptions.setTransitionDuration(3); | |
File videofile = presentationApi.downloadPresentation("Sample.pptx", ExportFormat.MPEG4, videoExportOptions, null, storageFolderName, null, null, null); | |
// Copy the downloaded Video to the local directory | |
copyFile(videofile, new File(localPath, outputPdfName)); | |
System.out.println("Presentation converted to Video and copied to: " + localPath + outputPdfName); | |
} | |
public static byte[] readFileToByteArray(String filePath) throws IOException { | |
Path path = new File(filePath).toPath(); | |
return Files.readAllBytes(path); | |
} | |
private void copyFile(File sourceFile, File targetFile) throws IOException { | |
if (sourceFile == null || !sourceFile.exists()) { | |
throw new IOException("Source file does not exist: " + sourceFile); | |
} | |
// Ensure the target directory exists | |
Path targetPath = targetFile.toPath(); | |
Files.createDirectories(targetPath.getParent()); | |
// Copy the file | |
Files.copy(sourceFile.toPath(), targetPath, StandardCopyOption.REPLACE_EXISTING); | |
} | |
} |
โค้ดนี้สาธิตวิธีเปลี่ยน งานนำเสนอ PowerPoint เป็น MP4 ด้วย Java REST Interface คุณสามารถตั้งค่าความละเอียดวิดีโอเอาต์พุตเป็น FullHD, HD และ QHD ได้โดยใช้ตัวระบุ VideoExportOptions.VideoResolutionTypeEnum มีประเภทการเปลี่ยนภาพมากมายที่คุณสามารถเลือกได้ เช่น การเฟด การเลื่อนลง การเลื่อนไปทางขวา การเลื่อนไปทางซ้าย การเลื่อนแบบวงกลม การครอบตัดแบบวงกลม เป็นต้น
บทความนี้สอนให้เราสร้างวิดีโอจากงานนำเสนอโดยใช้ API บนคลาวด์ หากคุณต้องการรวมงานนำเสนอหลายรายการเข้าเป็นงานนำเสนอเดียว โปรดดูบทความที่ ผสานการนำเสนอด้วย Java REST API