Swap Image and Video in Template

Easily Swap Images and Videos in HeyGen Templates

Welcome to Image/Video Swapping!

You can interchangeably use image and video within templates. Here's how you can replace an image with a video or vice versa using the Template API.

Image/Video Swapping Concept

Image and Video Properties

When swapping images and videos in templates, you can use the following properties to customize the content:

Image Properties:

  • url: URL of the image content.
  • asset_id: Asset ID of the image content.
  • fit: Adjustment of image or video to fit in a area, options: cover, contain, crop, or none. More Info

Video Properties:

  • url: URL of the video content.
  • asset_id: Asset ID of the video content.
  • play_style: Video playback style, options: fit_to_scene, freeze, loop, once. More Info
  • fit: Adjustment of image or video to fit in a area, options: cover, contain, crop, or none. More Info

Creating Template through the Interface

To create templates, visit HeyGen Template page and click on "Create Template". You can then set variables and change variable names using the toolbar's API icon.

💡

Variable Assignment

As you can see, we have assigned a variable name to our image element. In this tutorial, we will demonstrate how to swap this image with a video using the Template API.

Template Interface with Variable Assignment

Step 1: Get a List of Your Templates

Using the following API request you will get a list of your templates that you have created in the HeyGen interface, obtain your template_id from here.

bash
curl --location 'https://api.konpro.ai/v1/templates' \
     --header 'accept: application/json' \
     --header 'x-api-key: <your-api-key>'
Step 1: Template List Example

Step 2: Retrieve Template Elements

To retrieve template elements, use this API request. Get the variable you want to change from here.

bash
curl --location 'https://api.konpro.ai/v1/template/<template_id>' \
     --header 'accept: application/json' \
     --header 'x-api-key: <your-api-key>'
Step 2: Template Elements Example

Step 3: Modify Template Elements and Generate Video

To modify template elements and generate videos, you need to submit an API request as follows. In the request body, specify the elements you want to change by providing the appropriate object within the variables section.

bash
curl --location 'https://api.konpro.ai/v1/template/<template_id>/generate' \
     --header 'x-api-key: <your-api-key>' \
     --header 'Content-Type: application/json' \
     --data '{
  "caption": false,
  "title": "New Video",
  "variables": {
    "content": {
      "name": "content",
      "type": "video",
      "properties": {
        "url": "https://files.heygen.ai/prod/movio/preset/video/origin/af5d137b8dfa426aa504c587ad8cb9fa.mp4",
        "asset_id": null,
        "play_style": "loop",
        "fit": "contain"
      }
    }
  }
}'

You will receive a video_id after your request. To check the video's status and retrieve further details, you can use the video_status API endpoint.

Step 3: API Request Example

Conclusion

This guide has demonstrated how to replace an image with a video in a template using HeyGen's Template API, and vice versa. By following the steps outlined here, you can seamlessly modify template elements to create customized videos that suit your specific needs.

Final Result: Image to Video Swap
Final Result: Video to Image Swap

Table of Contents