Audio-only workflows come to Cloudflare Stream
Video files carry a lot of data that is irrelevant to many downstream tasks. A video is not a single file but a container of high-dimensional information — resolution, frame rate, codecs, and a sequence of images over time. Processing all of that just to get to the audio track is slow and costly, especially for customers running AI inference pipelines that only need to analyze speech or sound.
Cloudflare Stream now offers audio extraction, letting developers pull a lightweight M4A audio track from any video with a single API call or a dashboard click. The feature is designed to support workflows such as:
- AI and machine learning: feed audio into voice-to-text models for transcription, translation, or AI-powered summaries.
- Content moderation: analyze the audio portion of videos to check for compliance and safety issues.
Two ways to extract audio
On-the-fly with Media Transformations
Media Transformations works for short-form content stored anywhere, fetching the source media directly from your origin and optimizing it at the edge. Adding mode=audio to a transformation URL now extracts audio on the fly. You can also clip a specific section using time and duration parameters. Once Media Transformations is enabled for your domain, a request like the one below generates a 10-second M4A clip starting at the 5-second mark of the source video.
https://example.com/cdn-cgi/media/mode=audio,time=5s,duration=10s/<SOURCE-VIDEO>
Details on setup and available options are in the Media Transformations documentation.
Persistent downloads for Stream videos
For content already managed within Stream, the dashboard and API now support generating a downloadable audio file alongside the existing MP4 download option. The result is a persistent M4A file stored alongside the video.
Workers AI demo: transcription and translation
The following sample code shows how to combine Media Transformations with Workers AI. The worker performs a two-step process: first transcribing the video's audio to English, then translating the transcript into Spanish.
export default {
async fetch(request, env, ctx) {
// 1. Use Media Transformations to fetch only the audio track
const res = await fetch( "https://blog.cloudflare.com/cdn-cgi/media/mode=audio/https://pub-d9fcbc1abcd244c1821f38b99017347f.r2.dev/announcing-audio-mode.mp4" );
const blob = await res.arrayBuffer();
// 2. Transcribe the audio to text using Whisper
const transcript_response = await env.AI.run(
"@cf/openai/whisper-large-v3-turbo",
{
audio: base64Encode(blob), // A base64 encoded string is required by @cf/openai/whisper-large-v3-turbo
}
);
// Check if transcription was successful and text exists
if (!transcript_response.text) {
return Response.json({ error: "Failed to transcribe audio." }, { status: 500 });
}
// 3. Translate the transcribed text using the M2M100 model
const translation_response = await env.AI.run(
'@cf/meta/m2m100-1.2b',
{
text: transcript_response.text,
source_lang: 'en', // The source language (English)
target_lang: 'es' // The target language (Spanish)
}
);
// 4. Return both the original transcription and the translation
return Response.json({
transcription: transcript_response.text,
translation: translation_response.translated_text
});
}
};
export function base64Encode(buf) {
let string = '';
(new Uint8Array(buf)).forEach(
(byte) => { string += String.fromCharCode(byte) }
)
return btoa(string)
}
The worker returns a clean JSON response, with the transcription snippet shown below.
{
"transcription": "I'm excited to announce that Media Transformations from Cloudflare has added audio-only mode. Now you can quickly extract and deliver just the audio from your short form video. And from there, you can transcribe it or summarize it on Worker's AI or run moderation or inference tasks easily.",
"translation": "Estoy encantado de anunciar que Media Transformations de Cloudflare ha añadido el modo solo de audio. Ahora puede extraer y entregar rápidamente sólo el audio de su vídeo de forma corta. Y desde allí, puede transcribirlo o resumirlo en la IA de Worker o ejecutar tareas de moderación o inferencia fácilmente."
}
How the feature works under the hood
Stream's media processing uses two distinct pipelines. The video-on-demand (VOD) pipeline handles videos uploaded directly to Stream, generating and storing encoded segments for adaptive bitrate streaming over HLS/DASH. The on-the-fly-encoding (OTFE) pipeline powers Stream Live and Media Transformations, fetching media from the customer's origin and transforming it at the edge rather than pre-processing and storing files. Both pipelines were extended to support audio extraction.
Extending the OTFE pipeline
The OTFE pipeline is built for real-time operations, and its existing flow handled visual tasks: resize videos or generate thumbnail frames. To add an audio-only mode, the work involved two main pieces:
- Extended validation logic: in addition to the existing checks for URL correctness, the new code verifies that the source video contains an audio track before attempting extraction.
- A new transformation handler: a handler within the OTFE platform that discards visual tracks entirely and outputs a high-quality M4A file.
Extending the VOD pipeline
For the VOD pipeline, the existing MP4 downloads workflow was the foundation. Creating a download starts with a POST request to the API layer, which handles authentication and validation, creates a database record, and enqueues a job for asynchronous workers. To support audio downloads, new type-specific API endpoints (POST /downloads/{type}) were introduced, while the legacy POST /downloads route remains as an alias for the default video download type — preserving backward compatibility.
The asynchronous queue performs the core work, which required:
- Adding logic to the consumer to recognize the new audio download type
- Pulling the ffmpeg template defined in the API layer to encode the audio stream into a high-quality M4A container
Available in the dashboard
Audio extraction is also available directly in the Stream dashboard. Navigating to any video shows options to download either the video or just the audio track. Once the download is ready, the URL for the file appears along with the ability to disable it.





