sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.76k stars 566 forks source link

Special characters in apple metadata box TYPEs converted to UTF-8 (Android) #282

Open andymstone opened 6 years ago

andymstone commented 6 years ago

I've had a problem writing metadata into an mp4 in an Android app using e.g. AppleNameBox. The problem stems from lines like:

public static final String TYPE = "©nam";

When the meta data is written the copyright symbol is written as two characters (0xC2 0xA9) and then the 'm' is dropped off the end of the 4 digit type name. The resulting metadata entries are then not usable by other software.

I believe this is because the String is being stored as UTF-8 so the copyright symbol is encoded as two bytes in the String. A simple workaround is to specify the encoded character explicitly in all of the affected boxes:

public static final String TYPE = "\u00A9nam";

A better solution might be to use a char array/byte array to store the types, but that would involve changes up the class hierarchy.