Chuyển đổi PowerPoint sang Video bằng Java REST API

Hãy làm theo bài viết này để chuyển đổi PowerPoint sang video bằng Java REST API. Bạn sẽ học cách phát triển bộ chuyển đổi Power Point sang video bằng Java RESTful Service bằng cách sử dụng Cloud SDK dựa trên Java. Nó chia sẻ các thiết lập khác nhau để tùy chỉnh video đầu ra theo yêu cầu của người dùng.

Điều kiện tiên quyết

Các bước chuyển đổi PPT sang Video bằng Java Low Code API

  1. Tạo đối tượng SlidesApi để chuyển đổi bản trình bày thành video
  2. Tạo đối tượng VideoExportOptions và thiết lập các cài đặt tùy chỉnh cho bản trình bày
  3. Tải bản trình bày nguồn lên bộ nhớ đám mây với tên đã chỉ định
  4. Gọi phương thức DownloadPresentation() để chuyển đổi bản trình bày đã tải lên thành video bằng cách sử dụng các thiết lập tùy chỉnh
  5. Lưu luồng phản hồi cuộc gọi API dưới dạng tệp MP4 trên bộ nhớ cục bộ

Các bước này giải thích quy trình biến PowerPoint thành video bằng Java Low Code API. Tạo đối tượng SlidesApi, tải tệp trình bày nguồn lên bộ lưu trữ đám mây và khởi tạo đối tượng VideoExportOptions để đặt các thuộc tính tùy chỉnh cho video đầu ra. Cuối cùng, phương thức DownloadPresentation() được sử dụng để truy xuất bản trình bày từ bộ lưu trữ đám mây theo định dạng và cài đặt đã chỉ định.

Mã cho PowerPoint Slide to Video Converter với API dựa trên 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);
}
}

Mã này trình bày cách thay đổi PowerPoint presentation thành MP4 với Java REST Interface. Bạn có thể đặt độ phân giải video đầu ra thành FullHD, HD và QHD bằng cách sử dụng trình liệt kê VideoExportOptions.VideoResolutionTypeEnum. Có rất nhiều kiểu chuyển đổi mà bạn có thể chọn như mờ dần, trượt xuống, trượt phải, trượt trái, đóng vòng tròn, cắt vòng tròn, v.v.

Bài viết này hướng dẫn chúng ta cách tạo video từ bài thuyết trình bằng API dựa trên Đám mây. Nếu bạn muốn hợp nhất nhiều bài thuyết trình thành một bài thuyết trình duy nhất, hãy tham khảo bài viết trên Hợp nhất các bài thuyết trình với Java REST API.

 Tiếng Việt