From 731de5c0d5b778100015fb035a7aa2aa7404053e Mon Sep 17 00:00:00 2001 From: MilkClouds Date: Tue, 9 Jul 2024 21:32:58 +0900 Subject: [PATCH 1/2] feature: can set fps and added av1/vp9 codec --- README.md | 3 ++- examples/basic.rs | 7 ++++--- src/encoder.rs | 27 ++++++++++++++++++++++++++- src/lib.rs | 3 ++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9664137..e81f27f 100644 --- a/README.md +++ b/README.md @@ -71,11 +71,12 @@ impl GraphicsCaptureApiHandler for Capture { println!("Got The Flag: {message}"); let encoder = VideoEncoder::new( - VideoEncoderType::Mp4, + VideoEncoderType::Hevc, VideoEncoderQuality::HD1080p, 1920, 1080, "video.mp4", + Some(30), )?; Ok(Self { diff --git a/examples/basic.rs b/examples/basic.rs index b7764fe..4acca67 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -32,11 +32,12 @@ impl GraphicsCaptureApiHandler for Capture { println!("Got The Flag: {message}"); let encoder = VideoEncoder::new( - VideoEncoderType::Mp4, + VideoEncoderType::Hevc, VideoEncoderQuality::HD1080p, - 1920, - 1080, + 2560, + 1440, "video.mp4", + Some(30), )?; Ok(Self { diff --git a/src/encoder.rs b/src/encoder.rs index aa968ee..172d352 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -159,6 +159,8 @@ pub enum VideoEncoderType { Hevc, Mp4, Wmv, + Av1, + Vp9, } #[derive(Eq, PartialEq, Clone, Copy, Debug)] @@ -214,6 +216,7 @@ impl VideoEncoder { width: u32, height: u32, path: P, + fps: Option, ) -> Result { let path = path.as_ref(); @@ -230,6 +233,12 @@ impl VideoEncoder { VideoEncoderType::Wmv => { MediaEncodingProfile::CreateWmv(VideoEncodingQuality(encoder_quality as i32))? } + VideoEncoderType::Av1 => { + MediaEncodingProfile::CreateAv1(VideoEncodingQuality(encoder_quality as i32))? + } + VideoEncoderType::Vp9 => { + MediaEncodingProfile::CreateVp9(VideoEncodingQuality(encoder_quality as i32))? + } }; media_encoding_profile .Video()? @@ -237,7 +246,17 @@ impl VideoEncoder { media_encoding_profile .Video()? .SetHeight(height)?; - + if fps.is_some() { + media_encoding_profile + .Video()? + .FrameRate()? + .SetNumerator(fps.unwrap())?; + media_encoding_profile + .Video()? + .FrameRate()? + .SetDenominator(1)?; + } + let video_encoding_properties = VideoEncodingProperties::CreateUncompressed( &MediaEncodingSubtypes::Bgra8()?, width, @@ -403,6 +422,12 @@ impl VideoEncoder { VideoEncoderType::Wmv => { MediaEncodingProfile::CreateWmv(VideoEncodingQuality(encoder_quality as i32))? } + VideoEncoderType::Av1 => { + MediaEncodingProfile::CreateAv1(VideoEncodingQuality(encoder_quality as i32))? + } + VideoEncoderType::Vp9 => { + MediaEncodingProfile::CreateVp9(VideoEncodingQuality(encoder_quality as i32))? + } }; let video_encoding_properties = VideoEncodingProperties::CreateUncompressed( diff --git a/src/lib.rs b/src/lib.rs index 4a76d74..3a904df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,11 +67,12 @@ //! println!("Got The Flag: {message}"); //! //! let encoder = VideoEncoder::new( -//! VideoEncoderType::Mp4, +//! VideoEncoderType::Hevc, //! VideoEncoderQuality::HD1080p, //! 1920, //! 1080, //! "video.mp4", +//! Some(30), //! )?; //! //! Ok(Self { From 1825095d203fe79b4d87c00d7f8cd65cf8efea43 Mon Sep 17 00:00:00 2001 From: MilkClouds Date: Tue, 9 Jul 2024 21:34:45 +0900 Subject: [PATCH 2/2] Update basic.rs --- examples/basic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/basic.rs b/examples/basic.rs index 4acca67..9c06a37 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -34,8 +34,8 @@ impl GraphicsCaptureApiHandler for Capture { let encoder = VideoEncoder::new( VideoEncoderType::Hevc, VideoEncoderQuality::HD1080p, - 2560, - 1440, + 1920, + 1080, "video.mp4", Some(30), )?;