Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changes.d/pr-519.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[scuffle-ffmpeg]]
category = "feat"
description = "added a method for accessing the raw data of a frame"
authors = ["@timleg002"]
11 changes: 11 additions & 0 deletions crates/ffmpeg/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ impl FrameData {
Some(unsafe { core::slice::from_raw_parts_mut(start_ptr.as_ptr(), self.linesize.unsigned_abs() as usize) })
}

/// Returns the entire data buffer
pub fn get_all(&self) -> &[u8] {
Copy link
Member

Choose a reason for hiding this comment

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

I am not a huge fan of the name of this function. I think we should also add a comment about alignment / padding values. Perhaps get_buffer

Since these lines also include the padding values / alignment and is not just the raw frame data.

// Safety: the pointer is within bounds & this slice is valid
unsafe {
core::slice::from_raw_parts_mut(
self.ptr.as_ptr(),
self.linesize.unsigned_abs() as usize * self.height.unsigned_abs() as usize,
)
}
}

/// Fills the data buffer with `value`
pub fn fill(&mut self, value: u8) {
for row in 0..self.height() {
Expand Down