Video & documents
Video and document conversion are asynchronous REST jobs, not on-the-fly URL transformations. This library builds the paths you submit to the convert API. gif2video is the exception, served directly from a URL.
Video conversion paths
videoPath produces the domain-less string POST /convert/video/ expects:
import {
cut,
format,
quality,
size,
thumbs,
videoPath
} from '@uploadcare/cdn-url/video'
videoPath(uuid, [
size({ width: 720, height: 540 }),
format('webm'),
quality('better'),
cut('0:0:10.0', '30.0'),
thumbs(5)
])
// → /:uuid/video/-/size/720x540/-/format/webm/-/quality/better/-/cut/0:0:10.0/30.0/-/thumbs~5/import { cdn } from '@uploadcare/cdn-url/fluent'
import { prefixedCdnBase } from '@uploadcare/cdn-url/cdn-base'
const myCdn = cdn.base(prefixedCdnBase('demopublickey'))
cdn
.video(uuid)
.size({ width: 720, height: 540 })
.format('webm')
.quality('better')
.cut('0:0:10.0', '30.0')
.thumbs(5).path
// → /:uuid/video/-/size/720x540/-/format/webm/-/quality/better/-/cut/0:0:10.0/30.0/-/thumbs~5/No builder tab, on purpose
CdnUrl can hold a conversion: 'video' and will happily serialize it, but it attaches the CDN base and hands back a full URL. The convert API wants a path, so use videoPath or a fluent video chain instead. Conversion paths are the one thing here that needs no CDN base at all; gif2video, being an on-the-fly URL, does. The string level has no place in either: it builds URLs, not paths, and a gif2video prefix lives inside what it treats as the chain, so replacing that chain drops the conversion.
Grammar the creators enforce (in development):
sizedimensions must be divisible by 4; output is downscale-onlycuttakesH:MM:SS.sss-style timestamps (zero-padding optional) or plain seconds, and'end'as the lengththumbs(n)accepts 1 to 50 and must be the last operation
Submit with @uploadcare/rest-client:
import { convertVideo } from '@uploadcare/rest-client'
await convertVideo(
{ paths: [videoPath(uuid, ops)], store: true },
{ authSchema }
)The job produces a new uuid for the converted file (plus thumbnails). Finished results are also addressable on the CDN as https://…/:uuid/video/-/…/, which is why parseCdnUrl understands the video prefix inside full URLs.
Document conversion paths
Same model, documentPath:
import { documentPath, format, page } from '@uploadcare/cdn-url/document'
documentPath(uuid, [format('pdf')])
// → /:uuid/document/-/format/pdf/
documentPath(uuid, [format('jpg'), page(2)])
// → /:uuid/document/-/format/jpg/-/page/2/page is 1-based and only valid when the target format is jpg or png.
gif2video: the on-the-fly exception
Animated GIFs convert to video directly on the CDN, with no REST job:
import { format, gif2videoUrl, quality } from '@uploadcare/cdn-url/gif2video'
gif2videoUrl('https://1s4oyld5dc.ucarecd.net', uuid, [
format('webm'),
quality('better')
])
// → https://1s4oyld5dc.ucarecd.net/:uuid/gif2video/-/format/webm/-/quality/better/<video autoplay loop muted playsinline :src="gif2videoUrl(…)" />Note the URL shape: the gif2video prefix attaches right after the uuid with a plain /, without a -/ separator. The source file must be an animated image, otherwise the CDN responds 400.