Skip to content

Commit

Permalink
Merge pull request #63 from MilkClouds/feature/fps-set-codec-add
Browse files Browse the repository at this point in the history
feature: can set fps and added av1/vp9 codec
  • Loading branch information
NiiightmareXD authored Jul 11, 2024
2 parents 6552bac + 1825095 commit 3691f5f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"video.mp4",
Some(30),
)?;

Ok(Self {
Expand Down
27 changes: 26 additions & 1 deletion src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ pub enum VideoEncoderType {
Hevc,
Mp4,
Wmv,
Av1,
Vp9,
}

#[derive(Eq, PartialEq, Clone, Copy, Debug)]
Expand Down Expand Up @@ -214,6 +216,7 @@ impl VideoEncoder {
width: u32,
height: u32,
path: P,
fps: Option<u32>,
) -> Result<Self, VideoEncoderError> {
let path = path.as_ref();

Expand All @@ -230,14 +233,30 @@ 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()?
.SetWidth(width)?;
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,
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3691f5f

Please sign in to comment.