Skip to content

feat: add hardware frame context wrappers - #274

Open
jb-alvarado wants to merge 9 commits into
zmwangx:masterfrom
jb-alvarado:feature/hardware-contexts
Open

feat: add hardware frame context wrappers#274
jb-alvarado wants to merge 9 commits into
zmwangx:masterfrom
jb-alvarado:feature/hardware-contexts

Conversation

@jb-alvarado

Copy link
Copy Markdown
Contributor

Expose safe wrappers for FFmpeg hardware device and frame contexts, including frame allocation and software-to-hardware uploads. Allow video encoders to receive a cloned hardware frame context before opening.

Expose safe wrappers for FFmpeg hardware device and frame contexts, including frame allocation and software-to-hardware uploads. Allow video encoders to receive a cloned hardware frame context before opening.
Comment thread src/util/hardware.rs Outdated
#[inline]
pub fn upload(&self, source: &frame::Video) -> Result<frame::Video, Error> {
let mut destination = self.allocate_video()?;
destination.set_pts(source.pts());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this needs the full av_frame_copy_props, not only pts

@AdrianEddy

Copy link
Copy Markdown
Collaborator
  1. No way to wrap an existing device or frames context. Device can only be built by av_hwdevice_ctx_create, and Frames only by allocating a fresh one. So the decode-hw → encode-hw zero-copy path is impossible with this API: you can't take a decoder's (*frame).hw_frames_ctx and hand it to the encoder.
  2. I'd be nice to expose the initial_pool_size, as some backends need to tune that value
  3. pix_fmt isn't set, and the doc comment doesn't say you must. avcodec_open2 fails if pix_fmt isn't the hardware format. Since Frames already knows its format, set_hardware_frames could just do it.
  4. I'd be nice to add download() too for symmetry
  5. No set_hardware_device on the encoder.
  6. Device::create takes the raw AVHWDeviceType ffi enum, which leaks ffi into a safe wrapper.

@jb-alvarado

Copy link
Copy Markdown
Contributor Author

Thanks @AdrianEddy, for reviewing my pull request. I implemented your suggestions and added also an example.

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