Generate Video from Template
HeyGen API support generating video from template.
Making a Template
Any videos after 06:00 am Friday, 19 August 2022 UTC, can be used as a template(videos older than this are not supported). You can make a video on https://heygen.com. After the video submitted, you can check the video ID from your video list.
Get Template Info
Use the video ID as template ID, get template variables by Get Template API.
You'll get a JSON like this in your response
{
"code": 100,
"data": {
"scenes": [
{
"variables": [
{
"name": "avatar_0",
"properties": [
{
"default": "Kent-insuit-20220728",
"name": "id"
},
{
"default": "https://file.movio.la/pacific/resource/audio/admin/552339db40344e65a5980bffcdc2521c.mp3?OSSAccessKeyId=LTAI4FhUZsa1YYumWbTWusLN&Expires=1660892351&Signature=%2Fz4S%2FoM08RLqEDVJCpeWjbTEs0M%3D",
"name": "audio"
}
],
"type": "avatar"
},
{
"name": "text_0",
"properties": [
{
"default": "Subtitle Text",
"name": "text"
}
],
"type": "text"
}
],
"video_id": "aabbccdd"
},
"message": "Success"
}
Generate Template Video
Make a call to Generate Template API, replace the variable as you need.
Here is an example of replace a text variable:
{
"title": "your video title (optional)",
"test": true,
"variables": [
{
"properties": {
"text": "Welcome to HeyGen API!"
},
"name": "text_0"
}
],
"template_id": "aabbccdd"
}
Please note the text length of the original template.
The Generate Template API will only replace the variables you specificed in the request.
The "test" flag will specific that you're in a test environment, the video generation will not deduct your credits, but there will be an watermark on the video.
If you want to generate video without watermark, set the "test" flag to false or remove the test field. Make sure you have enough quota to deduct, or the generation will be failed.
Query Video Status
The Generate Template API will return a video_id
in the response data, get the video status by Video Status API.
You'll get a response like this if the video has been ready:
{
"code": 100,
"data":
{
"id": "your_video_id_here",
"status": "completed"
"video_url": "https://path/to/video.mp4"
},
"message": "Success"
}
The video URL will be expire in seven days, please make sure you’ve download the video or save it to somewhere safe.
Updated about 2 months ago