This guide explains how to export a video from an existing project using the BlendDuck SDK.

Usage

To export a video, you’ll use the videos.export() method of the BlendDuck client.

import BlendDuck, { ExportOptions, ExportStatus } from "@blendduck/node-sdk";


// Initialize the BlendDuck client
const client = new BlendDuck({
  apiKey: process.env.BLENDDUCK_API_KEY
});

async function exportVideo(projectId: string) {
  // Define export options
  const exportOptions: ExportOptions = {
    resolution: "1080p",
    quality: "medium",
    fps: 30
  };

  try {
    // Start the export process
    const exportId = await client.videos.export(projectId, exportOptions);

    console.log(`Export process started. Export ID: ${exportId}`);

    // Monitor the export progress
    let status: ExportStatus;
    do {
      await new Promise(resolve => setTimeout(resolve, 5000)); // Wait for 5 seconds
      status = await client.videos.getExportStatus(exportId);
      console.log(`Export progress: ${status.progress}%`);
    } while (status.status === ExportStatus.Processing);

    if (status.status === ExportStatus.Completed) {
      console.log(`Export completed successfully!`);
      console.log(`Download your video at: ${status.url}`);
    } else {
      console.error(`Export failed: ${status.error}`);
    }
  } catch (error) {
    console.error("Error exporting video:", error);
  }
}

// Usage
exportVideo("your-project-id-here");

Export Options

The ExportOptions object allows you to customize your video export:

  • resolution: The video resolution (e.g., “720p”, “1080p”, “4k”)
  • quality: The export quality (e.g., “low”, “medium”, “high”)
  • fps: The frames per second for the exported video

Export Status

The getExportStatus() method returns an ExportStatus object with the following properties:

  • status: The current status of the export (“processing”, “completed”, or “failed”)
  • progress: The export progress as a percentage (0-100)
  • url: The URL to download the exported video (available when status is “completed”)
  • error: Error message if the export failed

Error Handling

If there’s an issue with starting the export or with the API request, the method will throw an error. It’s good practice to wrap the call in a try-catch block to handle any potential errors gracefully.