Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 53 additions & 12 deletions src/content/docs/stream/viewing-videos/download-videos.mdx
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
---
title: Download videos
title: Download video or audio
pcx_content_type: how-to
sidebar:
order: 6
---

When you upload a video to Stream, it can be streamed using HLS/DASH. However, for certain use-cases (such as offline viewing), you may want to download the MP4. You can enable MP4 support on a per video basis by following the steps below:
When you upload a video to Stream, it can be streamed using HLS/DASH. However, for use certain use-cases, you may want to download the MP4 or M4A file.
For cases such as offline viewing, you may want to download the MP4 file. Whereas, for downstream tasks like AI summarization, if you want to extract only the audio, downloading an M4A file may be more useful.

1. Enable MP4 support by making a POST request to the `/downloads` endpoint (example below)
2. Save the MP4 URL provided by the response to the `/downloads` endpoint. This MP4 URL will become functional when the MP4 is ready in the next step.
3. Poll the `/downloads `endpoint until the `status` field is set to `ready` to inform you when the MP4 is available. You can now use the MP4 URL from step 2.
## Generate downloadable MP4 files

## Generate downloadable files
> NOTE: The `/downloads` endpoint defaults to creating an MP4 download.

You can enable downloads for an uploaded video once it is ready to view by making an HTTP request to the `/downloads` endpoint.
You can enable MP4 support on a per video basis by following the steps below:

1. Enable MP4 support by making a POST request to the `/downloads` or `/downloads/default` endpoint
2. Save the MP4 URL provided by the response to the endpoint. This MP4 URL will become functional when the MP4 is ready in the next step.
3. Poll the `/downloads` endpoint until the `status` field is set to `ready` to inform you when the MP4 is available. You can now use the MP4 URL from step 2.

You can enable downloads for an uploaded video once it is ready to view by making an HTTP request to either the `/downloads` or `/downloads/default` endpoint.

To get notified when a video is ready to view, refer to [Using webhooks](/stream/manage-video-library/using-webhooks/#notifications).

The downloads API response will include all available download types for the video, the download URL for each type, and the processing status of the download file.
## Generate downloadable M4A files

```bash title="Request"
To enable M4A support on a per video basis, we follow steps similar to that of generating an MP4 download, but instead send a POST request to the `/downloads/audio` endpoint.

## Examples

The downloads API response will include download type for the video, the download URL, and the processing status of the download file.

Separate requests would be needed to generate a downloadable MP4 and M4A file, respectively. For example:

```bash title="Request MP4"
curl -X POST \
-H "Authorization: Bearer <API_TOKEN>" \
https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/stream/<VIDEO_UID>/downloads
```

```json title="Response"
```json title="Response MP4"
{
"result": {
"default": {
"default": {
"status": "inprogress",
"url": "https://customer-<CODE>.cloudflarestream.com/<VIDEO_UID>/downloads/default.mp4",
"percentComplete": 75.0
Expand All @@ -39,10 +52,33 @@ https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/stream/<VIDEO_UID>/do
"messages": []
}
```
And for an M4A file:

```json title="Request M4A"
curl -X POST \
-H "Authorization: Bearer <API_TOKEN>" \
https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/stream/<VIDEO_UID>/downloads/audio
```

```json title="Response M4A"
{
"result": {
"audio": {
"status": "inprogress",
"url": "https://customer-<CODE>.cloudflarestream.com/<VIDEO_UID>/downloads/audio.m4a",
"percentComplete": 75.0
}
},
"success": true,
"errors": [],
"messages": []
}
```


## Get download links

You can view all available downloads for a video by making a `GET` HTTP request to the downloads API. The response for creating and fetching downloads are the same.
You can view all available downloads for a video by making a `GET` HTTP request to the downloads API.

```bash title="Request"
curl -X GET \
Expand All @@ -53,6 +89,11 @@ https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/stream/<VIDEO_UID>/do
```json title="Response"
{
"result": {
"audio": {
"status": "ready",
"url": "https://customer-<CODE>.cloudflarestream.com/<VIDEO_UID>/downloads/audio.m4a",
"percentComplete": 100.0
}
"default": {
"status": "ready",
"url": "https://customer-<CODE>.cloudflarestream.com/<VIDEO_UID>/downloads/default.mp4",
Expand Down
Loading