Skip to content

Support custom codec - #3383

Draft
tongyuantongyu wants to merge 6 commits into
AOMediaCodec:mainfrom
tongyuantongyu:custom-codec
Draft

tongyuantongyu wants to merge 6 commits into
AOMediaCodec:mainfrom
tongyuantongyu:custom-codec

Conversation

@tongyuantongyu

Copy link
Copy Markdown
Contributor

Expose codec interface in a new header codec.h so custom codecs can be registered and used by libavif.

I made this while building my own tool that performs batched hardware encoding using a long-living GPU encode session. At its best it may be added to contrib/ after some more polishing, but it's definitely too niche to be accepted as a built-in codec.

This PR allows anyone to add another codec into libavif without hacking into the library code.

@tongyuantongyu
tongyuantongyu marked this pull request as draft September 27, 2026 12:22
@tongyuantongyu

Copy link
Copy Markdown
Contributor Author

@y-guyon I saw your PR #2381. I think allowing users to implement their own codec is better than adding callback.

​+ @wantehchang @maryla-uc Asking if we want this feature. We probably need to refactor the codec interface to be forward-compatible and versioned, so I want to hear your opinion before working on this further.

@y-guyon

y-guyon commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

I think allowing users to implement their own codec is better than adding callback.

Could you describe what is better exactly? I agree it probably is more complete and powerful, but it also exposes more internal stuff in the public API. I am fine with both approaches, I just wonder if the work is worth it overall. Also maybe CrabbyAvif is a more future-looking location for such a feature.

@tongyuantongyu

Copy link
Copy Markdown
Contributor Author

Could you describe what is better exactly?

customEncodeImageFunc and customEncodeFinishFunc are basically encodeImage and encodeFinish that built-in codecs would implement and replace them when present. Yet the user still have to select a built-in codec, let its avifCodecCreate* and destroyInternal be called without doing anything. It's confusing and wasteful, and more importantly, it forces developers to ship at least one built-in codec, that will never be used, in order to use their custom codec.

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.

2 participants