Create a transcode
Create an H.264 MP4 transcode.
Create a transcode from an existing Source. When it is ready, download the file or make it available to your users.
Before you begin
You need a Source in the same Project, a Project access token, and an official SDK. Replace the token and Source ID in the examples. Keep the token on your server.
Set your storage as the Project's default output destination for lasting exports. The example uses exports/video.mp4, relative to that storage's base_prefix. Choose a distinct filename for each export.
For testing, you can use a Project whose default is Chunkify temporary storage. Chunkify generates the output path there, and deletes the output 24 hours after publication.
For webhook notifications, configure and verify your webhook before creating the transcode. Subscribe to transcoding.ready, transcoding.failed, and transcoding.cancelled.
Create a transcode
The format below creates an H.264 MP4 at the Source's dimensions and frame rate. Omitted settings use the format defaults.
import Chunkify from '@chunkify/chunkify';
async function main() {
const client = new Chunkify({
projectAccessToken: 'My Project Access Token',
});
const transcoding = await client.transcodings.create({
source_id: 'src_2G6MJiNz71bHQGNzGwKx5cJwPFS',
format: {
id: "mp4_h264",
},
storage: {
path: 'exports/video.mp4',
},
});
console.log(transcoding.id, transcoding.status);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Creation accepts the request and returns its current status; the file is not available until publication. Save the returned id for status checks and webhook correlation.
Follow the process
Use Get a transcode with that ID, or handle a verified webhook. Check periodically until status is ready, failed, or cancelled.
The format response contains the settings accepted for this request, including resolved dimensions, frame rate, and trim. Actual output properties appear in files after publication.
A transcoding.ready webhook contains the same resource structure at data.transcoding. Read every member of its files collection. See Events for the lifecycle event types.
Retrieve the file
When the transcode is ready, use a file's url to download it, or its cdn_url when your output storage has CDN delivery configured. Do not infer the output key from the input Source path.
The signed url lasts at most ten minutes. Retrieve the transcode again for a fresh URL while the file remains available. For lasting delivery, use your storage and its configured CDN.
Check error if the transcode fails. Lifecycle and files covers error handling, cancellation, and cleanup.
Change the output
Enable per-title optimization when you want content-based video bitrate selection.