Import from a URL
Have your ClipMux server fetch a video from a public URL and encode it, with no upload from your side.
When the file is already online, for example in another bucket or on your old video host, your backend can hand ClipMux its URL. The server fetches the file itself, stores it as the video's source and encodes it exactly as it would an upload. Nothing passes through your backend or a browser.
Before you start
- An API key with
assets:write, from your backend. - A URL that anyone on the internet can fetch with a plain
GET:httporhttps, answering200with the file. A short-lived signed URL from your own storage works, as long as it lasts while the import runs.
Import a video
import { ClipMux } from '@clipmux/node'
const clipmux = new ClipMux() // reads the CLIPMUX_* settings
const asset = await clipmux.assets.importUrl(
{
url: 'https://files.example.com/lesson-42.mp4',
passthrough: 'lesson_42',
title: 'Lesson 42: Sorting',
},
{ idempotencyKey: 'import-lesson_42' },
)
console.log(asset.id, asset.status) // ast_… processingPOST /v1/assets answers 201 with the video, already processing, and
its playback ID. With an Idempotency-Key, a retry of the same request
returns the same video instead of importing twice.
| Field | Default | What it does |
|---|---|---|
url | The public http or https URL to fetch. Required. | |
playback_policy | signed | signed for a private video, public for one anyone with the URL can watch. |
passthrough | Your own ID for the video, up to 255 bytes. See Link videos to your records. | |
title | A name for people, one line, up to 200 characters. | |
generate | { "subtitles": true, "chapters": true } makes subtitles and chapters once the video is ready. Chapters imply subtitles. | |
renditions | every rung up to the source | The rungs to encode, for example ["1080p", "480p"]. See Choose renditions. |
When the video is ready, your webhook receives video.asset.ready, as for
an upload.
What is refused
ClipMux fetches only public addresses, so an import can't be used to reach the server's own machine or your private network. It refuses:
- a URL that isn't
httporhttps, has no host, or is over 2048 characters; - a URL with credentials in it, such as
https://user:pass@…; - a host that is, or resolves to, a loopback, private, link-local or other non-public address, including cloud metadata addresses.
The address is checked on every connection, after DNS, and on each of up to
5 redirects, so a redirect or a DNS change can't lead around it. A URL that
is refused when you send it is 400 import_url_refused, and nothing is
created. One that leads to a refused address later ends the video as
errored with import_url_refused.
Sizes and failures
The file may be up to 312.5 GiB (10,000 parts of 32 MiB), and one fetch may
take up to 6 hours. A fetch that fails for a passing reason (a network error,
or a 5xx, 408 or 429 answer) is tried 3 times in all, with a growing
wait between tries.
An import that fails for good ends the video errored, sends
video.asset.errored, and sets error_code:
error_code | What happened |
|---|---|
import_url_refused | The URL, or an address it redirected to, is not public. |
import_failed | The fetch kept failing, or the server answered something other than 200, or an empty body. |
import_too_large | The file is larger than the import limit. |
A file that arrives but isn't a video ClipMux can read fails later, at encoding, like an upload would.
Check it works
Get the video until it's ready:
curl -s https://video.example.com/v1/assets/ast_… \
-H "Authorization: Bearer $CLIPMUX_API_KEY" | jq '{status, error_code}'processing turns into ready. If it ends errored, error_code is one of
those above. For import_failed, fetch the URL yourself with
curl -I from somewhere outside your network: it must answer 200.