Skip to content

Read and write metadata as UTF-8 with surrogateescape - #2386

Merged
WyattBlue merged 1 commit into
mainfrom
patch
Aug 18, 2026
Merged

Read and write metadata as UTF-8 with surrogateescape#2386
WyattBlue merged 1 commit into
mainfrom
patch

Conversation

@WyattBlue

Copy link
Copy Markdown
Member

metadata_encoding and metadata_errors made the caller pick one encoding for a whole container, which cannot represent a file that mixes them across tags. FFmpeg stores tags as bytes with no declared encoding, so decode them the way Python decodes filesystem paths. Valid UTF-8 will read normally, while anything else survives as surrogates and encodes back unchanged. A tag in another encoding can be recovered per key with:

value.encode("utf-8", "surrogateescape").decode("cp1251")

Drops both fields, making a container 16 bytes smaller.

metadata_encoding and metadata_errors made the caller pick one encoding
for a whole container, which cannot represent a file that mixes them
across tags. FFmpeg stores tags as bytes with no declared encoding, so
decode them the way Python decodes filesystem paths. Valid UTF-8 will
read normally, while anything else survives as surrogates and encodes
back unchanged. A tag in another encoding can be recovered per key with:

    value.encode("utf-8", "surrogateescape").decode("cp1251")

Drops both fields, making a container 16 bytes smaller.
@WyattBlue
WyattBlue merged commit 3c92201 into main Aug 18, 2026
8 checks passed
@WyattBlue
WyattBlue deleted the patch branch August 18, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant