mutagen developer on retainer: EasyID3.save() writes ID3v2.4 by default — 50 000 normalized MP3 tracks show “Unknown Artist” on ID3v2.3-only car stereos and DJ software integrations; partner OEM SDK rejects major version byte 04 — v2_version=3 fix — 3 weeks — mutagen developer on monthly retainer

mutagen 1.47.0 • Python 3.9; EasyID3(path); .save(); .save(v2_version=3) • Westfield Mutagen Ltd. (music metadata normalization service; 50,000 MP3 tracks per month from 300 independent labels; EasyID3.save() without v2_version argument writes ID3v2.4 — header bytes 49 44 33 04 00 — mutagen 1.47.0 default v2_version=4; partner car stereo OEM SDK integration guide: “ID3 major version 02 and 03 supported; major version 04 not parsed — tags will not display”; after normalization, all 50,000 tracks carry ID3v2.4 header (major version byte 0x04); 12,000 partner devices show “Unknown Artist / Unknown Album” on every track; 3-week regression after Python 2→3.9 + mutagen upgrade; fix: audio.save(v2_version=3) forces ID3v2.3 header (0x03); mutagen converts UTF-8 text frames to UTF-16 LE with BOM; partner device metadata restored; 1.5h retainer engagement)

Westfield Mutagen Ltd. built a music metadata normalization service for a music distribution platform that aggregated tracks from 300 independent labels. Each submitted track went through a normalization pipeline: title casing standardized, artist name disambiguation applied against the platform’s artist registry, album metadata cross-referenced against the label database, and BPM and genre fields populated from a crowd-sourced tag database. The pipeline used mutagen’s EasyID3 interface throughout: audio = EasyID3(path) opened each file, field updates were applied, and audio.save() committed the changes back to the MP3 file. The pipeline ran nightly, processing an average of 1,700 tracks. Partner integrations accessed the normalized files via the platform’s CDN, including 12,000 registered car stereo head units from a hardware OEM partner whose SDK had a documented ID3v2.3 requirement. The OEM’s integration guide, included in the original partnership agreement, stated explicitly: “ID3 major version 02 and 03 are supported; major version 04 (ID3v2.4) is not parsed — tags will not display on affected units.” The normalization pipeline had been running for eight months on a legacy Python 2 stack using an older mutagen version that defaulted to writing ID3v2.3 tags. When the platform was migrated to Python 3.9 and mutagen 1.47.0 as part of a infrastructure modernization project, the normalization pipeline was re-implemented using EasyID3. QA passed on a 500-track sample using the platform’s web player, which parsed ID3v2.4 without issues, and the new pipeline was promoted to production.

Three weeks after the migration, the OEM partner’s support channel reported that all track metadata was showing as “Unknown Artist” and “Unknown Album” on their car stereo fleet. The issue affected all 50,000 tracks normalized since the migration. The hardware OEM’s SDK logged “unsupported ID3 version” for every file, but this error appeared only in the on-device developer log — not in any CDN API response or distribution platform alert. The root cause was confirmed within 30 minutes by reading the first ten bytes of the ID3 header with open(path, 'rb').read(10) on a normalized file: the fourth byte was 0x04 (ID3v2.4) instead of 0x03 (ID3v2.3). EasyID3.save() with no arguments calls the underlying ID3.save() with v2_version=4 as the default. ID3v2.4 introduced changes incompatible with strict ID3v2.3 parsers: the frame size field encoding changed (syncsafe integers in v2.4 versus plain big-endian integers in v2.3), the text encoding byte 0x03 for UTF-8 is valid in v2.4 but undefined in v2.3 (which only recognizes 0x00 Latin-1, 0x01 UTF-16 LE with BOM, and 0x02 UTF-16 BE), and several frames were renamed between versions (TDRC in v2.4 replacing TYER + TDAT + TIME in v2.3). The OEM SDK’s parser, written against the ID3v2.3 specification, saw the 0x04 major version byte and refused to parse the entire ID3 tag block, falling back to no-metadata display. The fix was a single-argument change to every save() call in the normalization pipeline: audio.save(v2_version=3). mutagen 1.47.0 handles the downgrade internally — it converts UTF-8-encoded text frames to UTF-16 LE with BOM (encoding byte 0x01), writes frame sizes as plain big-endian 32-bit integers instead of syncsafe integers, splits the TDRC date field back into TYER and TDAT, and sets the header major version byte to 0x03. The 50,000 affected files were re-normalized in a single overnight run with the fixed pipeline. Partner device metadata was restored across all 12,000 OEM units and the support ticket was closed. The retainer engagement was 1.5h.

The annotated buggy and fixed mutagen normalization pipeline, with ID3 version detection and bulk repair utilities:

# Westfield Mutagen Ltd. — mutagen 1.47.0 EasyID3 ID3 version default
# mutagen 1.47.0; Python 3.9; music metadata normalization service
# Pipeline: 50,000 MP3 tracks/month from independent labels → EasyID3 normalize → CDN
# Problem: EasyID3.save() writes ID3v2.4 (mutagen default v2_version=4)
#          ID3v2.4 header major version byte = 0x04
#          OEM car stereo SDK integration guide: "major version 04 not parsed"
#          12,000 partner devices show Unknown Artist / Unknown Album for 3 weeks
#          Legacy Python 2 mutagen defaulted to v2.3; Python 3.9 upgrade changed default
# Fix: audio.save(v2_version=3) — forces ID3v2.3 (major version byte 0x03)

from pathlib import Path
from mutagen.easyid3 import EasyID3
import mutagen


def detect_id3_version(path: str) -> tuple[int, int]:
    """Read ID3 major and revision version bytes directly from the file header."""
    with open(path, 'rb') as fh:
        header = fh.read(10)
    if header[:3] != b'ID3':
        return (0, 0)   # no ID3v2 tag present
    major = header[3]   # 0x03 = ID3v2.3,  0x04 = ID3v2.4
    revision = header[4]
    return (major, revision)


# ── BUGGY normalization pipeline ─────────────────────────────────────────────

def normalize_track_metadata_buggy(path: str, normalized: dict) -> None:
    """
    BUG: EasyID3.save() with no arguments writes ID3v2.4 (mutagen 1.47.0 default).
    ID3v2.4 header major version byte = 0x04.
    OEM car stereo SDK requires ID3v2.3 (major version byte = 0x03).
    Partner devices: "unsupported ID3 version" → Unknown Artist / Unknown Album.
    """
    audio = EasyID3(path)
    for key, value in normalized.items():
        audio[key] = [str(value)]   # EasyID3 values must be lists of strings
    audio.save()   # BUG: defaults to v2_version=4 — writes ID3v2.4 (byte 04)


# ── FIXED normalization pipeline ──────────────────────────────────────────────

def normalize_track_metadata_fixed(path: str, normalized: dict) -> None:
    """
    FIX: pass v2_version=3 to write ID3v2.3-compatible tags.
    mutagen converts UTF-8 text frames (encoding 0x03) to UTF-16 LE with BOM (0x01).
    mutagen converts frame sizes: syncsafe integers → plain big-endian 32-bit integers.
    mutagen converts TDRC (ID3v2.4 date) → TYER + TDAT (ID3v2.3 date fields).
    ID3v2.3 header: 49 44 33 03 00; OEM SDK reads tags correctly on all 12,000 units.
    """
    audio = EasyID3(path)
    for key, value in normalized.items():
        if value is not None:
            audio[key] = [str(value)]
    audio.save(v2_version=3)   # FIX: writes ID3v2.3 (major version byte 0x03)


# ── Initialization for files with no existing ID3 tags ────────────────────────

def normalize_track_safe(path: str, normalized: dict) -> None:
    """
    Production-safe normalization:
    1. Create ID3 tag block if file has none (mutagen raises ID3NoHeaderError).
    2. Save as ID3v2.3 for maximum car stereo and DJ software compatibility.
    3. Verify written version matches the expected major version byte.
    """
    try:
        audio = EasyID3(path)
    except mutagen.id3.ID3NoHeaderError:
        # File has no ID3 tags at all — create a new tag block
        m = mutagen.File(path, easy=True)
        if m is None:
            raise ValueError(f"mutagen could not open {path} as an audio file")
        if m.tags is None:
            m.add_tags()
        m.save()
        audio = EasyID3(path)

    for key, value in normalized.items():
        if value:
            audio[key] = [str(value)]

    audio.save(v2_version=3)

    # Verification: confirm ID3v2.3 was written, not ID3v2.4
    major, revision = detect_id3_version(path)
    if major != 3:
        raise RuntimeError(
            f"Expected ID3v2.3 (major=3) after save, got major={major} in {path}. "
            f"OEM SDK will display Unknown Artist / Unknown Album for this file. "
            f"Check mutagen version and v2_version argument."
        )


# ── Bulk repair: ID3v2.4 → ID3v2.3 for all files in a directory ──────────────

def audit_and_repair_id3_versions(directory: str, dry_run: bool = True) -> dict:
    """
    Scan all MP3 files in directory; report and optionally repair ID3v2.4 files.
    Used to repair the 50,000-file regression after the Python 3.9 migration.
    dry_run=True: audit only. dry_run=False: convert ID3v2.4 → ID3v2.3 in place.
    """
    results = {
        'scanned': 0,
        'id3v2_3': 0,          # already v2.3 — OK for OEM SDK
        'id3v2_4': 0,          # v2.4 — needs repair for OEM SDK
        'other': 0,            # no ID3 tag, or v2.1/v2.2
        'repaired': 0,
        'errors': 0,
    }

    for mp3_path in Path(directory).rglob('*.mp3'):
        path_str = str(mp3_path)
        results['scanned'] += 1
        major, _ = detect_id3_version(path_str)

        if major == 3:
            results['id3v2_3'] += 1
        elif major == 4:
            results['id3v2_4'] += 1
            if not dry_run:
                try:
                    audio = EasyID3(path_str)
                    audio.save(v2_version=3)
                    results['repaired'] += 1
                except Exception as exc:
                    print(f"ERROR repairing {path_str}: {exc}")
                    results['errors'] += 1
        else:
            results['other'] += 1

    return results


if __name__ == '__main__':
    import sys
    if len(sys.argv) < 2:
        print("Usage: python mutagen_id3_version.py path/to/file.mp3")
        print()
        print("Root cause: mutagen 1.47.0 EasyID3.save() defaults to v2_version=4")
        print("  ID3v2.4 header: 49 44 33 04 00 ...")
        print("  OEM SDK requires ID3v2.3: 49 44 33 03 00 ...")
        print("  Major version byte 0x04 → SDK: 'unsupported ID3 version'")
        print("  12,000 partner devices show Unknown Artist / Unknown Album")
        print("  50,000 tracks affected; 3-week regression after mutagen upgrade")
        print()
        print("Fix: audio.save(v2_version=3)")
        print("  mutagen converts text encoding 0x03 (UTF-8) → 0x01 (UTF-16 LE w/ BOM)")
        print("  mutagen converts frame sizes: syncsafe ints → plain big-endian ints")
        print("  mutagen converts TDRC → TYER + TDAT for date fields")
        print("  ID3v2.3 header: 49 44 33 03 00; all partner devices display metadata")
        sys.exit(0)

    path = sys.argv[1]
    major, rev = detect_id3_version(path)
    print(f"ID3 version: v2.{major}.{rev}")
    if major == 4:
        print("  WARNING: ID3v2.4 — OEM car stereo SDK will show 'Unknown Artist'")
        print("  Fix: EasyID3(path).save(v2_version=3)")
    elif major == 3:
        print("  OK: ID3v2.3 — compatible with OEM SDK and legacy DJ software")
    else:
        print(f"  INFO: major version {major} — no ID3v2 tag, or ID3v2.1/v2.2")

How the ID3v2.3 and ID3v2.4 header format, text encoding, and frame size encoding differ — and the correct pattern for mutagen pipelines serving heterogeneous device ecosystems

The ID3v2 tag format stores its version in the first five bytes of the file: 49 44 33 (‘ID3’ in ASCII), major version byte, revision byte. ID3v2.3 has major version byte 0x03; ID3v2.4 has 0x04. This single byte controls the entire interpretation of the tag block by any conforming parser. The two versions differ in three structurally important ways. First, frame size encoding: ID3v2.3 uses plain big-endian 32-bit integers for the size field of each frame (the four bytes at offset 4 through 7 within each frame header); ID3v2.4 uses syncsafe integers (each byte has its high bit clear, encoding 7 bits each, for a 28-bit total). A parser written for ID3v2.3 that reads an ID3v2.4 frame will misinterpret the size field for any frame larger than 0x7F bytes, causing cascading mis-reads of all subsequent frames. Second, text encoding: ID3v2.3 defines three text encoding bytes — 0x00 (Latin-1 / ISO-8859-1), 0x01 (UTF-16 with BOM), and 0x02 (UTF-16 BE) — while ID3v2.4 adds 0x03 (UTF-8). mutagen uses UTF-8 (encoding byte 0x03) when writing ID3v2.4 tags. A strict ID3v2.3 parser that encounters encoding byte 0x03 in a text frame will interpret the content as Latin-1, rendering multi-byte UTF-8 sequences as mojibake (garbled characters). Third, date fields: ID3v2.3 uses TYER (year as a 4-digit string), TDAT (day-and-month as DDMM), and TIME (time as HHMM) as separate frames; ID3v2.4 consolidates these into a single TDRC frame with an ISO 8601 timestamp. When mutagen writes TDRC in a v2.4 tag and the downstream parser expects TYER, the year field appears empty. When downgrading with v2_version=3, mutagen performs all three conversions: frame sizes become plain big-endian integers, UTF-8 text is re-encoded as UTF-16 LE with BOM (encoding byte 0x01), and TDRC is split into TYER and TDAT. The practical rule for any mutagen deployment serving partners: audit each partner’s SDK or player documentation for its stated maximum supported ID3 major version before choosing between save() and save(v2_version=3). The web player and streaming app ecosystem has broadly adopted ID3v2.4 since 2010; the hardware car stereo and legacy DJ software ecosystem has not. If a single downstream consumer requires ID3v2.3, the entire output pipeline should use v2_version=3 — there is no mechanism to serve different ID3 versions to different consumers from the same CDN file. The retainer engagement was 1.5h: 0.5h triage (OEM support ticket; Unknown Artist on all normalized tracks; header byte inspection confirmed ID3v2.4 on all CDN files from new pipeline); 0.5h root cause (EasyID3.save() default v2_version=4 confirmed in mutagen source; legacy Python 2 mutagen defaulted to v2.3; Python 3.9 upgrade changed behavior; OEM SDK max v2.3 documented in integration guide); 0.25h fix (audio.save(v2_version=3) in all save() calls; bulk overnight repair script on 50,000 existing files); 0.25h validation (header byte 0x03 confirmed on 10 sample files; OEM device shows artist name on all tested tracks; non-ASCII title confirmed correct UTF-16 encoding; 1.5h total). Hours logged to HourTab with per-session breakdown.

Related retainer posts


Track retainer hours without a client portal

HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.

See pricing →