# Convert MP3 to AAC

> To convert MP3 to AAC, send one POST to /v1/audio-convert with the MP3 source and "to": "aac" in the body. Left out, "to" falls back to its default "mp3", so a AAC request has to send it. Each call costs $0.003 in USDC on Base via x402, with no account and no API key. The source file can be up to 100 MB and 60 min (3,600 s) long.

- Endpoint: `POST /v1/audio-convert`
- Price: $0.003 per successful call
- API: [audio-convert](https://grist.tools/docs/audio-convert)
- Selects the target: `"to": "aac"`

## Limits

| Limit | Value |
| --- | --- |
| Largest source file | 100 MB (104,857,600 bytes) |
| Longest input | 60 min (3,600 s) |
| Timeout | 94 s |
| Source formats | AIFF, AVI, FLAC, MKV, MP3, MP4, Ogg, WAV |
| Output formats | AAC, FLAC, MP3, Opus, WAV |

## Example

A real MP3 to AAC run of audio-convert.

Request body:

```json
{
  "url": "https://grist.tools/samples/av/pair-tone.mp3",
  "to": "aac"
}
```

Response:

```json
{
  "source_url": "https://grist.tools/samples/av/pair-tone.mp3",
  "bytes": 12980,
  "source_container": "mp3",
  "format": "aac",
  "bitrate_kbps": null,
  "sample_rate": null,
  "audio_bytes": 10202,
  "audio_base64": "//FsQEjf/AEIVCwkSCWOhsSDWGBsSwsJB2F/2yq4hffG+KzlPurWt+uqv0nWFTf/..."
}
```

Source file: av/pair-tone.mp3, 12.7 KB (12,980 bytes). 3 s mono 8 kHz MP3 at 32 kbit/s, encoded by ffmpeg's libmp3lame with the bit-exact flags: three 0.5 s 500 Hz triangle beeps at rising level, each followed by 0.5 s of silence. The recorded run returned 10 KB (10,202 bytes) of AAC, 79% of the source size, with the source read as the mp3 container. Decoded, the AAC in audio_base64 opens with FF F1 6C 40 48 DF FC 01 08 54 2C 24. Recorded with ffmpeg 8.1.2.
In the sample itself: the file opens with an ID3v2.4 tag with 10 bytes of body, then an MPEG 2.5 Layer III frame header at byte 20: 32 kbps, 8,000 Hz, mono. That first frame is an Info header rather than audio, and it counts 44 audio frames and 12,960 bytes. In the returned AAC: it opens with an ADTS frame header carrying no CRC: MPEG-4 AAC LC, 8,000 Hz, 1 channel, a first frame of 582 bytes, and buffer fullness 0x7FF, the value that marks a variable bitrate stream.

## Format notes

MP3 as a source: MP3 is lossy audio. Grist accepts it when the file opens with an ID3v2 tag or with a bare MPEG audio frame sync: the byte FF followed by a byte whose top three bits are set. That sync test also matches a raw ADTS AAC stream, and because nothing proves ffmpeg would then pick the right demuxer, AAC is kept out of the sources. Duration needs care with MP3. For a file without a Xing header, the probe estimates length by dividing file size by the bitrate of the first frames, which a crafted variable-bitrate file can falsify, so any probe warning sends the measurement to a scan of real packet timestamps. Once accepted, the first audio stream is decoded by ffmpeg; a lossless destination stores the decoded samples without recovering what MP3 encoding discarded.

AAC as a target: AAC output is a raw ADTS stream: ffmpeg's aac encoder writes through the adts muxer, and no MP4 container is built around it. Each ADTS frame carries its own header, and the stream is written straight to a pipe without a seekable file. The bitrate_kbps setting applies, but AAC has its own lower ceiling, because it is the slowest encoder of the set and that ceiling keeps a maximum-length input inside the encode deadline. Only the first audio stream is encoded; video, metadata and chapters are dropped, and bit-exact flags keep output reproducible for the pinned ffmpeg. sample_rate is optional, otherwise ffmpeg normally keeps the source rate. AAC is a destination only: a raw ADTS file would pass the MPEG frame-sync sniff, yet nothing proves ffmpeg would receive the right demuxer, so it is not accepted as a source.

## Errors

- `invalid_input` (400)
- `blocked_target` (403)
- `unreachable_target` (424)
- `upstream_timeout` (424)
- `unsupported_content_type` (415)
- `too_large` (413)
- `unprocessable` (422)
- `internal` (500)

When each is raised, and what it means for payment: https://grist.tools/docs/audio-convert.

## Questions

### What does it cost to convert MP3 to AAC?

$0.003 per call, paid in USDC on Base via x402.

### How large can the MP3 file be?

Up to 100 MB (104,857,600 bytes), and at most 60 min (3,600 s) of media. Past a limit the call answers too_large (413).

### What happens if the conversion fails?

The tool answers with a typed JSON error from the errors table. Payment is settled only after the tool has produced its result; a call that fails inside the tool is never settled.

This page as HTML: https://grist.tools/tools/mp3-to-aac. Every page of grist.tools has a Markdown version at its address plus .md.
