Skip to main content

Documentation Index

Fetch the complete documentation index at: https://rendi.dev/docs/llms.txt

Use this file to discover all available pages before exploring further.

Scale a video to a target resolution (e.g., 1280×720 or 1920×1080) and letterbox where needed to preserve the source aspect ratio.

Code

const API_KEY = process.env.RENDI_API_KEY;

const submit = await fetch("https://api.rendi.dev/v1/run-ffmpeg-command", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-KEY": API_KEY,
  },
  body: JSON.stringify({
    input_files: {
      in_1: "https://storage.rendi.dev/sample/sample.avi",
    },
    output_files: {
      out_1: "resized-720p.mp4",
    },
    ffmpeg_command:
      '-i {{in_1}} -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -c:a copy {{out_1}}',
  }),
});
const { command_id } = await submit.json();

while (true) {
  const res = await fetch(`https://api.rendi.dev/v1/commands/${command_id}`, {
    headers: { "X-API-KEY": API_KEY },
  });
  const data = await res.json();
  if (data.status === "SUCCESS") {
    console.log("Resized URL:", data.output_files.out_1.storage_url);
    break;
  }
  if (data.status === "FAILED") throw new Error("Command failed");
  await new Promise((r) => setTimeout(r, 2000));
}

How the FFmpeg command works

  • scale=1280:720:force_original_aspect_ratio=decrease — fit inside 1280×720, keep aspect ratio
  • pad=1280:720:(ow-iw)/2:(oh-ih)/2 — letterbox with black bars centered
  • -c:v libx264 — re-encode video with H.264 (required after scaling)
  • -c:a copy — pass audio through unchanged (faster than re-encoding)
  • {{out_1}} — output file
For stretch-to-fit without letterbox, drop the pad filter. For crop-to-fit, change decrease to increase and add crop=1280:720.

Response

{
  "output_files": {
    "out_1": {
      "file_id": "a8b2f3c4-...",
      "size_mbytes": 22.4,
      "duration": 596.459,
      "file_type": "video",
      "file_format": "mp4",
      "storage_url": "https://storage.rendi.dev/temp_files/.../resized-720p.mp4",
      "width": 1280,
      "height": 720,
      "codec": "h264"
    }
  },
  "status": "SUCCESS",
  "command_type": "FFMPEG_COMMAND"
}