Skip to content

Extract Audio

The extractAudio recipe pulls the first audio track from a video (or audio-in-video container) and saves it as a standalone file.

Xora probes the input and chooses the best path:

  1. Stream copy when the source codec maps to a web-friendly file extension (fast, no quality loss).
  2. Transcode to your output.format fallback when stream copy is not possible (for example AC-3, DTS, or E-AC-3).

After probing, Xora resolves the output file extension:

Source audio codecOutput fileMethod
mp3.mp3Stream copy
aac.aacStream copy
opus.opusStream copy
vorbis.oggStream copy
flac.flacStream copy
pcm_* (for example pcm_s16le).wavStream copy
Anything else (for example ac3, dts, eac3).mp3, .aac, or .wavTranscode to output.format

The default output key is outputs/{jobId}/result.{ext} where {ext} is the resolved extension above — not always the extension from output.format.

When transcoding is required, output.format must be one of mp3, aac, or wav:

output.formatEncoderNotes
mp3 (default if invalid)libmp3lameBest universal compatibility
aacAAC @ 192 kbpsSmaller than MP3 at similar quality
wav16-bit PCMLossless, large files

Request MP3 as the fallback (used only when stream copy is not possible):

Terminal window
curl -X POST https://api.xora.sh/v1/jobs \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"mode": "recipe",
"input": {
"url": "https://example.com/interview.mp4"
},
"output": {
"format": "mp3"
},
"recipe": {
"name": "extractAudio"
}
}'
{
"jobId": "01JXYZ1234ABCDEF56789000",
"state": "queued"
}

When the job completes, check the output file metadata (extension and MIME type) — it reflects the resolved format, which may differ from output.format.

ParameterTypeRequiredDescription
namestringYesMust be "extractAudio"
startSecondsnumberNoStart offset into the input (seconds)
durationSecondsnumberNoMaximum duration to extract (seconds)
stageInputbooleanNoSet false to stream directly from your URL when the host supports HTTP byte ranges (skips copying the full video to engine storage). Default: true. See Input Staging.
Job fieldTypeRequiredDescription
output.formatstringYesFallback transcode target: mp3, aac, or wav. Ignored when stream copy applies.

Input has AAC audio; output.format is only used if copy is impossible:

{
"mode": "recipe",
"input": { "url": "https://example.com/video.mp4" },
"output": { "format": "mp3" },
"recipe": { "name": "extractAudio" }
}

Completed output: result.aac (not result.mp3).

Unsupported for stream copy; falls back to output.format:

{
"mode": "recipe",
"input": { "url": "https://example.com/movie.mkv" },
"output": { "format": "mp3" },
"recipe": { "name": "extractAudio" }
}

Completed output: result.mp3.

{
"mode": "recipe",
"input": { "url": "https://cdn.example.com/video.mp4" },
"output": { "format": "mp3" },
"recipe": { "name": "extractAudio" },
"stageInput": false
}

Use when you know the source needs re-encoding and you prefer AAC over MP3:

{
"mode": "recipe",
"input": { "url": "https://example.com/video.mkv" },
"output": { "format": "aac" },
"recipe": { "name": "extractAudio" }
}

If you set outputPath, the file extension must match output.format at request time. The engine still resolves copy vs transcode from the source; prefer the default output key when you want the resolved extension (for example .aac from an AAC source).

Stream-copied formats vary in HTML5 <audio> support:

ExtensionBroad web supportNotes
.mp3, .aac, .wavExcellentSafest for universal delivery
.opus, .flac, .oggGood on modern browsersOlder Safari / iOS may need a transcode fallback

If you need guaranteed playback everywhere, use a source that transcodes (for example AC-3 → output.format: "mp3") or post-process to MP3.

ScenarioSuggested output.formatTypical result
Podcast from video interviewmp3.aac or .mp3 depending on source
Audio for transcription APImp3.mp3 if source is AC-3/DTS; else copy
Music from live performanceaacCopy if already AAC/FLAC; else transcode
Audio for further editingwav.wav if PCM source; else transcode to WAV
Voice memo from videomp3Copy if MP3/AAC; else MP3 transcode
  • Output formats — format reference and recipe matrix
  • Input staging — when to set stageInput: false
  • Transcode — full container/codec conversion (always re-encodes to output.format)