feat(linux): add zero-copy v4l2 encoder - #5717
Draft
GenshinImpactStarts wants to merge 6 commits into
Draft
GenshinImpactStarts wants to merge 6 commits into
GenshinImpactStarts wants to merge 6 commits into
Conversation
add add add
cmake cmake
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Description
This PR introduces a zero-copy V4L2 hardware encoder path on Linux, targeting embedded devices such as Raspberry Pi. It currently supports baseline YUV420 8-bit encoding, integrates with existing capture backends, and syncs with the Web UI settings. The implementation follows the VAAPI approach: exporting DMA-BUF fds and using EGL for color conversion.
Implementation
Required AVCodec integration changes
The V4L2 M2M path differs from the existing AVCodec initialization and usage paths, so several supporting changes were necessary:
avcodec_encode_device_t:load_opened_context: retrieves the AVCodec context during encoder initialization to extract V4L2 DMA-BUFs.send_frame: V4L2 buffers are managed by FFmpeg, so additional metadata must be passed during encoding to interact with the FFmpeg patches.validate_configpath now manually passes a terminating packet (nullptr) to flush the encoder.validate_confignow records the packet count of the first frame and concatenates them when the actual packets are produced.eglCreateImage,eglDestroyImage,FramebufferTexture). Fallbacks are provided for these older drivers.Testing and limitations
Tested only on Raspberry Pi 4B running Debian 12. Due to limitations, I was unable to compile on Windows, so the impact on other codecs has not been tested. It would be helpful if CI could generate artifacts for further testing.
This PR is quite large, so I've roughly split the changes into logical commits; it's best reviewed commit by commit.
Note: This PR depends on LizardByte/build-deps#781, which adds the two required FFmpeg patches for V4L2 zero-copy support.
Screenshot
Issues Fixed or Closed
Roadmap Issues
Type of Change
Checklist
AI Usage
See our AI usage policy.