The cap rejects MP3 files with oversized ID3v2 tags without shrinking or stripping them. ID3v2 stores title, artist, and cover art at the start of the file; try the cap on the included tagged.mp3.
dotnet add package RecursiveAI.OneAudioRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneAudio; var limits = new AudioLimits { MaxMetadataBytes = 128 }; try { using var mp3 = Audio.Open("tagged.mp3", limits); Console.WriteLine("Opened MP3."); } catch (AudioLimitExceededException ex) { Console.WriteLine(ex.LimitName); }
MaxMetadataBytesUnzip the example, then dotnet run.
The full program
The sample is a quarter-second mono tone. Its ID3v2.3 title is 512 zero characters; the complete declared tag body is larger than the title. The program accepts a cap in bytes and reads one audio frame only if opening succeeds.
using OneAudio; int cap = args.Length == 0 ? 128 : int.Parse(args[0]); var limits = new AudioLimits { MaxMetadataBytes = cap }; try { using var audio = Audio.Open("tagged.mp3", limits); var samples = new float[audio.Format.Channels]; Console.WriteLine($"Decoded {audio.Read(samples)} PCM frame."); } catch (AudioLimitExceededException ex) when (ex.LimitName == nameof(AudioLimits.MaxMetadataBytes)) { Console.WriteLine($"Rejected: {ex.Requested} bytes > {ex.Limit}."); }
Rejected: 568 bytes > 128.Audio.Open throws AudioLimitExceededException before it returns a decoder when the tag exceeds the cap. Match LimitName rather than treating every limit failure as oversized metadata. The check doesn’t edit or sanitize the MP3; the decoder skips leading ID3v2 under the cap and ignores ID3v1, APE, and Lyrics3 tags at the end.
Variations
Allow a bigger tag. Run the full program with a 1,024-byte cap on the same file:
dotnet run -- 1024Decoded 1 PCM frame.Related recipes
The short answer
Set AudioLimits.MaxMetadataBytes and pass the options to Audio.Open. For MP3 input, the decoder checks the size declared in the leading ID3v2 header against the cap before it skips the tag and before it decodes the audio. It checks each leading tag it handles against the cap, not the sum of all tag sizes. Format detection and header probing can still read ahead. The default cap is 1 MiB (1,048,576 bytes). Lower it to match what your app accepts; raise it deliberately for inputs that need larger tags. The 128-byte cap above is only to make the rejection easy to reproduce.
How much space does ID3 metadata take up in an MP3?
There’s no fixed size for ID3v2. A tag can hold text such as title and artist, binary attachments such as a picture, and padding. For the ID3v2.3 format used in this sample, the size declared in the header includes the padding but excludes the ten-byte header itself. The decoder compares that declared size with the cap. So a title that fits in the cap doesn’t tell you whether the tag fits: its frame header, other fields, and padding also count. Embedded cover art can make a tag large even when the track is short.
Does limiting metadata size make the MP3 smaller?
No. The option is a policy for what your decoder opens. It doesn’t scrub metadata, downsize the cover, or change the audio bitrate. There is no rewritten output file. If you want smaller files, decide whether you want less metadata or less audio data before choosing what to change. If you only want to keep oversized uploads out of a decoding job, report the declared size and configured cap from the exception. Don’t use the cap as a substitute for a maximum upload size or decoded length: even a file with no ID3v2 tag can contain a long recording.