Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
capture frames in camera-windows
Brendan Allana9195c16f3dc
diff --git a/crates/camera-directshow/src/lib.rs b/crates/camera-directshow/src/lib.rsindex 3fdb620c3..6a85a4c36 100644--- a/crates/camera-directshow/src/lib.rs+++ b/crates/camera-directshow/src/lib.rs@@ -326,7 +326,8 @@ pub struct VideoInputDevice {moniker: IMoniker,prop_bag: IPropertyBag,filter: IBaseFilter,- stream_config: Option<IAMStreamConfig>,+ output_pin: IPin,+ stream_config: IAMStreamConfig,}impl VideoInputDevice {@@ -334,14 +335,16 @@ impl VideoInputDevice {let prop_bag: IPropertyBag = unsafe { moniker.BindToStorage(None, None) }?;let filter: IBaseFilter = unsafe { moniker.BindToObject(None, None) }?;- let stream_config = filter+ let output_pin = filter.get_pin(PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE, GUID::zeroed())- .and_then(|f| f.cast::<IAMStreamConfig>().ok());+ .ok_or(E_FAIL)?;+ let stream_config = output_pin.cast::<IAMStreamConfig>().ok().ok_or(E_FAIL)?;Ok(Self {moniker,prop_bag,filter,+ output_pin,stream_config,})}@@ -369,13 +372,88 @@ impl VideoInputDevice {}pub fn media_types(&self) -> Option<VideoMediaTypesIterator> {- self.stream_config.as_ref().and_then(|stream_config| {- stream_config- .media_types()- .map(|inner| VideoMediaTypesIterator { inner })- .ok()- })+ self.stream_config+ .media_types()+ .map(|inner| VideoMediaTypesIterator { inner })+ .ok()+ }++ pub fn filter(&self) -> &IBaseFilter {+ &self.filter+ }++ pub fn stream_config(&self) -> &IAMStreamConfig {+ &self.stream_config+ }++ pub fn set_format(&mut self, format: &AMMediaType) -> windows_core::Result<()> {+ unsafe { self.stream_config.SetFormat(&**format) }}++ pub fn run(self, callback: SinkCallback) -> Result<RunHandle, RunError> {+ unsafe {+ let sink_filter = SinkFilter::new(callback);++ let input_sink_pin = sink_filter.get_pin(0).ok_or(RunError::NoInputPin)?;++ let graph_builder: IGraphBuilder =+ CoCreateInstance(&CLSID_FilterGraph, None, CLSCTX_INPROC_SERVER)+ .map_err(RunError::CreateGraph)?;++ let capture_graph_builder: ICaptureGraphBuilder2 =+ CoCreateInstance(&CLSID_CaptureGraphBuilder2, None, CLSCTX_INPROC_SERVER)+ .map_err(RunError::CreateGraph)?;++ let media_control = graph_builder+ .cast::<IMediaControl>()+ .expect("Failed to cast IGraphBuilder to IMediaControl");++ capture_graph_builder+ .SetFiltergraph(&graph_builder)+ .map_err(RunError::ConfigureGraph)?;+ graph_builder+ .AddFilter(&self.filter, None)+ .map_err(RunError::ConfigureGraph)?;++ let sink_filter: IBaseFilter = sink_filter+ .cast()+ .expect("Failed to cast SinkFilter to IBaseFilter");++ graph_builder+ .AddFilter(&sink_filter, None)+ .map_err(RunError::ConfigureGraph)?;++ let mut stream_config = null_mut();+ capture_graph_builder+ .FindInterface(+ Some(&PIN_CATEGORY_CAPTURE),+ Some(&MEDIATYPE_Video),+ &self.filter,+ &IAMStreamConfig::IID,+ &mut stream_config,+ )+ .map_err(RunError::ConfigureGraph)?;++ graph_builder+ .ConnectDirect(&self.output_pin, &input_sink_pin, None)+ .map_err(RunError::ConfigureGraph)?;++ media_control.Run().map_err(RunError::Run)?;++ Ok(RunHandle { media_control })+ }+ }+}++pub struct RunHandle {+ media_control: IMediaControl,+}++pub enum RunError {+ NoInputPin,+ CreateGraph(windows_core::Error),+ ConfigureGraph(windows_core::Error),+ Run(windows_core::Error),}impl Deref for VideoInputDevice {@@ -840,12 +918,12 @@ impl IMemInputPin_Impl for SinkInputPin_Impl {let video_info =unsafe { &*(media_type.pbFormat as *const _ as *const KS_VIDEOINFOHEADER) };- println!(- "New frame: {}x{}, {pts}pts, {bytes} bytes, {}",- video_info.bmiHeader.biWidth,- video_info.bmiHeader.biHeight,- format_str.unwrap_or("unknown format")- );+ // println!(+ // "New frame: {}x{}, {pts}pts, {bytes} bytes, {}",+ // video_info.bmiHeader.biWidth,+ // video_info.bmiHeader.biHeight,+ // format_str.unwrap_or("unknown format")+ // );let length = unsafe { psample.GetActualDataLength() };diff --git a/crates/camera-mediafoundation/src/lib.rs b/crates/camera-mediafoundation/src/lib.rsindex d8f2eed83..647e4a7f8 100644--- a/crates/camera-mediafoundation/src/lib.rs+++ b/crates/camera-mediafoundation/src/lib.rs@@ -6,6 +6,7 @@ use std::{mem::MaybeUninit,ops::{Deref, DerefMut},os::windows::ffi::OsStringExt,+ ptr::null_mut,slice::from_raw_parts,};@@ -13,7 +14,8 @@ use windows::Win32::{Media::MediaFoundation::*, System::Com::CoInitialize};use windows_core::PWSTR;pub fn initialize_mediafoundation() -> windows_core::Result<()> {- unsafe { CoInitialize(None) }.ok()+ unsafe { CoInitialize(None) }.ok()?;+ unsafe { MFStartup(MF_API_VERSION, MFSTARTUP_NOSOCKET) }}pub struct DeviceSourcesIterator {@@ -156,6 +158,7 @@ impl Display for Device {}}+#[derive(Clone)]pub struct SourceReader {inner: IMFSourceReader,}@@ -178,6 +181,60 @@ impl SourceReader {.SetCurrentMediaType(stream_index, None, media_type)}}++ pub fn try_read_sample(&self, stream_index: u32) -> windows_core::Result<Option<VideoSample>> {+ let mut imf_sample = None;+ let mut stream_flags = 0;++ let imf_sample = loop {+ unsafe {+ self.ReadSample(+ stream_index,+ 0,+ None,+ Some(&mut stream_flags),+ None,+ Some(&mut imf_sample),+ )?;+ }++ if let Some(imf_sample) = imf_sample {+ break imf_sample;+ }+ };++ if stream_flags as i32 & MF_SOURCE_READERF_CURRENTMEDIATYPECHANGED.0+ == MF_SOURCE_READERF_CURRENTMEDIATYPECHANGED.0+ {+ return Ok(None);+ // selected_format =+ // VideoFormat::new(reader.GetCurrentMediaType(stream_index).unwrap())+ // .unwrap();+ }++ Ok(Some(VideoSample(imf_sample)))+ }+}++pub struct VideoSample(IMFSample);++impl VideoSample {+ pub fn bytes(&self) -> windows_core::Result<Vec<u8>> {+ unsafe {+ let bytes = self.0.GetTotalLength().unwrap();+ let mut out = Vec::with_capacity(bytes as usize);++ let buffer_count = self.0.GetBufferCount()?;+ for buffer_i in 0..buffer_count {+ let buffer = self.0.GetBufferByIndex(buffer_i)?;++ let bytes = buffer.lock()?;+ out.extend(&*bytes);+ }++ Ok(out)+ }+ }}pub struct NativeMediaTypesIterator<'a> {@@ -241,3 +298,48 @@ fn get_device_model_id(device_id: &str) -> Option<String> {Some(format!("{id_vendor}:{id_product}"))}++pub trait IMFMediaBufferExt {+ fn lock(&self) -> windows_core::Result<IMFMediaBufferLock>;+}++impl IMFMediaBufferExt for IMFMediaBuffer {+ fn lock(&self) -> windows_core::Result<IMFMediaBufferLock> {+ let mut bytes_ptr = null_mut();+ let mut size = 0;++ unsafe {+ self.Lock(&mut bytes_ptr, None, Some(&mut size))?;+ }++ Ok(IMFMediaBufferLock {+ source: self,+ bytes: unsafe { std::slice::from_raw_parts_mut(bytes_ptr as *mut u8, size as usize) },+ })+ }+}++pub struct IMFMediaBufferLock<'a> {+ source: &'a IMFMediaBuffer,+ bytes: &'a mut [u8],+}++impl<'a> Drop for IMFMediaBufferLock<'a> {+ fn drop(&mut self) {+ let _ = unsafe { self.source.Unlock() };+ }+}++impl<'a> Deref for IMFMediaBufferLock<'a> {+ type Target = [u8];++ fn deref(&self) -> &Self::Target {+ &self.bytes+ }+}++impl<'a> DerefMut for IMFMediaBufferLock<'a> {+ fn deref_mut(&mut self) -> &mut Self::Target {+ &mut self.bytes+ }+}diff --git a/crates/camera-windows/Cargo.toml b/crates/camera-windows/Cargo.tomlindex 3130a63ee..65e95c58a 100644--- a/crates/camera-windows/Cargo.toml+++ b/crates/camera-windows/Cargo.toml@@ -11,6 +11,7 @@ cap-camera-directshow = { path = "../camera-directshow" }windows = { version = "0.60", features = ["Win32_Media_MediaFoundation"] }windows-core = { version = "0.60" }thiserror.workspace = true+inquire = "0.7.5"[lints]workspace = truediff --git a/crates/camera-windows/examples/cli.rs b/crates/camera-windows/examples/cli.rsindex 8d011f1e0..8a4c8a95b 100644--- a/crates/camera-windows/examples/cli.rs+++ b/crates/camera-windows/examples/cli.rs@@ -1,3 +1,51 @@+use std::ops::Deref;++use cap_camera_windows::*;+fn main() {- dbg!(cap_camera_windows::get_devices().unwrap());+ let devices = get_devices()+ .unwrap()+ .into_iter()+ .map(DeviceSelection)+ .collect::<Vec<_>>();++ let selected_device = inquire::Select::new("Select a device", devices)+ .prompt()+ .unwrap();++ let format = inquire::Select::new("Select a format", selected_device.formats().clone())+ .prompt()+ .unwrap();++ for frame in selected_device.0.start_capturing(&format).unwrap() {+ if let Ok(frame) = frame {+ dbg!(frame.bytes.len(), frame.pixel_format);+ }+ }}++pub struct DeviceSelection(pub VideoDeviceInfo);++impl Deref for DeviceSelection {+ type Target = VideoDeviceInfo;++ fn deref(&self) -> &Self::Target {+ &self.0+ }+}++impl std::fmt::Display for DeviceSelection {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ write!(+ f,+ "{:?} ({})",+ self.0.name(),+ &match self.0.is_mf() {+ true => "Media Foundation",+ false => "DirectShow",+ }+ )+ }+}++pub struct FormatSelection(VideoFormat);diff --git a/crates/camera-windows/src/lib.rs b/crates/camera-windows/src/lib.rsindex 9ac605b64..7c74dfcd2 100644--- a/crates/camera-windows/src/lib.rs+++ b/crates/camera-windows/src/lib.rs@@ -1,23 +1,124 @@#![cfg(windows)]-use cap_camera_directshow::{AM_MEDIA_TYPEVideoExt, AMMediaType};+use cap_camera_directshow::{AM_MEDIA_TYPEExt, AM_MEDIA_TYPEVideoExt, AMMediaType, SinkFilter};+use cap_camera_mediafoundation::{IMFMediaBufferExt, SourceReader};+use ffmpeg::format::Pixel;use std::{- ffi::OsString,+ ffi::{OsStr, OsString},fmt::{Debug, Display},+ ops::Deref,+ ptr::null_mut,+ time::Duration,};-use windows::Win32::Media::MediaFoundation::*;+use windows::Win32::Media::{DirectShow::*, MediaFoundation::*};use windows_core::GUID;#[derive(Clone)]-pub struct DeviceInfo {+pub struct VideoDeviceInfo {id: OsString,name: OsString,model_id: Option<String>,formats: Vec<VideoFormat>,- inner: DeviceInfoInner,+ inner: VideoDeviceInfoInner,}-impl Debug for DeviceInfo {+impl VideoDeviceInfo {+ pub fn id(&self) -> &OsStr {+ &self.id+ }++ pub fn name(&self) -> &OsStr {+ &self.name+ }++ pub fn formats(&self) -> &Vec<VideoFormat> {+ &self.formats+ }++ pub fn is_mf(&self) -> bool {+ matches!(self.inner, VideoDeviceInfoInner::MediaFoundation { .. })+ }++ fn name_and_model(&self) -> String {+ if let Some(model_id) = &self.model_id {+ format!("{} ({model_id})", self.name.to_string_lossy())+ } else {+ self.name.to_string_lossy().to_string()+ }+ }++ pub fn start_capturing<'a>(+ self,+ format: &VideoFormat,+ ) -> windows_core::Result<CaptureIterator> {+ let res = match (self.inner, &format.inner) {+ (+ VideoDeviceInfoInner::MediaFoundation { device, reader },+ VideoFormatInner::MediaFoundation(mf_format),+ ) => {+ let stream_index = MF_SOURCE_READER_FIRST_VIDEO_STREAM.0 as u32;+ let pixel_format = format.pixel_format;++ reader+ .set_current_media_type(stream_index, &mf_format)+ .unwrap();+ unsafe {+ reader.SetStreamSelection(stream_index, true).unwrap();+ }++ Box::new(std::iter::from_fn(move || {+ let sample = match reader.try_read_sample(stream_index) {+ Ok(v) => v?,+ Err(e) => return Some(Err(e)),+ };++ let bytes = match sample.bytes() {+ Ok(v) => v,+ Err(e) => return Some(Err(e)),+ };++ Some(Ok(Frame {+ bytes,+ pixel_format: pixel_format,+ }))+ })) as CaptureIterator+ }+ (+ VideoDeviceInfoInner::DirectShow(mut device),+ VideoFormatInner::DirectShow(format),+ ) => {+ let (tx, rx) = std::sync::mpsc::sync_channel(1);++ device.set_format(format)?;++ let _ = device.run(Box::new(move |buffer, media_type, time_delta| {+ let Some(format) = DSPixelFormat::new(media_type).map(|v| v.format) else {+ return;+ };++ let _ = tx.try_send(Frame {+ bytes: buffer.to_vec(),+ pixel_format: format,+ });+ }));++ Box::new(std::iter::from_fn(move || {+ match rx.recv_timeout(Duration::from_secs(5)) {+ Ok(buffer) => Some(Ok(buffer)),+ Err(e) => None,+ }+ })) as CaptureIterator+ }+ _ => todo!(),+ };++ Ok(res)+ }+}++type CaptureIterator<'a> = Box<dyn Iterator<Item = windows_core::Result<Frame>> + 'a>;++impl Debug for VideoDeviceInfo {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {f.debug_struct("DeviceInfo").field("id", &self.id)@@ -28,31 +129,50 @@ impl Debug for DeviceInfo {}}-impl DeviceInfo {- fn is_mf(&self) -> bool {- matches!(self.inner, DeviceInfoInner::MediaFoundation(_))- }+pub struct Frame {+ pub bytes: Vec<u8>,+ pub pixel_format: PixelFormat,+}- fn name_and_model(&self) -> String {- if let Some(model_id) = &self.model_id {- format!("{} ({model_id})", self.name.to_string_lossy())- } else {- self.name.to_string_lossy().to_string()+#[derive(Debug, Clone, Copy)]+pub enum PixelFormat {+ ARGB,+ RGB24,+ RGB32,+ YUV420P,+ YUYV422,+ UYVY422,+ NV12,+}++impl PixelFormat {+ pub fn as_ffmpeg(&self) -> ffmpeg::format::Pixel {+ match self {+ PixelFormat::YUV420P => Pixel::YUV420P,+ PixelFormat::RGB24 => Pixel::RGB24,+ PixelFormat::RGB32 => Pixel::RGB32,+ PixelFormat::YUYV422 => Pixel::YUYV422,+ PixelFormat::UYVY422 => Pixel::UYVY422,+ PixelFormat::ARGB => Pixel::ARGB,+ PixelFormat::NV12 => Pixel::NV12,}}}#[derive(Clone)]-enum DeviceInfoInner {- MediaFoundation(cap_camera_mediafoundation::Device),+enum VideoDeviceInfoInner {+ MediaFoundation {+ device: cap_camera_mediafoundation::Device,+ reader: cap_camera_mediafoundation::SourceReader,+ },DirectShow(cap_camera_directshow::VideoInputDevice),}-impl Debug for DeviceInfoInner {+impl Debug for VideoDeviceInfoInner {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {match self {Self::DirectShow(_) => write!(f, "DirectShow"),- Self::MediaFoundation(_) => write!(f, "MediaFoundation"),+ Self::MediaFoundation { .. } => write!(f, "MediaFoundation"),}}}@@ -63,7 +183,7 @@ pub enum GetDevicesError {DSDeviceEnumerationFailed(windows_core::Error),}-pub fn get_devices() -> Result<Vec<DeviceInfo>, GetDevicesError> {+pub fn get_devices() -> Result<Vec<VideoDeviceInfo>, GetDevicesError> {let _ = cap_camera_directshow::initialize_directshow();let _ = cap_camera_mediafoundation::initialize_mediafoundation();@@ -79,15 +199,15 @@ pub fn get_devices() -> Result<Vec<DeviceInfo>, GetDevicesError> {let formats = reader.native_media_types(stream_index)?- .filter_map(|t| VideoFormat::new_mf(&t).ok())+ .filter_map(|t| VideoFormat::new_mf(t).ok()).collect::<Vec<_>>();- Ok::<_, windows_core::Error>(DeviceInfo {+ Ok::<_, windows_core::Error>(VideoDeviceInfo {name,id,model_id,formats,- inner: DeviceInfoInner::MediaFoundation(device),+ inner: VideoDeviceInfoInner::MediaFoundation { device, reader },})}).filter_map(|result| match result {@@ -110,15 +230,15 @@ pub fn get_devices() -> Result<Vec<DeviceInfo>, GetDevicesError> {.media_types().into_iter().flatten()- .filter_map(|media_type| VideoFormat::new_ds(&media_type).ok())+ .filter_map(|media_type| VideoFormat::new_ds(media_type).ok()).collect::<Vec<_>>();- Some(DeviceInfo {+ Some(VideoDeviceInfo {name,id,model_id,formats,- inner: DeviceInfoInner::DirectShow(device),+ inner: VideoDeviceInfoInner::DirectShow(device),})}).filter_map(|result| {@@ -133,7 +253,6 @@ pub fn get_devices() -> Result<Vec<DeviceInfo>, GetDevicesError> {for dshow_device in dshow_devices {let name_and_model = dshow_device.name_and_model();- // dbg!(&name_and_model);let mf_device = devices.iter()@@ -155,11 +274,32 @@ pub fn get_devices() -> Result<Vec<DeviceInfo>, GetDevicesError> {}#[derive(Debug, Clone)]-struct VideoFormat {+pub struct VideoFormat {width: u32,height: u32,frame_rate: f32,- pixel_format: ffmpeg::format::Pixel,+ pixel_format: PixelFormat,+ inner: VideoFormatInner,+}++#[derive(Clone)]+pub enum VideoFormatInner {+ MediaFoundation(IMFMediaType),+ DirectShow(AMMediaType),+}++impl Debug for VideoFormatInner {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ f.debug_struct("VideoFormatInner")+ .field(+ "variant",+ &match self {+ VideoFormatInner::MediaFoundation(_) => "MediaFoundation",+ VideoFormatInner::DirectShow(_) => "DirectShow",+ },+ )+ .finish()+ }}#[derive(thiserror::Error, Debug)]@@ -173,7 +313,7 @@ pub enum VideoFormatError {}impl VideoFormat {- fn new_mf(inner: &IMFMediaType) -> Result<Self, VideoFormatError> {+ fn new_mf(inner: IMFMediaType) -> Result<Self, VideoFormatError> {if unsafe { inner.GetMajorType()? } != MFMediaType_Video {return Err(VideoFormatError::NotVideo);}@@ -198,11 +338,12 @@ impl VideoFormat {frame_rate,pixel_format: MFPixelFormat::new(subtype).ok_or(VideoFormatError::InvalidPixelFormat(subtype))?- .as_ffmpeg(),+ .format,+ inner: VideoFormatInner::MediaFoundation(inner),})}- fn new_ds(inner: &AMMediaType) -> Result<Self, VideoFormatError> {+ fn new_ds(inner: AMMediaType) -> Result<Self, VideoFormatError> {if inner.majortype != MFMediaType_Video {return Err(VideoFormatError::NotVideo);}@@ -214,9 +355,10 @@ impl VideoFormat {height: video_info.bmiHeader.biHeight as u32,frame_rate: ((10_000_000.0 / video_info.AvgTimePerFrame as f32) * 100.0).round()/ 100.0,- pixel_format: DSPixelFormat::new(inner)+ pixel_format: DSPixelFormat::new(&inner).ok_or(VideoFormatError::InvalidPixelFormat(inner.subtype))?- .as_ffmpeg(),+ .format,+ inner: VideoFormatInner::DirectShow(inner),})}}@@ -229,69 +371,73 @@ impl Display for VideoFormat {}struct MFPixelFormat {- ffmpeg: ffmpeg::format::Pixel,+ format: PixelFormat,mf: GUID,}impl MFPixelFormat {fn new(subtype: GUID) -> Option<Self> {- use ffmpeg::format::Pixel;-- let get_ffmpeg = || {+ let get_format = || {Some(match subtype {- t if t == MFVideoFormat_I420 || t == MFVideoFormat_IYUV => Pixel::YUV420P,- t if t == MFVideoFormat_RGB24 => Pixel::RGB24,- t if t == MFVideoFormat_RGB32 => Pixel::RGB32,- t if t == MFVideoFormat_YUY2 => Pixel::YUYV422,- t if t == MFVideoFormat_UYVY => Pixel::UYVY422,- t if t == MFVideoFormat_ARGB32 => Pixel::ARGB,- t if t == MFVideoFormat_NV12 => Pixel::NV12,+ t if t == MFVideoFormat_I420 || t == MFVideoFormat_IYUV => PixelFormat::YUV420P,+ t if t == MFVideoFormat_RGB24 => PixelFormat::RGB24,+ t if t == MFVideoFormat_RGB32 => PixelFormat::RGB32,+ t if t == MFVideoFormat_YUY2 => PixelFormat::YUYV422,+ t if t == MFVideoFormat_UYVY => PixelFormat::UYVY422,+ t if t == MFVideoFormat_ARGB32 => PixelFormat::ARGB,+ t if t == MFVideoFormat_NV12 => PixelFormat::NV12,_ => return None,})};Some(Self {- ffmpeg: get_ffmpeg()?,+ format: get_format()?,mf: subtype,})}+}- pub fn as_ffmpeg(&self) -> ffmpeg::format::Pixel {- self.ffmpeg+impl Deref for MFPixelFormat {+ type Target = PixelFormat;++ fn deref(&self) -> &Self::Target {+ &self.format}}struct DSPixelFormat {- ffmpeg: ffmpeg::format::Pixel,+ format: PixelFormat,ds: GUID,}+impl Deref for DSPixelFormat {+ type Target = PixelFormat;++ fn deref(&self) -> &Self::Target {+ &self.format+ }+}+impl DSPixelFormat {fn new(major_type: &AM_MEDIA_TYPE) -> Option<Self> {- use ffmpeg::format::Pixel;-let subtype = major_type.subtype;let get_ffmpeg = || {Some(match subtype {- t if t == MEDIASUBTYPE_I420 || t == MEDIASUBTYPE_IYUV => Pixel::YUV420P,- t if t == MEDIASUBTYPE_RGB24 => Pixel::RGB24,- t if t == MEDIASUBTYPE_RGB32 => Pixel::RGB32,- t if t == MEDIASUBTYPE_YUY2 => Pixel::YUYV422,- t if t == MEDIASUBTYPE_UYVY => Pixel::UYVY422,- t if t == MEDIASUBTYPE_ARGB32 => Pixel::ARGB,- t if t == MEDIASUBTYPE_NV12 => Pixel::NV12,+ t if t == MEDIASUBTYPE_I420 || t == MEDIASUBTYPE_IYUV => PixelFormat::YUV420P,+ t if t == MEDIASUBTYPE_RGB24 => PixelFormat::RGB24,+ t if t == MEDIASUBTYPE_RGB32 => PixelFormat::RGB32,+ t if t == MEDIASUBTYPE_YUY2 => PixelFormat::YUYV422,+ t if t == MEDIASUBTYPE_UYVY => PixelFormat::UYVY422,+ t if t == MEDIASUBTYPE_ARGB32 => PixelFormat::ARGB,+ t if t == MEDIASUBTYPE_NV12 => PixelFormat::NV12,_ => return None,})};Some(Self {- ffmpeg: get_ffmpeg()?,+ format: get_ffmpeg()?,ds: subtype,})}-- pub fn as_ffmpeg(&self) -> ffmpeg::format::Pixel {- self.ffmpeg- }}