Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
446 changes: 344 additions & 102 deletions crates/enc-ffmpeg/src/mux/segmented_stream.rs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions crates/enc-ffmpeg/src/video/h264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,13 @@ fn get_bitrate(width: u32, height: u32, frame_rate: f32, bpp: f32) -> usize {
((pixels_per_second * bpp as f64) as usize).min(MAX_BITRATE)
}

/// Bitrate this module's encoders target for `bpp`, so a hardware encoder fed straight from the
/// capture texture keeps the recording quality of the software path.
pub fn bitrate_for_bpp(width: u32, height: u32, frame_rate: ffmpeg::Rational, bpp: f32) -> u32 {
let fps = frame_rate.0 as f32 / frame_rate.1.max(1) as f32;
get_bitrate(width, height, fps, bpp) as u32
}

const MAX_BITRATE: usize = 1_000_000_000;

#[cfg(test)]
Expand Down
13 changes: 9 additions & 4 deletions crates/enc-mediafoundation/src/d3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use windows::Win32::Graphics::{
D3D_DRIVER_TYPE, D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_UNKNOWN, D3D_DRIVER_TYPE_WARP,
},
Direct3D11::{
D3D11_CREATE_DEVICE_BGRA_SUPPORT, D3D11_CREATE_DEVICE_FLAG, D3D11_SDK_VERSION,
D3D11CreateDevice, ID3D11Device,
D3D11_CREATE_DEVICE_BGRA_SUPPORT, D3D11_CREATE_DEVICE_FLAG,
D3D11_CREATE_DEVICE_VIDEO_SUPPORT, D3D11_SDK_VERSION, D3D11CreateDevice, ID3D11Device,
},
Dxgi::{DXGI_ERROR_UNSUPPORTED, IDXGIDevice},
};
Expand Down Expand Up @@ -70,7 +70,7 @@ fn create_d3d_device_on_pinned_adapter(
pub fn create_d3d_device() -> Result<ID3D11Device> {
let mut device = None;
let flags = {
let mut flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
let mut flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
if cfg!(feature = "d3ddebug") {
flags |= D3D11_CREATE_DEVICE_DEBUG;
}
Expand All @@ -97,7 +97,12 @@ pub fn create_d3d_device() -> Result<ID3D11Device> {
if let Err(error) = &result
&& error.code() == DXGI_ERROR_UNSUPPORTED
{
result = create_d3d_device_with_type(D3D_DRIVER_TYPE_WARP, flags, &mut device);
// WARP rejects VIDEO_SUPPORT; a WARP device cannot hardware-encode anyway.
result = create_d3d_device_with_type(
D3D_DRIVER_TYPE_WARP,
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
&mut device,
);
}
result?;
device.ok_or_else(windows::core::Error::from_win32)
Expand Down
Loading