Using AI models to generate images is a very powerful feature that allows you to create high-quality videos and simplify the creation process, without the need to find images or photos in photo libraries or stock websites, or even create them manually.
JSON2Video API allows you to directly use AI models from the API to generate images for your videos simplifying a lot the creation process. You don't need to generate images calling external APIs or services, you just need to provide the parameters for the AI model and JSON2Video will handle the rest.
Generating images with AI models
To generate images with AI models, you use the Image Element like for any other image element, but instead of providing an image URL, you specify the model to use and the parameters for the AI model.
The current supported models are freepik-classic
and flux-pro
.
Using freepik-classic model
The following example shows how to generate an image using the freepik-classic
model.
{
"resolution": "full-hd",
"scenes": [
{
"elements": [
{
"type": "image",
"model": "freepik-classic",
"prompt": "A beautiful image of a flower with a bee flying around it",
"aspect-ratio": "horizontal",
"resize": "cover",
"zoom": 3,
"duration": 10
}
]
}
]
}
The AI generation related properties are:
model
: The AI model to use for the generation.prompt
: The prompt to use for the generation. This is the text that will be used to generate the image.aspect-ratio
: The aspect ratio of the image. Possible values arehorizontal
,vertical
andsquared
.
The resulting video is:
Using flux-pro model
Now, if we want to use flux-pro
model instead of freepik-classic
, we can do it by changing the model
property.
{
"resolution": "full-hd",
"scenes": [
{
"elements": [
{
"type": "image",
"model": "flux-pro",
"prompt": "A beautiful image of a flower with a bee flying around it",
"aspect-ratio": "horizontal",
"resize": "cover",
"zoom": 3,
"duration": 10
}
]
}
]
}
The resulting video is:
Image caching
Images generated with AI models are cached in JSON2Video servers to avoid calling the AI models for the same image multiple times. This means that if you call the JSON2Video API with the same parameters for the same image multiple times, the same image will be used in the video, avoiding the need to call the AI models again.
If for any reason you need to regenerate an image, you can do it by setting the cache
property to false
.
Published on January 13th, 2025