Skip to content

Generating Videos

Project Setup

Terminal window
# Create a project directory.
mkdir prodia-video-generation
cd prodia-video-generation

Install Node (if not already installed):

Terminal window
brew install node
# Close the current terminal and open a new one so that node is available.

Create project skeleton:

Terminal window
# Requires node --version >= 18
# Initialize the project with npm.
npm init -y
# Install the prodia-js library.
npm install prodia --save
Terminal window
# Export your token so it can be used by the main code.
export PRODIA_TOKEN=your-token-here

Create a main file for your project:

main.js
const { createProdia } = require("prodia/v2");
const prodia = createProdia({
token: process.env.PRODIA_TOKEN // get it from environment
});

You’re now ready to make some API calls!

With a Prompt

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
const job = await prodia.job({
type: "inference.veo.fast.txt2vid.v1",
config: {
prompt: "A sweeping mountain landscape at sunrise, captured from a high-angle perspective using a wide-angle lens. The early morning light casts long shadows across the rugged terrain, with mist rolling over the valleys. The scene features sharp detail in the rocks, lush greenery, and clouds forming over distant peaks. Warm oranges and pinks dominate the sky, creating a dramatic and serene atmosphere. High dynamic range (HDR) captures the subtle transitions between light and shadow.",
},
});
const video = await job.arrayBuffer();
await fs.writeFile("landscape.mp4", new Uint8Array(video));
})();
Terminal window
node main.js
Terminal window
open landscape.mp4

From an Image

Let’s extend our example and generate a video from an existing image.

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
// get input image
const inputBuffer = await (await fetch("https://docs.prodia.com/strike-a-pose.jpg")).arrayBuffer();
const job = await prodia.job({
type: "inference.veo.fast.img2vid.v1",
config: {
prompt: "Walking down the street.",
},
}, {
inputs: [ inputBuffer ]
});
const video = await job.arrayBuffer();
await fs.writeFile("walking.mp4", new Uint8Array(video));
})();
Terminal window
node main.js
Terminal window
open walking.mp4

To an Image

We can also control the last frame of the video generation. For this example we will switch to Seedance for the first and last frame fields. We will also use the same image for the first and last frame in order to create a loop-able video.

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
const firstFrame = await fetch("https://docs.prodia.com/strike-a-pose.jpg");
const firstFrameFile = new File([await firstFrame.arrayBuffer()], "first-frame.jpg", {type: 'image/jpeg'});
const lastFrame = await fetch("https://docs.prodia.com/strike-a-pose.jpg");
const lastFrameFile = new File([await lastFrame.arrayBuffer()], "last-frame.jpg", {type: 'image/jpeg'});
const job = await prodia.job({
type: "inference.seedance.lite.img2vid.v1",
config: {
prompt: "Dancing in the street.",
first_frame: "first-frame.jpg",
last_frame: "last-frame.jpg",
},
}, {
inputs: [
firstFrameFile,
lastFrameFile,
]
});
const video = await job.arrayBuffer();
await fs.writeFile("loop.mp4", new Uint8Array(video));
})();
Terminal window
node main.js
Terminal window
open loop.mp4