Skip to content

Conversation

@skidder
Copy link
Contributor

@skidder skidder commented Jun 21, 2025

Summary

This PR introduces AV1 video codec support to lilliput, adding the dav1d AV1 decoding library to FFmpeg for improved AV1 and AVIF processing performance. It also ensures comprehensive dependency header coverage and licensing compliance across all platforms.

Key Changes

Core Features

  • AV1 Video Decoding: Feature-flagged support for AV1 encoded video recognition and decoding
  • dav1d Integration: Added the high-performance dav1d AV1 decoder library to FFmpeg
  • AVIF Performance: Faster AVIF decoding through libavif's dav1d backend
  • Security Model: AV1 support is disabled by default, following the same pattern as HEVC

Implementation Details

Build System Updates:

  • Added dav1d 1.5.1 library with meson build system support
  • Updated FFmpeg configuration to enable AV1 decoders (--enable-decoder=av1, --enable-libdav1d)
  • Enhanced libavif to use both libaom and dav1d codecs for optimal performance
  • Cross-platform support for macOS ARM64 and Linux (AMD64/ARM64)

Dependency Infrastructure:

  • Complete header coverage: Added native dependency header includes for all Linux platforms, including previously missing headers
  • License compliance: Ensured all dependencies have corresponding license files in third-party-licenses/
  • Updated build manifests: Refreshed dependency build info files with new library versions and checksums

Code Changes:

  • Feature flag av1Enabled controls AV1 support (disabled by default)
  • Updated avcodec_decoder_create() to accept AV1 enablement parameter
  • Added codec gating logic to reject AV1 content when disabled
  • Enhanced error handling and null pointer checks in decoder functions

Testing:

  • Added comprehensive AV1 test coverage in avcodec_test.go
  • Included test AV1 video file (testdata/av1-mp4.mp4)
  • Tests verify both disabled (default) and enabled states

Usage

Enable AV1 support:

go build -ldflags="-X=github.com/discord/lilliput.av1Enabled=true"

Run AV1 tests:

go test -ldflags="-X=github.com/discord/lilliput.av1Enabled=true"

Dependencies Added

  • dav1d 1.5.1: High-performance AV1 decoder by VideoLAN
  • meson/ninja: Build system for dav1d compilation
  • Updated dependency manifests and build info
  • Complete header file coverage across all supported platforms
  • Corresponding license files for all dependencies

Security Considerations

  • AV1 decoding is disabled by default for security
  • Follows established pattern from HEVC feature flag implementation
  • Requires explicit opt-in via build flag to enable AV1 support

References

This implementation provides a foundation for efficient AV1 video processing while maintaining lilliput's security-first approach to codec support and ensuring complete dependency management across all supported platforms.

@skidder skidder force-pushed the feature/av1-support branch 2 times, most recently from 43388a3 to e25a6ca Compare June 22, 2025 14:20
This commit adds support for AV1 video decoding in lilliput, following
the same pattern as HEVC support with build flag gating.

Changes:
- Add AV1 decoder enablement behind build flag (av1Enabled)
- Update FFmpeg build scripts to include --enable-decoder=av1 and --enable-libaom
- Add codec gating logic to reject AV1 when disabled (default)
- Add basic tests for AV1 support and decoder creation
- Include test AV1 video file for validation

Usage:
Enable AV1 support: go build -ldflags="-X=github.com/discord/lilliput.av1Enabled=true"

Features:
- AV1 video detection in containers (MP4, WebM, etc.)
- First-frame extraction from AV1 videos
- Same security model as HEVC (disabled by default)
@skidder skidder force-pushed the feature/av1-support branch from 06616f5 to 314f0d3 Compare June 23, 2025 14:11
@skidder skidder marked this pull request as ready for review June 23, 2025 14:44
static int avcodec_decoder_copy_frame(const avcodec_decoder d, opencv_mat mat, AVFrame* frame)
{
if (!d || !d->codec || !d->codec->codec || !mat || !frame) {
return -1;
Copy link
Contributor

@salarkhan salarkhan Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some point (not in this pr) we should probably move to more modern c++ features like std::optional/std::expected instead of spitting out -1 for errs no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure - in the meantime I think we should stick with numeric return codes, as C++ exceptions have bitten us recently.

Copy link
Contributor

@salarkhan salarkhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignored all the .h or .a files, but the rest lgtm

@skidder skidder merged commit 1281d19 into master Jun 23, 2025
8 checks passed
@skidder skidder deleted the feature/av1-support branch June 23, 2025 16:48
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.

3 participants