Lesson 5 of 10

Extract Audio

Pull an MP3 or WAV audio track out of a video for podcast and transcription workflows using the options array.

Follow along with a live API key. 100 free minutes, no credit card.

Get free API key

Just the audio, please

A lot of workflows only care about the sound: podcast episodes, transcription pipelines, and audio archives all start by pulling the audio track out of a video. With FFmpeg Micro you do this in one transcode job. Set outputFormat to an audio format, drop the video stream, and pick a codec. No new endpoints to learn: you already have createTranscode, waitForJob, and getDownloadUrl from Lesson 3.

The three moving parts

  • outputFormat is the audio format. Allowed audio outputs are mp3, m4a, aac, wav, ogg, opus, and flac.
  • -vn drops the video stream. It's a flag with no argument. Without it, the job keeps trying to write a video track into an audio-only file.
  • -c:a sets the audio codec. Allowed values include mp3, aac, libopus, libvorbis, and copy. Pair it with -b:a to set the bitrate.

Extract to MP3

The most common case is an MP3 at a sensible bitrate. This helper wraps createTranscode with the exact options the API expects: outputFormat: 'mp3', -vn to drop video, -c:a mp3 for the codec, and -b:a for the bitrate:

// extract-audio.mjs
import { createTranscode, waitForJob, getDownloadUrl } from './client.mjs'

// Pull an MP3 audio track out of a video.
export async function extractAudio(url, { bitrate = '192k' } = {}) {
  return createTranscode({
    inputs: [{ url }],
    outputFormat: 'mp3',
    options: [
      { option: '-vn' },                    // drop the video stream
      { option: '-c:a', argument: 'mp3' },  // audio codec
      { option: '-b:a', argument: bitrate },// audio bitrate, e.g. '192k'
    ],
  })
}

Run it end to end using the helpers from Lesson 3:

const job = await extractAudio('https://example.com/talk.mp4', { bitrate: '192k' })
const done = await waitForJob(job.id)
const { url } = await getDownloadUrl(done.id)
console.log('Audio ready:', url)

Extract to WAV

Transcription services often want uncompressed audio. A WAV output uses PCM, which is the default for the wav container, so you don't pass a codec at all. Just outputFormat: 'wav' and -vn:

// PCM wav needs no explicit codec.
export async function extractWav(url) {
  return createTranscode({
    inputs: [{ url }],
    outputFormat: 'wav',
    options: [
      { option: '-vn' }, // drop the video stream
    ],
  })
}

What could go wrong: FFmpeg CLI habits and older tutorials will steer you wrong here. The API rejects -acodec, the codec value libmp3lame, and -q:a with a 400 "Invalid FFmpeg options". Use -c:a instead of -acodec, use the codec value mp3 (not libmp3lame), and set quality with -b:a (not -q:a).

Key takeaways

  • Set outputFormat to the audio format: mp3, m4a, aac, wav, ogg, opus, or flac.
  • Drop the video stream with the -vn flag (no argument).
  • Set the codec with -c:a (mp3, aac, libopus, ...) and the bitrate with -b:a.
  • PCM wav needs no explicit codec. Just -vn.
  • Avoid -acodec, libmp3lame, and -q:a. The API returns a 400 for all three.

Next up: reach into the video itself and pull out still frames and thumbnails at any timestamp.

Build this into your app. No FFmpeg install

One call kicks off a job. No local FFmpeg, no servers, no worker queue to run.

const res = await fetch('https://api.ffmpeg-micro.com/v1/transcodes', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.FFMPEG_MICRO_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    inputs: [{ url: 'gs://your-bucket/input.mp4' }],
    outputFormat: 'mp4',
    preset: { quality: 'medium', resolution: '1080p' },
  }),
})
const job = await res.json() // { id, status: 'pending' }