Encoding of "media" file

Hi,

First of all, thank you for your work on Anki. It’s an amazing tool that helps so many people around the world.

I’m developing a C++ library to create Anki cards (ankicpp), and I’ve made some progress so far. I’m now able to create basic, reversed, and cloze cards.

However, I’m facing a challenge with media handling, specifically when generating the media file before packaging everything into an .apkg file.

I’ve noticed that Anki uses a specific binary format for the media file, with some metadata or fields preceding each image entry. However, I haven’t been able to figure out the purpose of all the bytes.

For example, when packaging a single image named flynn.jpeg, Anki generates the following byte sequence (grouped into 16-bit hexadecimal values for readability)

28b5(????) 2ffd(????) 0058(????)
3901(????) 000a(????) 250a(????)
0a66( LFf) 6c79(  ly) 6e6e(  nn)
2e6a(  .j) 7065(  pe) 6710(g???)
6569(????) 1a14(????) 4c7d(sha1)
63dc(sha1) b087(sha1) e1a5(sha1)
f461(sha1) 6759(sha1) 8461(sha1)
d9c7(sha1) 717a(sha1) 09d6(sha1)

Could you help me understand what the first 24 bytes represent, as well as the 8 bytes immediately preceding the SHA-1 hash?

I apologize if my question isn’t entirely clear. Essentially, I’m trying to understand the structure and purpose of each field in the final media file so that I can implement the export process independently in my C++ library.

Thank you for your time and for your work on Anki!

Best regards,
Natan

It’s a zstd-compressed Protobuf message:

Thanks for your response, Abdo! It was very helpful.

Since you’re already following my post, I have just one more question.

The fields below are also Protobuf messages, right?

fields.config
templates.config
notetypes.config

That’s right.

Thanks.