Video Generation
Introduction
As artificial intelligence technology continues to advance, video generation models are gradually becoming an essential tool in the field of content creation. These models transform input text into dynamic videos, endowing words with visual effects and expanding the dimensions of expression. Not only do they help creators save significant time, but they also generate high-quality, creative visual content. The potential of Text-to-Video models has been fully demonstrated in various application scenarios, including education, advertising, and entertainment.
Next, we will explore some best practices for Text-to-Video models to help you better utilize this cutting-edge technology in practical operations.
Best Practices
Using MaaS_KL as an example
MaaS_KL provides a video generation method, which includes 2 APIs in total:
-
First, use the video generation interface to create a video generation task, returning a
task_id. -
Then, use the query task status interface to check the status of the task based on the
task_id. When the status is successful, the URL of the generated video will be obtained.
Generate Video
Image-to-Video
curl --location 'https://genaiapi.cloudsway.net/v1/ai/xxx/kling/videos/image2video' \
--header 'Authorization: Bearer xxx' \
--header 'Content-Type: application/json' \
--data '{ "model_name":"kling-v1",
"image":"https://pic1.zhimg.com/v2-0cbb2efa5a55f2e716eebe2d6a6eef67_r.jpg?source=12a79843",
"prompt":"Nezha is practicing martial arts."
Text-to-Video
curl --location 'https://genaiapi.cloudsway.net/v1/ai/XXX/kling/videos/text2video' \
--header 'Authorization: Bearer XXX' \
--header 'Content-Type: application/json' \
--data '{ "model_name":"kling-v1",
"prompt":"The little dog is running on the grass."
Return TaskID
The above requests will return a taskid
{
"code": 0, // Error code; see Error Codes for specific definitions
"message": "string", // Error message
"request_id": "string", // Request ID, generated by the system, used to track requests and troubleshoot issues
"data": {
"task_id": "string", // Task ID, generated by the system
"task_info": {
// Parameter information at task creation
"external_task_id": "string" // Customer-defined task ID
},
"task_status": "string", // Task status, enumeration values: submitted (submitted), processing (in processing), succeed (succeeded), failed (failed)
"created_at": 1722769557708, // Task creation time, Unix timestamp, unit: ms
"updated_at": 1722769557708 // Task update time, Unix timestamp, unit: ms
}
}
Query Video Task Result
Use the returned taskid to query the video task result.
Query Image-Based Video Task Status
curl -X GET "https://genaiapi.cloudsway.net/v1/ai/XXXX/kling/videos/image2video/{id}" \
-H "Authorization: Bearer RWxxxxxxxx0Gd"
Query Text-Based Video Task Status
curl -X GET "https://genaiapi.cloudsway.net/v1/ai/XXXX/kling/videos/text2video/{id}" \
-H "Authorization: Bearer RWxxxxxxxx0Gd"
Response
{
"code": 0, // Error code; see Error Codes for specific definitions
"message": "string", // Error message
"request_id": "string", // Request ID, generated by the system, used to track requests and troubleshoot issues
"data":{
"task_id": "string", // Task ID, generated by the system
"task_status": "string", // Task status, enumeration values: submitted (submitted), processing (in processing), succeed (succeeded), failed (failed)
"task_status_msg": "string", // Task status message; displays the failure reason when the task fails (e.g., triggering the platform's content risk control, etc.)
"task_info": { // Parameter information at task creation
"external_task_id": "string" // Customer-defined task ID
},
"task_result":{
"videos":[
{
"id": "string", // Generated video ID; globally unique
"url": "string", // URL of the generated video, e.g., https://p1.a.kwimgs.com/bs2/upload-ylab-stunt/special-effect/
"duration": "string" // Total video duration, unit: s
}
]
},
"created_at": 1722769557708, // Task creation time, Unix timestamp, unit: ms
"updated_at": 1722769557708, // Task update time, Unix timestamp, unit: ms
}
}