The Stream binding for Workers now supports clipping videos, customizing signed URL tokens, and fetching caption files.
Clip a video into a new video from a time range of an existing one:
const clip = await env.STREAM.clip("VIDEO_ID", {
startTimeSeconds: 10,
endTimeSeconds: 40,
});
const clip = await env.STREAM.clip("VIDEO_ID", {
startTimeSeconds: 10,
endTimeSeconds: 40,
});
Customize signed URL tokens with an expiry, download access, IP and country access rules, or your own signing key, without making an API call:
const token = await env.STREAM.video("VIDEO_ID").generateToken({
expiresAt: new Date(Date.now() + 30 * 60 * 1000),
downloadable: true,
accessRules: [
{ type: "ip.geoip.country", action: "allow", country: ["US"] },
{ type: "any", action: "block" },
],
});
const token = await env.STREAM.video("VIDEO_ID").generateToken({
expiresAt: new Date(Date.now() + 30 * 60 * 1000),
downloadable: true,
accessRules: [
{ type: "ip.geoip.country", action: "allow", country: ["US"] },
{ type: "any", action: "block" },
],
});
Fetch a caption file as a WebVTT stream:
const vtt = await env.STREAM.video("VIDEO_ID").captions.get("en");
const response = new Response(vtt, {
headers: { "Content-Type": "text/vtt" },
});
const vtt = await env.STREAM.video("VIDEO_ID").captions.get("en");
const response = new Response(vtt, { …