Extract Audio
Extract audio tracks from video files as MP3, AAC, or WAV.
Extract Audio
Extracting the audio track from a video is useful for creating podcasts from video recordings, pulling soundtracks, or preparing audio for transcription services. FFmpeg can extract audio in any format and quality level.
Video to MP3
Extract the audio track and encode it as MP3. The -q:a 2 flag sets the quality level, where 0 is the best and 9 is the worst (2 is a good balance of quality and file size, roughly equivalent to 192 kbps).
ffmpeg -i {{in_video}} -vn -c:a libmp3lame -q:a 2 {{out_audio}}Video to AAC
AAC provides better quality than MP3 at the same bitrate. Use -b:a to set an explicit bitrate target.
ffmpeg -i {{in_video}} -vn -c:a aac -b:a 192k {{out_audio}}Video to WAV (lossless)
WAV with PCM encoding gives you uncompressed, lossless audio. File sizes are much larger, but there is zero quality loss. Useful as an intermediate format for further audio processing.
ffmpeg -i {{in_video}} -vn -c:a pcm_s16le {{out_audio}}Copy audio stream (no re-encoding)
If the video already contains the audio codec you want, you can copy the stream directly without re-encoding. This is instant and preserves the original quality. The output format must be compatible with the source codec.
ffmpeg -i {{in_video}} -vn -c:a copy {{out_audio}}For example, if the source video contains AAC audio, you can copy it directly to an .m4a or .aac file.
Full API example
Extract the audio from a video file as a high-quality MP3.
curl -X POST https://renderio.dev/api/v1/run-ffmpeg-command \
-H "Content-Type: application/json" \
-H "X-API-KEY: ffsk_your_api_key_here" \
-d '{
"input_files": {
"in_video": "https://example.com/interview.mp4"
},
"output_files": {
"out_audio": "interview.mp3"
},
"ffmpeg_command": "ffmpeg -i {{in_video}} -vn -c:a libmp3lame -q:a 2 {{out_audio}}"
}'import requests
response = requests.post(
"https://renderio.dev/api/v1/run-ffmpeg-command",
headers={
"Content-Type": "application/json",
"X-API-KEY": "ffsk_your_api_key_here",
},
json={
"input_files": {
"in_video": "https://example.com/interview.mp4",
},
"output_files": {
"out_audio": "interview.mp3",
},
"ffmpeg_command": "ffmpeg -i {{in_video}} -vn -c:a libmp3lame -q:a 2 {{out_audio}}",
},
)
data = response.json()
print("Command ID:", data["command_id"])interface RunCommandResponse {
command_id: string;
}
const response = await fetch("https://renderio.dev/api/v1/run-ffmpeg-command", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": "ffsk_your_api_key_here",
},
body: JSON.stringify({
input_files: {
in_video: "https://example.com/interview.mp4",
},
output_files: {
out_audio: "interview.mp3",
},
ffmpeg_command: "ffmpeg -i {{in_video}} -vn -c:a libmp3lame -q:a 2 {{out_audio}}",
}),
});
const { command_id } = (await response.json()) as RunCommandResponse;
console.log("Command ID:", command_id);const response = await fetch("https://renderio.dev/api/v1/run-ffmpeg-command", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": "ffsk_your_api_key_here",
},
body: JSON.stringify({
input_files: {
in_video: "https://example.com/interview.mp4",
},
output_files: {
out_audio: "interview.mp3",
},
ffmpeg_command: "ffmpeg -i {{in_video}} -vn -c:a libmp3lame -q:a 2 {{out_audio}}",
}),
});
const { command_id } = await response.json();
console.log("Command ID:", command_id);<?php
$ch = curl_init("https://renderio.dev/api/v1/run-ffmpeg-command");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"X-API-KEY: ffsk_your_api_key_here",
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"input_files" => [
"in_video" => "https://example.com/interview.mp4",
],
"output_files" => [
"out_audio" => "interview.mp3",
],
"ffmpeg_command" => "ffmpeg -i {{in_video}} -vn -c:a libmp3lame -q:a 2 {{out_audio}}",
]));
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo "Command ID: " . $data["command_id"] . "\n";The API returns a command_id immediately. Poll GET /api/v1/commands/:commandId to check when the extraction is complete, then download the output from the storage_url in the response.
Tips and variations
-vnflag: This disables video recording in the output. Without it, FFmpeg might try to include a video stream, which would fail for audio-only containers.- MP3 quality scale: The
-q:aflag for libmp3lame uses a VBR scale from 0 (best, ~245 kbps) to 9 (worst, ~65 kbps). Use-q:a 0for archival quality,-q:a 2for high quality, or-q:a 5for smaller files. - Sample rate conversion: Add
-ar 44100to resample to 44.1 kHz (CD quality) or-ar 16000for speech recognition services that expect 16 kHz input. - Mono downmix: Add
-ac 1to convert stereo to mono, which halves the file size and is often preferred for speech/podcast content. - Extract specific time range: Add
-ss 00:01:00 -t 30before the output to extract 30 seconds starting at the 1-minute mark.
Related guides
- Chained Workflow -- extract audio and compress video in a single pipeline
- File Metadata -- verify audio properties like sample rate and channels in the response
Further reading
- FFmpeg API Complete Guide -- full walkthrough of the RenderIO API
- FFmpeg Cheat Sheet: 50 Commands -- audio extraction and conversion commands