Discussions

Ask a Question
Back to All

API Video same aspect ration as image

Hi team, when I create a video inside the web app, I get a video that is the same (tall) aspect ratio as my image. However, when using the API talks endpoint, I'm getting back a square video. What do I need to do to get back a tall video like the web app can provide?

FYI, here is my code:

import requests
import time

URLs for the d-id.com API endpoints

image_upload_url = "https://api.d-id.com/images"
audio_upload_url = "https://api.d-id.com/audios"
animation_url = "https://api.d-id.com/talks"

Replace these with the paths to your local files

image_file_path = r"----------------------"
audio_file_path = r"--------------"

Headers including the Authorization header with your API key

headers = {
"Authorization": "Bearer -------------------"
}

Step 1: Upload the image

with open(image_file_path, 'rb') as image_file:
image_response = requests.post(image_upload_url, headers=headers, files={"image": image_file})

if image_response.status_code == 201:
image_data = image_response.json()
image_url = image_data['url'] # Temporary URL of the uploaded image
print("Image uploaded successfully:", image_url)
else:
print("Image upload failed:", image_response.text)
exit()

Step 2: Upload the audio

with open(audio_file_path, 'rb') as audio_file:
audio_response = requests.post(audio_upload_url, headers=headers, files={"audio": audio_file})

if audio_response.status_code == 201:
audio_data = audio_response.json()
audio_url = audio_data['url'] # Temporary URL of the uploaded audio
print("Audio uploaded successfully:", audio_url)
else:
print("Audio upload failed:", audio_response.text)
exit()

Step 3: Create the animation using the uploaded image and audio URLs

animation_payload = {
"source_url": image_url,
"script": {
"type": "audio",
"audio_url": audio_url
}
}

animation_response = requests.post(animation_url, headers=headers, json=animation_payload)

if animation_response.status_code in [200, 201]:
animation_data = animation_response.json()
animation_id = animation_data['id']
print("Animation created successfully:", animation_data)
else:
print("Animation creation failed:", animation_response.text)
exit()

Step 4: Check the status of the animation and download when ready

status_url = f"{animation_url}/{animation_id}"

while True:
status_response = requests.get(status_url, headers=headers)
if status_response.status_code == 200:
status_data = status_response.json()
print("Current status:", status_data['status'])
if status_data['status'] == 'done':
print("Animation is ready!")
video_url = status_data.get('result_url')
if video_url:
video_response = requests.get(video_url)
if video_response.status_code == 200:
# Specify the path where you want to save the downloaded video
video_file_path = r"---------------------------------" # Update this path
with open(video_file_path, 'wb') as video_file:
video_file.write(video_response.content)
print(f"Video downloaded successfully to {video_file_path}")
else:
print("Failed to download the video.")
else:
print("Video URL not found in the response.")
break
else:
print("Failed to check animation status:", status_response.text)
break

time.sleep(30)  # Adjust the sleep time as appropriate