use crate::event::VideoStream;
pub fn get_bits_per_pixel(pix_fmt: &str) -> Option<u32> {
match pix_fmt {
"yuv420p" => Some(12),
"yuyv422" => Some(16),
"rgb24" => Some(24),
"bgr24" => Some(24),
"yuv422p" => Some(16),
"yuv444p" => Some(24),
"yuv410p" => Some(9),
"yuv411p" => Some(12),
"gray" => Some(8),
"monow" => Some(1),
"monob" => Some(1),
"pal8" => Some(8),
"yuvj420p" => Some(12),
"yuvj422p" => Some(16),
"yuvj444p" => Some(24),
"uyvy422" => Some(16),
"uyyvyy411" => Some(12),
"bgr8" => Some(8),
"bgr4" => Some(4),
"rgb8" => Some(8),
"rgb4" => Some(4),
"nv12" => Some(12),
"nv21" => Some(12),
"argb" => Some(32),
"rgba" => Some(32),
"abgr" => Some(32),
"bgra" => Some(32),
"gray16be" => Some(16),
"gray16le" => Some(16),
"yuv440p" => Some(16),
"yuvj440p" => Some(16),
"yuva420p" => Some(20),
"rgb48be" => Some(48),
"rgb48le" => Some(48),
"rgb565be" => Some(16),
"rgb565le" => Some(16),
"rgb555be" => Some(15),
"rgb555le" => Some(15),
"bgr565be" => Some(16),
"bgr565le" => Some(16),
"bgr555be" => Some(15),
"bgr555le" => Some(15),
"vaapi" => Some(0),
"yuv420p16le" => Some(24),
"yuv420p16be" => Some(24),
"yuv422p16le" => Some(32),
"yuv422p16be" => Some(32),
"yuv444p16le" => Some(48),
"yuv444p16be" => Some(48),
"dxva2" => Some(0),
"rgb444le" => Some(12),
"rgb444be" => Some(12),
"bgr444le" => Some(12),
"bgr444be" => Some(12),
"ya8" => Some(16),
"bgr48be" => Some(48),
"bgr48le" => Some(48),
"yuv420p9be" => Some(13),
"yuv420p9le" => Some(13),
"yuv420p10be" => Some(15),
"yuv420p10le" => Some(15),
"yuv422p10be" => Some(20),
"yuv422p10le" => Some(20),
"yuv444p9be" => Some(27),
"yuv444p9le" => Some(27),
"yuv444p10be" => Some(30),
"yuv444p10le" => Some(30),
"yuv422p9be" => Some(18),
"yuv422p9le" => Some(18),
"gbrp" => Some(24),
"gbrp9be" => Some(27),
"gbrp9le" => Some(27),
"gbrp10be" => Some(30),
"gbrp10le" => Some(30),
"gbrp16be" => Some(48),
"gbrp16le" => Some(48),
"yuva422p" => Some(24),
"yuva444p" => Some(32),
"yuva420p9be" => Some(22),
"yuva420p9le" => Some(22),
"yuva422p9be" => Some(27),
"yuva422p9le" => Some(27),
"yuva444p9be" => Some(36),
"yuva444p9le" => Some(36),
"yuva420p10be" => Some(25),
"yuva420p10le" => Some(25),
"yuva422p10be" => Some(30),
"yuva422p10le" => Some(30),
"yuva444p10be" => Some(40),
"yuva444p10le" => Some(40),
"yuva420p16be" => Some(40),
"yuva420p16le" => Some(40),
"yuva422p16be" => Some(48),
"yuva422p16le" => Some(48),
"yuva444p16be" => Some(64),
"yuva444p16le" => Some(64),
"vdpau" => Some(0),
"xyz12le" => Some(36),
"xyz12be" => Some(36),
"nv16" => Some(16),
"nv20le" => Some(20),
"nv20be" => Some(20),
"rgba64be" => Some(64),
"rgba64le" => Some(64),
"bgra64be" => Some(64),
"bgra64le" => Some(64),
"yvyu422" => Some(16),
"ya16be" => Some(32),
"ya16le" => Some(32),
"gbrap" => Some(32),
"gbrap16be" => Some(64),
"gbrap16le" => Some(64),
"qsv" => Some(0),
"mmal" => Some(0),
"d3d11va" => Some(0),
"cuda" => Some(0),
"0rgb" => Some(24),
"rgb0" => Some(24),
"0bgr" => Some(24),
"bgr0" => Some(24),
"yuv420p12be" => Some(18),
"yuv420p12le" => Some(18),
"yuv420p14be" => Some(21),
"yuv420p14le" => Some(21),
"yuv422p12be" => Some(24),
"yuv422p12le" => Some(24),
"yuv422p14be" => Some(28),
"yuv422p14le" => Some(28),
"yuv444p12be" => Some(36),
"yuv444p12le" => Some(36),
"yuv444p14be" => Some(42),
"yuv444p14le" => Some(42),
"gbrp12be" => Some(36),
"gbrp12le" => Some(36),
"gbrp14be" => Some(42),
"gbrp14le" => Some(42),
"yuvj411p" => Some(12),
"bayer" => Some(3),
"xvmc" => Some(0),
"yuv440p10le" => Some(20),
"yuv440p10be" => Some(20),
"yuv440p12le" => Some(24),
"yuv440p12be" => Some(24),
"ayuv64le" => Some(64),
"ayuv64be" => Some(64),
"videotoolbox" => Some(0),
"p010le" => Some(15),
"p010be" => Some(15),
"gbrap12be" => Some(48),
"gbrap12le" => Some(48),
"gbrap10be" => Some(40),
"gbrap10le" => Some(40),
"mediacodec" => Some(0),
"gray12be" => Some(12),
"gray12le" => Some(12),
"gray10be" => Some(10),
"gray10le" => Some(10),
"p016le" => Some(24),
"p016be" => Some(24),
"d3d11" => Some(0),
"gray9be" => Some(9),
"gray9le" => Some(9),
"gbrpf32be" => Some(96),
"gbrpf32le" => Some(96),
"gbrapf32be" => Some(128),
"gbrapf32le" => Some(128),
"drm" => Some(0),
"opencl" => Some(0),
"gray14be" => Some(14),
"gray14le" => Some(14),
"grayf32be" => Some(32),
"grayf32le" => Some(32),
"yuva422p12be" => Some(36),
"yuva422p12le" => Some(36),
"yuva444p12be" => Some(48),
"yuva444p12le" => Some(48),
"nv24" => Some(24),
"nv42" => Some(24),
"vulkan" => Some(0),
"y210be" => Some(20),
"y210le" => Some(20),
"x2rgb10le" => Some(30),
"x2rgb10be" => Some(30),
"x2bgr10le" => Some(30),
"x2bgr10be" => Some(30),
"p210be" => Some(20),
"p210le" => Some(20),
"p410be" => Some(30),
"p410le" => Some(30),
"p216be" => Some(32),
"p216le" => Some(32),
"p416be" => Some(48),
"p416le" => Some(48),
"vuya" => Some(32),
"rgbaf16be" => Some(64),
"rgbaf16le" => Some(64),
"vuyx" => Some(24),
"p012le" => Some(18),
"p012be" => Some(18),
"y212be" => Some(24),
"y212le" => Some(24),
"xv30be" => Some(30),
"xv30le" => Some(30),
"xv36be" => Some(36),
"xv36le" => Some(36),
"rgbf32be" => Some(96),
"rgbf32le" => Some(96),
"rgbaf32be" => Some(128),
"rgbaf32le" => Some(128),
_ => None,
}
}
pub fn get_bytes_per_frame(video_data: &VideoStream) -> Option<u32> {
let bits_per_pixel = get_bits_per_pixel(&video_data.pix_fmt)?;
let num_bits = video_data.width * video_data.height * bits_per_pixel;
match num_bits % 8 {
0 => Some(num_bits / 8),
_ => None,
}
}