diff --git a/changes.d/pr-519.toml b/changes.d/pr-519.toml new file mode 100644 index 000000000..0198b65d4 --- /dev/null +++ b/changes.d/pr-519.toml @@ -0,0 +1,4 @@ +[[scuffle-ffmpeg]] +category = "feat" +description = "added a method for accessing the raw data of a frame" +authors = ["@timleg002"] diff --git a/crates/ffmpeg/src/frame.rs b/crates/ffmpeg/src/frame.rs index 075d6118b..947ea53a3 100644 --- a/crates/ffmpeg/src/frame.rs +++ b/crates/ffmpeg/src/frame.rs @@ -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] { + // 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() {