Discussions

Ask a Question
Back to All

Download videos with API

Hello,

I have a video that I created using the API, and I was wondering if there was any built in API calls to download the video? I.e something I can build into my code, along the lines of:

download_url = f"https://app.heygen.com/share/{video_id}"
output_filename = "AviVideo.mp4"

video_response = requests.get(download_url)

if video_response.status_code == 200:
    with open(output_filename, 'wb') as file:
        file.write(video_response.content)
    print(f"Video downloaded successfully to {output_filename}, video id {download_url}")
    print(f"File size: {len(video_response.content) / (1024 * 1024):.2f} MB")
else:
    print(f"Failed to download video. Status code: {video_response.status_code}")
    print(video_response.text)

I used this website to build the call:
https://apidog.com/blog/heygen-api/#downloading-your-generated-video-with-heygen-api

However the downloaded file is not valid.

Additionally, I used the given curl command

<https://app.heygen.com/videos/>\<video_id> --output my_avatar_video.mp4

and the returned video was the same as the python code above, not valid.

If anyone could give me recommendations on how to download the videos in my python program, that would very much be appreciated