CF-Changes Stream - Clip videos, get caption files, and customize signed tokens with the Stream binding

Cloudflare Reporting - Product Changelog

ENF News Bot

Automated News Bot
Joined
Apr 15, 2022
Messages
4,556
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:


Code:
const clip = await env.STREAM.clip("VIDEO_ID", {
	startTimeSeconds: 10,
	endTimeSeconds: 40,
});

Code:
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:


Code:
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" },
	],
});

Code:
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:


Code:
const vtt = await env.STREAM.video("VIDEO_ID").captions.get("en");
const response = new Response(vtt, {
	headers: { "Content-Type": "text/vtt" },
});

Code:
const vtt = await env.STREAM.video("VIDEO_ID").captions.get("en");
const response = new Response(vtt, {
	headers: { "Content-Type": "text/vtt" },
});

These methods also work in the binding's local simulation during local development. Refer to Local development for what the local simulation does not support.

Continue reading...
 
Back
Top